Thomas Wouters | cf297e4 | 2007-02-23 15:07:44 +0000 | [diff] [blame] | 1 | /* File automatically generated by Parser/asdl_c.py. */ |
| 2 | |
| 3 | |
| 4 | /* |
Benjamin Peterson | e6d4a9b | 2008-12-06 18:33:20 +0000 | [diff] [blame] | 5 | __version__ 67616. |
Thomas Wouters | cf297e4 | 2007-02-23 15:07:44 +0000 | [diff] [blame] | 6 | |
| 7 | This module must be committed separately after each AST grammar change; |
| 8 | The __version__ number is set to the revision number of the commit |
| 9 | containing the grammar change. |
| 10 | */ |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 11 | |
| 12 | #include "Python.h" |
| 13 | #include "Python-ast.h" |
| 14 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 15 | static PyTypeObject AST_type; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 16 | static PyTypeObject *mod_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 17 | static PyObject* ast2obj_mod(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 18 | static PyTypeObject *Module_type; |
| 19 | static char *Module_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 20 | "body", |
| 21 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 22 | static PyTypeObject *Interactive_type; |
| 23 | static char *Interactive_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 24 | "body", |
| 25 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 26 | static PyTypeObject *Expression_type; |
| 27 | static char *Expression_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 28 | "body", |
| 29 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 30 | static PyTypeObject *Suite_type; |
| 31 | static char *Suite_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 32 | "body", |
| 33 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 34 | static PyTypeObject *stmt_type; |
| 35 | static char *stmt_attributes[] = { |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 36 | "lineno", |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 37 | "col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 38 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 39 | static PyObject* ast2obj_stmt(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 40 | static PyTypeObject *FunctionDef_type; |
| 41 | static char *FunctionDef_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 42 | "name", |
| 43 | "args", |
| 44 | "body", |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 45 | "decorator_list", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 46 | "returns", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 47 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 48 | static PyTypeObject *ClassDef_type; |
| 49 | static char *ClassDef_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 50 | "name", |
| 51 | "bases", |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 52 | "keywords", |
| 53 | "starargs", |
| 54 | "kwargs", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 55 | "body", |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 56 | "decorator_list", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 57 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 58 | static PyTypeObject *Return_type; |
| 59 | static char *Return_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 60 | "value", |
| 61 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 62 | static PyTypeObject *Delete_type; |
| 63 | static char *Delete_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 64 | "targets", |
| 65 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 66 | static PyTypeObject *Assign_type; |
| 67 | static char *Assign_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 68 | "targets", |
| 69 | "value", |
| 70 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 71 | static PyTypeObject *AugAssign_type; |
| 72 | static char *AugAssign_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 73 | "target", |
| 74 | "op", |
| 75 | "value", |
| 76 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 77 | static PyTypeObject *For_type; |
| 78 | static char *For_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 79 | "target", |
| 80 | "iter", |
| 81 | "body", |
| 82 | "orelse", |
| 83 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 84 | static PyTypeObject *While_type; |
| 85 | static char *While_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 86 | "test", |
| 87 | "body", |
| 88 | "orelse", |
| 89 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 90 | static PyTypeObject *If_type; |
| 91 | static char *If_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 92 | "test", |
| 93 | "body", |
| 94 | "orelse", |
| 95 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 96 | static PyTypeObject *With_type; |
| 97 | static char *With_fields[]={ |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 98 | "context_expr", |
| 99 | "optional_vars", |
| 100 | "body", |
| 101 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 102 | static PyTypeObject *Raise_type; |
| 103 | static char *Raise_fields[]={ |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 104 | "exc", |
| 105 | "cause", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 106 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 107 | static PyTypeObject *TryExcept_type; |
| 108 | static char *TryExcept_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 109 | "body", |
| 110 | "handlers", |
| 111 | "orelse", |
| 112 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 113 | static PyTypeObject *TryFinally_type; |
| 114 | static char *TryFinally_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 115 | "body", |
| 116 | "finalbody", |
| 117 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 118 | static PyTypeObject *Assert_type; |
| 119 | static char *Assert_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 120 | "test", |
| 121 | "msg", |
| 122 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 123 | static PyTypeObject *Import_type; |
| 124 | static char *Import_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 125 | "names", |
| 126 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 127 | static PyTypeObject *ImportFrom_type; |
| 128 | static char *ImportFrom_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 129 | "module", |
| 130 | "names", |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 131 | "level", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 132 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 133 | static PyTypeObject *Global_type; |
| 134 | static char *Global_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 135 | "names", |
| 136 | }; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 137 | static PyTypeObject *Nonlocal_type; |
| 138 | static char *Nonlocal_fields[]={ |
| 139 | "names", |
| 140 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 141 | static PyTypeObject *Expr_type; |
| 142 | static char *Expr_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 143 | "value", |
| 144 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 145 | static PyTypeObject *Pass_type; |
| 146 | static PyTypeObject *Break_type; |
| 147 | static PyTypeObject *Continue_type; |
| 148 | static PyTypeObject *expr_type; |
| 149 | static char *expr_attributes[] = { |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 150 | "lineno", |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 151 | "col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 152 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 153 | static PyObject* ast2obj_expr(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 154 | static PyTypeObject *BoolOp_type; |
| 155 | static char *BoolOp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 156 | "op", |
| 157 | "values", |
| 158 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 159 | static PyTypeObject *BinOp_type; |
| 160 | static char *BinOp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 161 | "left", |
| 162 | "op", |
| 163 | "right", |
| 164 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 165 | static PyTypeObject *UnaryOp_type; |
| 166 | static char *UnaryOp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 167 | "op", |
| 168 | "operand", |
| 169 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 170 | static PyTypeObject *Lambda_type; |
| 171 | static char *Lambda_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 172 | "args", |
| 173 | "body", |
| 174 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 175 | static PyTypeObject *IfExp_type; |
| 176 | static char *IfExp_fields[]={ |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 177 | "test", |
| 178 | "body", |
| 179 | "orelse", |
| 180 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 181 | static PyTypeObject *Dict_type; |
| 182 | static char *Dict_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 183 | "keys", |
| 184 | "values", |
| 185 | }; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 186 | static PyTypeObject *Set_type; |
| 187 | static char *Set_fields[]={ |
| 188 | "elts", |
| 189 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 190 | static PyTypeObject *ListComp_type; |
| 191 | static char *ListComp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 192 | "elt", |
| 193 | "generators", |
| 194 | }; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 195 | static PyTypeObject *SetComp_type; |
| 196 | static char *SetComp_fields[]={ |
| 197 | "elt", |
| 198 | "generators", |
| 199 | }; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 200 | static PyTypeObject *DictComp_type; |
| 201 | static char *DictComp_fields[]={ |
| 202 | "key", |
| 203 | "value", |
| 204 | "generators", |
| 205 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 206 | static PyTypeObject *GeneratorExp_type; |
| 207 | static char *GeneratorExp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 208 | "elt", |
| 209 | "generators", |
| 210 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 211 | static PyTypeObject *Yield_type; |
| 212 | static char *Yield_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 213 | "value", |
| 214 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 215 | static PyTypeObject *Compare_type; |
| 216 | static char *Compare_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 217 | "left", |
| 218 | "ops", |
| 219 | "comparators", |
| 220 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 221 | static PyTypeObject *Call_type; |
| 222 | static char *Call_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 223 | "func", |
| 224 | "args", |
| 225 | "keywords", |
| 226 | "starargs", |
| 227 | "kwargs", |
| 228 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 229 | static PyTypeObject *Num_type; |
| 230 | static char *Num_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 231 | "n", |
| 232 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 233 | static PyTypeObject *Str_type; |
| 234 | static char *Str_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 235 | "s", |
| 236 | }; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 237 | static PyTypeObject *Bytes_type; |
| 238 | static char *Bytes_fields[]={ |
| 239 | "s", |
| 240 | }; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 241 | static PyTypeObject *Ellipsis_type; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 242 | static PyTypeObject *Attribute_type; |
| 243 | static char *Attribute_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 244 | "value", |
| 245 | "attr", |
| 246 | "ctx", |
| 247 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 248 | static PyTypeObject *Subscript_type; |
| 249 | static char *Subscript_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 250 | "value", |
| 251 | "slice", |
| 252 | "ctx", |
| 253 | }; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 254 | static PyTypeObject *Starred_type; |
| 255 | static char *Starred_fields[]={ |
| 256 | "value", |
| 257 | "ctx", |
| 258 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 259 | static PyTypeObject *Name_type; |
| 260 | static char *Name_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 261 | "id", |
| 262 | "ctx", |
| 263 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 264 | static PyTypeObject *List_type; |
| 265 | static char *List_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 266 | "elts", |
| 267 | "ctx", |
| 268 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 269 | static PyTypeObject *Tuple_type; |
| 270 | static char *Tuple_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 271 | "elts", |
| 272 | "ctx", |
| 273 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 274 | static PyTypeObject *expr_context_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 275 | static PyObject *Load_singleton, *Store_singleton, *Del_singleton, |
| 276 | *AugLoad_singleton, *AugStore_singleton, *Param_singleton; |
| 277 | static PyObject* ast2obj_expr_context(expr_context_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 278 | static PyTypeObject *Load_type; |
| 279 | static PyTypeObject *Store_type; |
| 280 | static PyTypeObject *Del_type; |
| 281 | static PyTypeObject *AugLoad_type; |
| 282 | static PyTypeObject *AugStore_type; |
| 283 | static PyTypeObject *Param_type; |
| 284 | static PyTypeObject *slice_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 285 | static PyObject* ast2obj_slice(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 286 | static PyTypeObject *Slice_type; |
| 287 | static char *Slice_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 288 | "lower", |
| 289 | "upper", |
| 290 | "step", |
| 291 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 292 | static PyTypeObject *ExtSlice_type; |
| 293 | static char *ExtSlice_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 294 | "dims", |
| 295 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 296 | static PyTypeObject *Index_type; |
| 297 | static char *Index_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 298 | "value", |
| 299 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 300 | static PyTypeObject *boolop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 301 | static PyObject *And_singleton, *Or_singleton; |
| 302 | static PyObject* ast2obj_boolop(boolop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 303 | static PyTypeObject *And_type; |
| 304 | static PyTypeObject *Or_type; |
| 305 | static PyTypeObject *operator_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 306 | static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton, |
| 307 | *Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton, |
| 308 | *RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton, |
| 309 | *FloorDiv_singleton; |
| 310 | static PyObject* ast2obj_operator(operator_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 311 | static PyTypeObject *Add_type; |
| 312 | static PyTypeObject *Sub_type; |
| 313 | static PyTypeObject *Mult_type; |
| 314 | static PyTypeObject *Div_type; |
| 315 | static PyTypeObject *Mod_type; |
| 316 | static PyTypeObject *Pow_type; |
| 317 | static PyTypeObject *LShift_type; |
| 318 | static PyTypeObject *RShift_type; |
| 319 | static PyTypeObject *BitOr_type; |
| 320 | static PyTypeObject *BitXor_type; |
| 321 | static PyTypeObject *BitAnd_type; |
| 322 | static PyTypeObject *FloorDiv_type; |
| 323 | static PyTypeObject *unaryop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 324 | static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton, |
| 325 | *USub_singleton; |
| 326 | static PyObject* ast2obj_unaryop(unaryop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 327 | static PyTypeObject *Invert_type; |
| 328 | static PyTypeObject *Not_type; |
| 329 | static PyTypeObject *UAdd_type; |
| 330 | static PyTypeObject *USub_type; |
| 331 | static PyTypeObject *cmpop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 332 | static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton, |
| 333 | *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton, |
| 334 | *NotIn_singleton; |
| 335 | static PyObject* ast2obj_cmpop(cmpop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 336 | static PyTypeObject *Eq_type; |
| 337 | static PyTypeObject *NotEq_type; |
| 338 | static PyTypeObject *Lt_type; |
| 339 | static PyTypeObject *LtE_type; |
| 340 | static PyTypeObject *Gt_type; |
| 341 | static PyTypeObject *GtE_type; |
| 342 | static PyTypeObject *Is_type; |
| 343 | static PyTypeObject *IsNot_type; |
| 344 | static PyTypeObject *In_type; |
| 345 | static PyTypeObject *NotIn_type; |
| 346 | static PyTypeObject *comprehension_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 347 | static PyObject* ast2obj_comprehension(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 348 | static char *comprehension_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 349 | "target", |
| 350 | "iter", |
| 351 | "ifs", |
| 352 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 353 | static PyTypeObject *excepthandler_type; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 354 | static char *excepthandler_attributes[] = { |
| 355 | "lineno", |
| 356 | "col_offset", |
| 357 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 358 | static PyObject* ast2obj_excepthandler(void*); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 359 | static PyTypeObject *ExceptHandler_type; |
| 360 | static char *ExceptHandler_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 361 | "type", |
| 362 | "name", |
| 363 | "body", |
| 364 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 365 | static PyTypeObject *arguments_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 366 | static PyObject* ast2obj_arguments(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 367 | static char *arguments_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 368 | "args", |
| 369 | "vararg", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 370 | "varargannotation", |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 371 | "kwonlyargs", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 372 | "kwarg", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 373 | "kwargannotation", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 374 | "defaults", |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 375 | "kw_defaults", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 376 | }; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 377 | static PyTypeObject *arg_type; |
| 378 | static PyObject* ast2obj_arg(void*); |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 379 | static char *arg_fields[]={ |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 380 | "arg", |
| 381 | "annotation", |
| 382 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 383 | static PyTypeObject *keyword_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 384 | static PyObject* ast2obj_keyword(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 385 | static char *keyword_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 386 | "arg", |
| 387 | "value", |
| 388 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 389 | static PyTypeObject *alias_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 390 | static PyObject* ast2obj_alias(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 391 | static char *alias_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 392 | "name", |
| 393 | "asname", |
| 394 | }; |
| 395 | |
| 396 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 397 | static int |
| 398 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 399 | { |
| 400 | Py_ssize_t i, numfields = 0; |
| 401 | int res = -1; |
| 402 | PyObject *key, *value, *fields; |
| 403 | fields = PyObject_GetAttrString((PyObject*)Py_TYPE(self), "_fields"); |
| 404 | if (!fields) |
| 405 | PyErr_Clear(); |
| 406 | if (fields) { |
| 407 | numfields = PySequence_Size(fields); |
| 408 | if (numfields == -1) |
| 409 | goto cleanup; |
| 410 | } |
| 411 | res = 0; /* if no error occurs, this stays 0 to the end */ |
| 412 | if (PyTuple_GET_SIZE(args) > 0) { |
| 413 | if (numfields != PyTuple_GET_SIZE(args)) { |
| 414 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes %s" |
Amaury Forgeot d'Arc | 245c70b | 2008-09-10 22:24:24 +0000 | [diff] [blame] | 415 | "%zd positional argument%s", |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 416 | Py_TYPE(self)->tp_name, |
| 417 | numfields == 0 ? "" : "either 0 or ", |
| 418 | numfields, numfields == 1 ? "" : "s"); |
| 419 | res = -1; |
| 420 | goto cleanup; |
| 421 | } |
| 422 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
| 423 | /* cannot be reached when fields is NULL */ |
| 424 | PyObject *name = PySequence_GetItem(fields, i); |
| 425 | if (!name) { |
| 426 | res = -1; |
| 427 | goto cleanup; |
| 428 | } |
| 429 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
| 430 | Py_DECREF(name); |
| 431 | if (res < 0) |
| 432 | goto cleanup; |
| 433 | } |
| 434 | } |
| 435 | if (kw) { |
| 436 | i = 0; /* needed by PyDict_Next */ |
| 437 | while (PyDict_Next(kw, &i, &key, &value)) { |
| 438 | res = PyObject_SetAttr(self, key, value); |
| 439 | if (res < 0) |
| 440 | goto cleanup; |
| 441 | } |
| 442 | } |
| 443 | cleanup: |
| 444 | Py_XDECREF(fields); |
| 445 | return res; |
| 446 | } |
| 447 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 448 | /* Pickling support */ |
| 449 | static PyObject * |
| 450 | ast_type_reduce(PyObject *self, PyObject *unused) |
| 451 | { |
| 452 | PyObject *res; |
| 453 | PyObject *dict = PyObject_GetAttrString(self, "__dict__"); |
| 454 | if (dict == NULL) { |
| 455 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) |
| 456 | PyErr_Clear(); |
| 457 | else |
| 458 | return NULL; |
| 459 | } |
| 460 | if (dict) { |
| 461 | res = Py_BuildValue("O()O", Py_TYPE(self), dict); |
| 462 | Py_DECREF(dict); |
| 463 | return res; |
| 464 | } |
| 465 | return Py_BuildValue("O()", Py_TYPE(self)); |
| 466 | } |
| 467 | |
| 468 | static PyMethodDef ast_type_methods[] = { |
| 469 | {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, |
| 470 | {NULL} |
| 471 | }; |
| 472 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 473 | static PyTypeObject AST_type = { |
| 474 | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 475 | "_ast.AST", |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 476 | sizeof(PyObject), |
| 477 | 0, |
| 478 | 0, /* tp_dealloc */ |
| 479 | 0, /* tp_print */ |
| 480 | 0, /* tp_getattr */ |
| 481 | 0, /* tp_setattr */ |
Mark Dickinson | e94c679 | 2009-02-02 20:36:42 +0000 | [diff] [blame] | 482 | 0, /* tp_reserved */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 483 | 0, /* tp_repr */ |
| 484 | 0, /* tp_as_number */ |
| 485 | 0, /* tp_as_sequence */ |
| 486 | 0, /* tp_as_mapping */ |
| 487 | 0, /* tp_hash */ |
| 488 | 0, /* tp_call */ |
| 489 | 0, /* tp_str */ |
| 490 | PyObject_GenericGetAttr, /* tp_getattro */ |
| 491 | PyObject_GenericSetAttr, /* tp_setattro */ |
| 492 | 0, /* tp_as_buffer */ |
| 493 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
| 494 | 0, /* tp_doc */ |
| 495 | 0, /* tp_traverse */ |
| 496 | 0, /* tp_clear */ |
| 497 | 0, /* tp_richcompare */ |
| 498 | 0, /* tp_weaklistoffset */ |
| 499 | 0, /* tp_iter */ |
| 500 | 0, /* tp_iternext */ |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 501 | ast_type_methods, /* tp_methods */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 502 | 0, /* tp_members */ |
| 503 | 0, /* tp_getset */ |
| 504 | 0, /* tp_base */ |
| 505 | 0, /* tp_dict */ |
| 506 | 0, /* tp_descr_get */ |
| 507 | 0, /* tp_descr_set */ |
| 508 | 0, /* tp_dictoffset */ |
| 509 | (initproc)ast_type_init, /* tp_init */ |
| 510 | PyType_GenericAlloc, /* tp_alloc */ |
| 511 | PyType_GenericNew, /* tp_new */ |
| 512 | PyObject_Del, /* tp_free */ |
| 513 | }; |
| 514 | |
| 515 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 516 | static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields) |
| 517 | { |
| 518 | PyObject *fnames, *result; |
| 519 | int i; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 520 | fnames = PyTuple_New(num_fields); |
| 521 | if (!fnames) return NULL; |
| 522 | for (i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 523 | PyObject *field = PyUnicode_FromString(fields[i]); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 524 | if (!field) { |
| 525 | Py_DECREF(fnames); |
| 526 | return NULL; |
| 527 | } |
| 528 | PyTuple_SET_ITEM(fnames, i, field); |
| 529 | } |
Guido van Rossum | e845c0f | 2007-11-02 23:07:07 +0000 | [diff] [blame] | 530 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "U(O){sOss}", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 531 | type, base, "_fields", fnames, "__module__", "_ast"); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 532 | Py_DECREF(fnames); |
| 533 | return (PyTypeObject*)result; |
| 534 | } |
| 535 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 536 | static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) |
| 537 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 538 | int i, result; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 539 | PyObject *s, *l = PyTuple_New(num_fields); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 540 | if (!l) return 0; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 541 | for(i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 542 | s = PyUnicode_FromString(attrs[i]); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 543 | if (!s) { |
| 544 | Py_DECREF(l); |
| 545 | return 0; |
| 546 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 547 | PyTuple_SET_ITEM(l, i, s); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 548 | } |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 549 | result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0; |
| 550 | Py_DECREF(l); |
| 551 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 552 | } |
| 553 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 554 | /* Conversion AST -> Python */ |
| 555 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 556 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 557 | { |
| 558 | int i, n = asdl_seq_LEN(seq); |
| 559 | PyObject *result = PyList_New(n); |
| 560 | PyObject *value; |
| 561 | if (!result) |
| 562 | return NULL; |
| 563 | for (i = 0; i < n; i++) { |
| 564 | value = func(asdl_seq_GET(seq, i)); |
| 565 | if (!value) { |
| 566 | Py_DECREF(result); |
| 567 | return NULL; |
| 568 | } |
| 569 | PyList_SET_ITEM(result, i, value); |
| 570 | } |
| 571 | return result; |
| 572 | } |
| 573 | |
| 574 | static PyObject* ast2obj_object(void *o) |
| 575 | { |
| 576 | if (!o) |
| 577 | o = Py_None; |
| 578 | Py_INCREF((PyObject*)o); |
| 579 | return (PyObject*)o; |
| 580 | } |
| 581 | #define ast2obj_identifier ast2obj_object |
| 582 | #define ast2obj_string ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 583 | |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 584 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 585 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 586 | return PyLong_FromLong(b); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 587 | } |
| 588 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 589 | /* Conversion Python -> AST */ |
| 590 | |
| 591 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 592 | { |
| 593 | if (obj == Py_None) |
| 594 | obj = NULL; |
| 595 | if (obj) |
| 596 | PyArena_AddPyObject(arena, obj); |
| 597 | Py_XINCREF(obj); |
| 598 | *out = obj; |
| 599 | return 0; |
| 600 | } |
| 601 | |
| 602 | #define obj2ast_identifier obj2ast_object |
| 603 | #define obj2ast_string obj2ast_object |
| 604 | |
| 605 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 606 | { |
| 607 | int i; |
| 608 | if (!PyLong_Check(obj)) { |
| 609 | PyObject *s = PyObject_Repr(obj); |
| 610 | if (s == NULL) return 1; |
| 611 | PyErr_Format(PyExc_ValueError, "invalid integer value: %.400s", |
Christian Heimes | 72b710a | 2008-05-26 13:28:38 +0000 | [diff] [blame] | 612 | PyBytes_AS_STRING(s)); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 613 | Py_DECREF(s); |
| 614 | return 1; |
| 615 | } |
| 616 | |
| 617 | i = (int)PyLong_AsLong(obj); |
| 618 | if (i == -1 && PyErr_Occurred()) |
| 619 | return 1; |
| 620 | *out = i; |
| 621 | return 0; |
| 622 | } |
| 623 | |
Benjamin Peterson | 1a6e0d0 | 2008-10-25 15:49:17 +0000 | [diff] [blame] | 624 | static int add_ast_fields(void) |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 625 | { |
| 626 | PyObject *empty_tuple, *d; |
| 627 | if (PyType_Ready(&AST_type) < 0) |
| 628 | return -1; |
| 629 | d = AST_type.tp_dict; |
| 630 | empty_tuple = PyTuple_New(0); |
| 631 | if (!empty_tuple || |
| 632 | PyDict_SetItemString(d, "_fields", empty_tuple) < 0 || |
| 633 | PyDict_SetItemString(d, "_attributes", empty_tuple) < 0) { |
| 634 | Py_XDECREF(empty_tuple); |
| 635 | return -1; |
| 636 | } |
| 637 | Py_DECREF(empty_tuple); |
| 638 | return 0; |
| 639 | } |
| 640 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 641 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 642 | static int init_types(void) |
| 643 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 644 | static int initialized; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 645 | if (initialized) return 1; |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 646 | if (add_ast_fields() < 0) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 647 | mod_type = make_type("mod", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 648 | if (!mod_type) return 0; |
| 649 | if (!add_attributes(mod_type, NULL, 0)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 650 | Module_type = make_type("Module", mod_type, Module_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 651 | if (!Module_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 652 | Interactive_type = make_type("Interactive", mod_type, |
| 653 | Interactive_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 654 | if (!Interactive_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 655 | Expression_type = make_type("Expression", mod_type, Expression_fields, |
| 656 | 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 657 | if (!Expression_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 658 | Suite_type = make_type("Suite", mod_type, Suite_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 659 | if (!Suite_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 660 | stmt_type = make_type("stmt", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 661 | if (!stmt_type) return 0; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 662 | if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 663 | FunctionDef_type = make_type("FunctionDef", stmt_type, |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 664 | FunctionDef_fields, 5); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 665 | if (!FunctionDef_type) return 0; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 666 | ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 7); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 667 | if (!ClassDef_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 668 | Return_type = make_type("Return", stmt_type, Return_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 669 | if (!Return_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 670 | Delete_type = make_type("Delete", stmt_type, Delete_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 671 | if (!Delete_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 672 | Assign_type = make_type("Assign", stmt_type, Assign_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 673 | if (!Assign_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 674 | AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 675 | if (!AugAssign_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 676 | For_type = make_type("For", stmt_type, For_fields, 4); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 677 | if (!For_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 678 | While_type = make_type("While", stmt_type, While_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 679 | if (!While_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 680 | If_type = make_type("If", stmt_type, If_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 681 | if (!If_type) return 0; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 682 | With_type = make_type("With", stmt_type, With_fields, 3); |
| 683 | if (!With_type) return 0; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 684 | Raise_type = make_type("Raise", stmt_type, Raise_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 685 | if (!Raise_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 686 | TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 687 | if (!TryExcept_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 688 | TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields, |
| 689 | 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 690 | if (!TryFinally_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 691 | Assert_type = make_type("Assert", stmt_type, Assert_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 692 | if (!Assert_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 693 | Import_type = make_type("Import", stmt_type, Import_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 694 | if (!Import_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 695 | ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 696 | 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 697 | if (!ImportFrom_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 698 | Global_type = make_type("Global", stmt_type, Global_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 699 | if (!Global_type) return 0; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 700 | Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1); |
| 701 | if (!Nonlocal_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 702 | Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 703 | if (!Expr_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 704 | Pass_type = make_type("Pass", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 705 | if (!Pass_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 706 | Break_type = make_type("Break", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 707 | if (!Break_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 708 | Continue_type = make_type("Continue", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 709 | if (!Continue_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 710 | expr_type = make_type("expr", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 711 | if (!expr_type) return 0; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 712 | if (!add_attributes(expr_type, expr_attributes, 2)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 713 | BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 714 | if (!BoolOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 715 | BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 716 | if (!BinOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 717 | UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 718 | if (!UnaryOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 719 | Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 720 | if (!Lambda_type) return 0; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 721 | IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 722 | if (!IfExp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 723 | Dict_type = make_type("Dict", expr_type, Dict_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 724 | if (!Dict_type) return 0; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 725 | Set_type = make_type("Set", expr_type, Set_fields, 1); |
| 726 | if (!Set_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 727 | ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 728 | if (!ListComp_type) return 0; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 729 | SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2); |
| 730 | if (!SetComp_type) return 0; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 731 | DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3); |
| 732 | if (!DictComp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 733 | GeneratorExp_type = make_type("GeneratorExp", expr_type, |
| 734 | GeneratorExp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 735 | if (!GeneratorExp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 736 | Yield_type = make_type("Yield", expr_type, Yield_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 737 | if (!Yield_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 738 | Compare_type = make_type("Compare", expr_type, Compare_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 739 | if (!Compare_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 740 | Call_type = make_type("Call", expr_type, Call_fields, 5); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 741 | if (!Call_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 742 | Num_type = make_type("Num", expr_type, Num_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 743 | if (!Num_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 744 | Str_type = make_type("Str", expr_type, Str_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 745 | if (!Str_type) return 0; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 746 | Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1); |
| 747 | if (!Bytes_type) return 0; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 748 | Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0); |
| 749 | if (!Ellipsis_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 750 | Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 751 | if (!Attribute_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 752 | Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 753 | if (!Subscript_type) return 0; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 754 | Starred_type = make_type("Starred", expr_type, Starred_fields, 2); |
| 755 | if (!Starred_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 756 | Name_type = make_type("Name", expr_type, Name_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 757 | if (!Name_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 758 | List_type = make_type("List", expr_type, List_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 759 | if (!List_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 760 | Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 761 | if (!Tuple_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 762 | 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] | 763 | if (!expr_context_type) return 0; |
| 764 | if (!add_attributes(expr_context_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 765 | Load_type = make_type("Load", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 766 | if (!Load_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 767 | Load_singleton = PyType_GenericNew(Load_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 768 | if (!Load_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 769 | Store_type = make_type("Store", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 770 | if (!Store_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 771 | Store_singleton = PyType_GenericNew(Store_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 772 | if (!Store_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 773 | Del_type = make_type("Del", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 774 | if (!Del_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 775 | Del_singleton = PyType_GenericNew(Del_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 776 | if (!Del_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 777 | AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 778 | if (!AugLoad_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 779 | AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 780 | if (!AugLoad_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 781 | AugStore_type = make_type("AugStore", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 782 | if (!AugStore_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 783 | AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 784 | if (!AugStore_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 785 | Param_type = make_type("Param", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 786 | if (!Param_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 787 | Param_singleton = PyType_GenericNew(Param_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 788 | if (!Param_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 789 | slice_type = make_type("slice", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 790 | if (!slice_type) return 0; |
| 791 | if (!add_attributes(slice_type, NULL, 0)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 792 | Slice_type = make_type("Slice", slice_type, Slice_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 793 | if (!Slice_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 794 | ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 795 | if (!ExtSlice_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 796 | Index_type = make_type("Index", slice_type, Index_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 797 | if (!Index_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 798 | boolop_type = make_type("boolop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 799 | if (!boolop_type) return 0; |
| 800 | if (!add_attributes(boolop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 801 | And_type = make_type("And", boolop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 802 | if (!And_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 803 | And_singleton = PyType_GenericNew(And_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 804 | if (!And_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 805 | Or_type = make_type("Or", boolop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 806 | if (!Or_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 807 | Or_singleton = PyType_GenericNew(Or_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 808 | if (!Or_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 809 | operator_type = make_type("operator", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 810 | if (!operator_type) return 0; |
| 811 | if (!add_attributes(operator_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 812 | Add_type = make_type("Add", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 813 | if (!Add_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 814 | Add_singleton = PyType_GenericNew(Add_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 815 | if (!Add_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 816 | Sub_type = make_type("Sub", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 817 | if (!Sub_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 818 | Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 819 | if (!Sub_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 820 | Mult_type = make_type("Mult", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 821 | if (!Mult_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 822 | Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 823 | if (!Mult_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 824 | Div_type = make_type("Div", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 825 | if (!Div_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 826 | Div_singleton = PyType_GenericNew(Div_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 827 | if (!Div_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 828 | Mod_type = make_type("Mod", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 829 | if (!Mod_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 830 | Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 831 | if (!Mod_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 832 | Pow_type = make_type("Pow", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 833 | if (!Pow_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 834 | Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 835 | if (!Pow_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 836 | LShift_type = make_type("LShift", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 837 | if (!LShift_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 838 | LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 839 | if (!LShift_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 840 | RShift_type = make_type("RShift", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 841 | if (!RShift_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 842 | RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 843 | if (!RShift_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 844 | BitOr_type = make_type("BitOr", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 845 | if (!BitOr_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 846 | BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 847 | if (!BitOr_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 848 | BitXor_type = make_type("BitXor", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 849 | if (!BitXor_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 850 | BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 851 | if (!BitXor_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 852 | BitAnd_type = make_type("BitAnd", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 853 | if (!BitAnd_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 854 | BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 855 | if (!BitAnd_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 856 | FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 857 | if (!FloorDiv_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 858 | FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 859 | if (!FloorDiv_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 860 | unaryop_type = make_type("unaryop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 861 | if (!unaryop_type) return 0; |
| 862 | if (!add_attributes(unaryop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 863 | Invert_type = make_type("Invert", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 864 | if (!Invert_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 865 | Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 866 | if (!Invert_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 867 | Not_type = make_type("Not", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 868 | if (!Not_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 869 | Not_singleton = PyType_GenericNew(Not_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 870 | if (!Not_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 871 | UAdd_type = make_type("UAdd", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 872 | if (!UAdd_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 873 | UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 874 | if (!UAdd_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 875 | USub_type = make_type("USub", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 876 | if (!USub_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 877 | USub_singleton = PyType_GenericNew(USub_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 878 | if (!USub_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 879 | cmpop_type = make_type("cmpop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 880 | if (!cmpop_type) return 0; |
| 881 | if (!add_attributes(cmpop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 882 | Eq_type = make_type("Eq", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 883 | if (!Eq_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 884 | Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 885 | if (!Eq_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 886 | NotEq_type = make_type("NotEq", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 887 | if (!NotEq_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 888 | NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 889 | if (!NotEq_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 890 | Lt_type = make_type("Lt", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 891 | if (!Lt_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 892 | Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 893 | if (!Lt_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 894 | LtE_type = make_type("LtE", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 895 | if (!LtE_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 896 | LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 897 | if (!LtE_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 898 | Gt_type = make_type("Gt", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 899 | if (!Gt_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 900 | Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 901 | if (!Gt_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 902 | GtE_type = make_type("GtE", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 903 | if (!GtE_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 904 | GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 905 | if (!GtE_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 906 | Is_type = make_type("Is", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 907 | if (!Is_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 908 | Is_singleton = PyType_GenericNew(Is_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 909 | if (!Is_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 910 | IsNot_type = make_type("IsNot", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 911 | if (!IsNot_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 912 | IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 913 | if (!IsNot_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 914 | In_type = make_type("In", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 915 | if (!In_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 916 | In_singleton = PyType_GenericNew(In_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 917 | if (!In_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 918 | NotIn_type = make_type("NotIn", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 919 | if (!NotIn_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 920 | NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 921 | if (!NotIn_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 922 | comprehension_type = make_type("comprehension", &AST_type, |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 923 | comprehension_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 924 | if (!comprehension_type) return 0; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 925 | excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 926 | if (!excepthandler_type) return 0; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 927 | if (!add_attributes(excepthandler_type, excepthandler_attributes, 2)) |
| 928 | return 0; |
| 929 | ExceptHandler_type = make_type("ExceptHandler", excepthandler_type, |
| 930 | ExceptHandler_fields, 3); |
| 931 | if (!ExceptHandler_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 932 | arguments_type = make_type("arguments", &AST_type, arguments_fields, 8); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 933 | if (!arguments_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 934 | arg_type = make_type("arg", &AST_type, arg_fields, 2); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 935 | if (!arg_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 936 | keyword_type = make_type("keyword", &AST_type, keyword_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 937 | if (!keyword_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 938 | alias_type = make_type("alias", &AST_type, alias_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 939 | if (!alias_type) return 0; |
| 940 | initialized = 1; |
| 941 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 942 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 943 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 944 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 945 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 946 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 947 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 948 | arena); |
| 949 | static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena); |
| 950 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 951 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 952 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 953 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 954 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 955 | arena); |
| 956 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 957 | arena); |
| 958 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 959 | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
| 960 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 961 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
| 962 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 963 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 964 | Module(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 965 | { |
| 966 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 967 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 968 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 969 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 970 | p->kind = Module_kind; |
| 971 | p->v.Module.body = body; |
| 972 | return p; |
| 973 | } |
| 974 | |
| 975 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 976 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 977 | { |
| 978 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 979 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 980 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 981 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 982 | p->kind = Interactive_kind; |
| 983 | p->v.Interactive.body = body; |
| 984 | return p; |
| 985 | } |
| 986 | |
| 987 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 988 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 989 | { |
| 990 | mod_ty p; |
| 991 | if (!body) { |
| 992 | PyErr_SetString(PyExc_ValueError, |
| 993 | "field body is required for Expression"); |
| 994 | return NULL; |
| 995 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 996 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 997 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 998 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 999 | p->kind = Expression_kind; |
| 1000 | p->v.Expression.body = body; |
| 1001 | return p; |
| 1002 | } |
| 1003 | |
| 1004 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1005 | Suite(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1006 | { |
| 1007 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1008 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1009 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1010 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1011 | p->kind = Suite_kind; |
| 1012 | p->v.Suite.body = body; |
| 1013 | return p; |
| 1014 | } |
| 1015 | |
| 1016 | stmt_ty |
| 1017 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1018 | decorator_list, expr_ty returns, int lineno, int col_offset, |
| 1019 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1020 | { |
| 1021 | stmt_ty p; |
| 1022 | if (!name) { |
| 1023 | PyErr_SetString(PyExc_ValueError, |
| 1024 | "field name is required for FunctionDef"); |
| 1025 | return NULL; |
| 1026 | } |
| 1027 | if (!args) { |
| 1028 | PyErr_SetString(PyExc_ValueError, |
| 1029 | "field args is required for FunctionDef"); |
| 1030 | return NULL; |
| 1031 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1032 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1033 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1034 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1035 | p->kind = FunctionDef_kind; |
| 1036 | p->v.FunctionDef.name = name; |
| 1037 | p->v.FunctionDef.args = args; |
| 1038 | p->v.FunctionDef.body = body; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1039 | p->v.FunctionDef.decorator_list = decorator_list; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1040 | p->v.FunctionDef.returns = returns; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1041 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1042 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1043 | return p; |
| 1044 | } |
| 1045 | |
| 1046 | stmt_ty |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 1047 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, expr_ty |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1048 | starargs, expr_ty kwargs, asdl_seq * body, asdl_seq * decorator_list, |
| 1049 | int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1050 | { |
| 1051 | stmt_ty p; |
| 1052 | if (!name) { |
| 1053 | PyErr_SetString(PyExc_ValueError, |
| 1054 | "field name is required for ClassDef"); |
| 1055 | return NULL; |
| 1056 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1057 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1058 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1059 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1060 | p->kind = ClassDef_kind; |
| 1061 | p->v.ClassDef.name = name; |
| 1062 | p->v.ClassDef.bases = bases; |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 1063 | p->v.ClassDef.keywords = keywords; |
| 1064 | p->v.ClassDef.starargs = starargs; |
| 1065 | p->v.ClassDef.kwargs = kwargs; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1066 | p->v.ClassDef.body = body; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1067 | p->v.ClassDef.decorator_list = decorator_list; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1068 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1069 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1070 | return p; |
| 1071 | } |
| 1072 | |
| 1073 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1074 | Return(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1075 | { |
| 1076 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1077 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1078 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1079 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1080 | p->kind = Return_kind; |
| 1081 | p->v.Return.value = value; |
| 1082 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1083 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1084 | return p; |
| 1085 | } |
| 1086 | |
| 1087 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1088 | Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1089 | { |
| 1090 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1091 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1092 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1093 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1094 | p->kind = Delete_kind; |
| 1095 | p->v.Delete.targets = targets; |
| 1096 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1097 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1098 | return p; |
| 1099 | } |
| 1100 | |
| 1101 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1102 | Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena |
| 1103 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1104 | { |
| 1105 | stmt_ty p; |
| 1106 | if (!value) { |
| 1107 | PyErr_SetString(PyExc_ValueError, |
| 1108 | "field value is required for Assign"); |
| 1109 | return NULL; |
| 1110 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1111 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1112 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1113 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1114 | p->kind = Assign_kind; |
| 1115 | p->v.Assign.targets = targets; |
| 1116 | p->v.Assign.value = value; |
| 1117 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1118 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1119 | return p; |
| 1120 | } |
| 1121 | |
| 1122 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1123 | AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int |
| 1124 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1125 | { |
| 1126 | stmt_ty p; |
| 1127 | if (!target) { |
| 1128 | PyErr_SetString(PyExc_ValueError, |
| 1129 | "field target is required for AugAssign"); |
| 1130 | return NULL; |
| 1131 | } |
| 1132 | if (!op) { |
| 1133 | PyErr_SetString(PyExc_ValueError, |
| 1134 | "field op is required for AugAssign"); |
| 1135 | return NULL; |
| 1136 | } |
| 1137 | if (!value) { |
| 1138 | PyErr_SetString(PyExc_ValueError, |
| 1139 | "field value is required for AugAssign"); |
| 1140 | return NULL; |
| 1141 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1142 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1143 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1144 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1145 | p->kind = AugAssign_kind; |
| 1146 | p->v.AugAssign.target = target; |
| 1147 | p->v.AugAssign.op = op; |
| 1148 | p->v.AugAssign.value = value; |
| 1149 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1150 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1151 | return p; |
| 1152 | } |
| 1153 | |
| 1154 | stmt_ty |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1155 | 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] | 1156 | lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1157 | { |
| 1158 | stmt_ty p; |
| 1159 | if (!target) { |
| 1160 | PyErr_SetString(PyExc_ValueError, |
| 1161 | "field target is required for For"); |
| 1162 | return NULL; |
| 1163 | } |
| 1164 | if (!iter) { |
| 1165 | PyErr_SetString(PyExc_ValueError, |
| 1166 | "field iter is required for For"); |
| 1167 | return NULL; |
| 1168 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1169 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1170 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1171 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1172 | p->kind = For_kind; |
| 1173 | p->v.For.target = target; |
| 1174 | p->v.For.iter = iter; |
| 1175 | p->v.For.body = body; |
| 1176 | p->v.For.orelse = orelse; |
| 1177 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1178 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1179 | return p; |
| 1180 | } |
| 1181 | |
| 1182 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1183 | While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1184 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1185 | { |
| 1186 | stmt_ty p; |
| 1187 | if (!test) { |
| 1188 | PyErr_SetString(PyExc_ValueError, |
| 1189 | "field test is required for While"); |
| 1190 | return NULL; |
| 1191 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1192 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1193 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1194 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1195 | p->kind = While_kind; |
| 1196 | p->v.While.test = test; |
| 1197 | p->v.While.body = body; |
| 1198 | p->v.While.orelse = orelse; |
| 1199 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1200 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1201 | return p; |
| 1202 | } |
| 1203 | |
| 1204 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1205 | If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1206 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1207 | { |
| 1208 | stmt_ty p; |
| 1209 | if (!test) { |
| 1210 | PyErr_SetString(PyExc_ValueError, |
| 1211 | "field test is required for If"); |
| 1212 | return NULL; |
| 1213 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1214 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1215 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1216 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1217 | p->kind = If_kind; |
| 1218 | p->v.If.test = test; |
| 1219 | p->v.If.body = body; |
| 1220 | p->v.If.orelse = orelse; |
| 1221 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1222 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1223 | return p; |
| 1224 | } |
| 1225 | |
| 1226 | stmt_ty |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1227 | With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno, |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1228 | int col_offset, PyArena *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1229 | { |
| 1230 | stmt_ty p; |
| 1231 | if (!context_expr) { |
| 1232 | PyErr_SetString(PyExc_ValueError, |
| 1233 | "field context_expr is required for With"); |
| 1234 | return NULL; |
| 1235 | } |
| 1236 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1237 | if (!p) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1238 | return NULL; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1239 | p->kind = With_kind; |
| 1240 | p->v.With.context_expr = context_expr; |
| 1241 | p->v.With.optional_vars = optional_vars; |
| 1242 | p->v.With.body = body; |
| 1243 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1244 | p->col_offset = col_offset; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1245 | return p; |
| 1246 | } |
| 1247 | |
| 1248 | stmt_ty |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 1249 | 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] | 1250 | { |
| 1251 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1252 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1253 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1254 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1255 | p->kind = Raise_kind; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 1256 | p->v.Raise.exc = exc; |
| 1257 | p->v.Raise.cause = cause; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1258 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1259 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1260 | return p; |
| 1261 | } |
| 1262 | |
| 1263 | stmt_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1264 | TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno, |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1265 | int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1266 | { |
| 1267 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1268 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1269 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1270 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1271 | p->kind = TryExcept_kind; |
| 1272 | p->v.TryExcept.body = body; |
| 1273 | p->v.TryExcept.handlers = handlers; |
| 1274 | p->v.TryExcept.orelse = orelse; |
| 1275 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1276 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1277 | return p; |
| 1278 | } |
| 1279 | |
| 1280 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1281 | TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset, |
| 1282 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1283 | { |
| 1284 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1285 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1286 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1287 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1288 | p->kind = TryFinally_kind; |
| 1289 | p->v.TryFinally.body = body; |
| 1290 | p->v.TryFinally.finalbody = finalbody; |
| 1291 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1292 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1293 | return p; |
| 1294 | } |
| 1295 | |
| 1296 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1297 | 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] | 1298 | { |
| 1299 | stmt_ty p; |
| 1300 | if (!test) { |
| 1301 | PyErr_SetString(PyExc_ValueError, |
| 1302 | "field test is required for Assert"); |
| 1303 | return NULL; |
| 1304 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1305 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1306 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1307 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1308 | p->kind = Assert_kind; |
| 1309 | p->v.Assert.test = test; |
| 1310 | p->v.Assert.msg = msg; |
| 1311 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1312 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1313 | return p; |
| 1314 | } |
| 1315 | |
| 1316 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1317 | Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1318 | { |
| 1319 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1320 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1321 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1322 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1323 | p->kind = Import_kind; |
| 1324 | p->v.Import.names = names; |
| 1325 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1326 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1327 | return p; |
| 1328 | } |
| 1329 | |
| 1330 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1331 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
| 1332 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1333 | { |
| 1334 | stmt_ty p; |
| 1335 | if (!module) { |
| 1336 | PyErr_SetString(PyExc_ValueError, |
| 1337 | "field module is required for ImportFrom"); |
| 1338 | return NULL; |
| 1339 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1340 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1341 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1342 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1343 | p->kind = ImportFrom_kind; |
| 1344 | p->v.ImportFrom.module = module; |
| 1345 | p->v.ImportFrom.names = names; |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 1346 | p->v.ImportFrom.level = level; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1347 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1348 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1349 | return p; |
| 1350 | } |
| 1351 | |
| 1352 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1353 | Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1354 | { |
| 1355 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1356 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1357 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1358 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1359 | p->kind = Global_kind; |
| 1360 | p->v.Global.names = names; |
| 1361 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1362 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1363 | return p; |
| 1364 | } |
| 1365 | |
| 1366 | stmt_ty |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 1367 | Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
| 1368 | { |
| 1369 | stmt_ty p; |
| 1370 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1371 | if (!p) |
| 1372 | return NULL; |
| 1373 | p->kind = Nonlocal_kind; |
| 1374 | p->v.Nonlocal.names = names; |
| 1375 | p->lineno = lineno; |
| 1376 | p->col_offset = col_offset; |
| 1377 | return p; |
| 1378 | } |
| 1379 | |
| 1380 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1381 | Expr(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1382 | { |
| 1383 | stmt_ty p; |
| 1384 | if (!value) { |
| 1385 | PyErr_SetString(PyExc_ValueError, |
| 1386 | "field value is required for Expr"); |
| 1387 | return NULL; |
| 1388 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1389 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1390 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1391 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1392 | p->kind = Expr_kind; |
| 1393 | p->v.Expr.value = value; |
| 1394 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1395 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1396 | return p; |
| 1397 | } |
| 1398 | |
| 1399 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1400 | Pass(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1401 | { |
| 1402 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1403 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1404 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1405 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1406 | p->kind = Pass_kind; |
| 1407 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1408 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1409 | return p; |
| 1410 | } |
| 1411 | |
| 1412 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1413 | Break(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1414 | { |
| 1415 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1416 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1417 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1418 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1419 | p->kind = Break_kind; |
| 1420 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1421 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1422 | return p; |
| 1423 | } |
| 1424 | |
| 1425 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1426 | Continue(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1427 | { |
| 1428 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1429 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1430 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1431 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1432 | p->kind = Continue_kind; |
| 1433 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1434 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1435 | return p; |
| 1436 | } |
| 1437 | |
| 1438 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1439 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1440 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1441 | { |
| 1442 | expr_ty p; |
| 1443 | if (!op) { |
| 1444 | PyErr_SetString(PyExc_ValueError, |
| 1445 | "field op is required for BoolOp"); |
| 1446 | return NULL; |
| 1447 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1448 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1449 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1450 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1451 | p->kind = BoolOp_kind; |
| 1452 | p->v.BoolOp.op = op; |
| 1453 | p->v.BoolOp.values = values; |
| 1454 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1455 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1456 | return p; |
| 1457 | } |
| 1458 | |
| 1459 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1460 | BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset, |
| 1461 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1462 | { |
| 1463 | expr_ty p; |
| 1464 | if (!left) { |
| 1465 | PyErr_SetString(PyExc_ValueError, |
| 1466 | "field left is required for BinOp"); |
| 1467 | return NULL; |
| 1468 | } |
| 1469 | if (!op) { |
| 1470 | PyErr_SetString(PyExc_ValueError, |
| 1471 | "field op is required for BinOp"); |
| 1472 | return NULL; |
| 1473 | } |
| 1474 | if (!right) { |
| 1475 | PyErr_SetString(PyExc_ValueError, |
| 1476 | "field right is required for BinOp"); |
| 1477 | return NULL; |
| 1478 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1479 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1480 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1481 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1482 | p->kind = BinOp_kind; |
| 1483 | p->v.BinOp.left = left; |
| 1484 | p->v.BinOp.op = op; |
| 1485 | p->v.BinOp.right = right; |
| 1486 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1487 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1488 | return p; |
| 1489 | } |
| 1490 | |
| 1491 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1492 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena |
| 1493 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1494 | { |
| 1495 | expr_ty p; |
| 1496 | if (!op) { |
| 1497 | PyErr_SetString(PyExc_ValueError, |
| 1498 | "field op is required for UnaryOp"); |
| 1499 | return NULL; |
| 1500 | } |
| 1501 | if (!operand) { |
| 1502 | PyErr_SetString(PyExc_ValueError, |
| 1503 | "field operand is required for UnaryOp"); |
| 1504 | return NULL; |
| 1505 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1506 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1507 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1508 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1509 | p->kind = UnaryOp_kind; |
| 1510 | p->v.UnaryOp.op = op; |
| 1511 | p->v.UnaryOp.operand = operand; |
| 1512 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1513 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1514 | return p; |
| 1515 | } |
| 1516 | |
| 1517 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1518 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena |
| 1519 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1520 | { |
| 1521 | expr_ty p; |
| 1522 | if (!args) { |
| 1523 | PyErr_SetString(PyExc_ValueError, |
| 1524 | "field args is required for Lambda"); |
| 1525 | return NULL; |
| 1526 | } |
| 1527 | if (!body) { |
| 1528 | PyErr_SetString(PyExc_ValueError, |
| 1529 | "field body is required for Lambda"); |
| 1530 | return NULL; |
| 1531 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1532 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1533 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1534 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1535 | p->kind = Lambda_kind; |
| 1536 | p->v.Lambda.args = args; |
| 1537 | p->v.Lambda.body = body; |
| 1538 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1539 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1540 | return p; |
| 1541 | } |
| 1542 | |
| 1543 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1544 | IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset, |
| 1545 | PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1546 | { |
| 1547 | expr_ty p; |
| 1548 | if (!test) { |
| 1549 | PyErr_SetString(PyExc_ValueError, |
| 1550 | "field test is required for IfExp"); |
| 1551 | return NULL; |
| 1552 | } |
| 1553 | if (!body) { |
| 1554 | PyErr_SetString(PyExc_ValueError, |
| 1555 | "field body is required for IfExp"); |
| 1556 | return NULL; |
| 1557 | } |
| 1558 | if (!orelse) { |
| 1559 | PyErr_SetString(PyExc_ValueError, |
| 1560 | "field orelse is required for IfExp"); |
| 1561 | return NULL; |
| 1562 | } |
| 1563 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1564 | if (!p) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1565 | return NULL; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1566 | p->kind = IfExp_kind; |
| 1567 | p->v.IfExp.test = test; |
| 1568 | p->v.IfExp.body = body; |
| 1569 | p->v.IfExp.orelse = orelse; |
| 1570 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1571 | p->col_offset = col_offset; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1572 | return p; |
| 1573 | } |
| 1574 | |
| 1575 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1576 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1577 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1578 | { |
| 1579 | expr_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1580 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1581 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1582 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1583 | p->kind = Dict_kind; |
| 1584 | p->v.Dict.keys = keys; |
| 1585 | p->v.Dict.values = values; |
| 1586 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1587 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1588 | return p; |
| 1589 | } |
| 1590 | |
| 1591 | expr_ty |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1592 | Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena) |
| 1593 | { |
| 1594 | expr_ty p; |
| 1595 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1596 | if (!p) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1597 | return NULL; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1598 | p->kind = Set_kind; |
| 1599 | p->v.Set.elts = elts; |
| 1600 | p->lineno = lineno; |
| 1601 | p->col_offset = col_offset; |
| 1602 | return p; |
| 1603 | } |
| 1604 | |
| 1605 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1606 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1607 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1608 | { |
| 1609 | expr_ty p; |
| 1610 | if (!elt) { |
| 1611 | PyErr_SetString(PyExc_ValueError, |
| 1612 | "field elt is required for ListComp"); |
| 1613 | return NULL; |
| 1614 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1615 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1616 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1617 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1618 | p->kind = ListComp_kind; |
| 1619 | p->v.ListComp.elt = elt; |
| 1620 | p->v.ListComp.generators = generators; |
| 1621 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1622 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1623 | return p; |
| 1624 | } |
| 1625 | |
| 1626 | expr_ty |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 1627 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena |
| 1628 | *arena) |
| 1629 | { |
| 1630 | expr_ty p; |
| 1631 | if (!elt) { |
| 1632 | PyErr_SetString(PyExc_ValueError, |
| 1633 | "field elt is required for SetComp"); |
| 1634 | return NULL; |
| 1635 | } |
| 1636 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1637 | if (!p) |
| 1638 | return NULL; |
| 1639 | p->kind = SetComp_kind; |
| 1640 | p->v.SetComp.elt = elt; |
| 1641 | p->v.SetComp.generators = generators; |
| 1642 | p->lineno = lineno; |
| 1643 | p->col_offset = col_offset; |
| 1644 | return p; |
| 1645 | } |
| 1646 | |
| 1647 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 1648 | DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int |
| 1649 | col_offset, PyArena *arena) |
| 1650 | { |
| 1651 | expr_ty p; |
| 1652 | if (!key) { |
| 1653 | PyErr_SetString(PyExc_ValueError, |
| 1654 | "field key is required for DictComp"); |
| 1655 | return NULL; |
| 1656 | } |
| 1657 | if (!value) { |
| 1658 | PyErr_SetString(PyExc_ValueError, |
| 1659 | "field value is required for DictComp"); |
| 1660 | return NULL; |
| 1661 | } |
| 1662 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1663 | if (!p) |
| 1664 | return NULL; |
| 1665 | p->kind = DictComp_kind; |
| 1666 | p->v.DictComp.key = key; |
| 1667 | p->v.DictComp.value = value; |
| 1668 | p->v.DictComp.generators = generators; |
| 1669 | p->lineno = lineno; |
| 1670 | p->col_offset = col_offset; |
| 1671 | return p; |
| 1672 | } |
| 1673 | |
| 1674 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1675 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1676 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1677 | { |
| 1678 | expr_ty p; |
| 1679 | if (!elt) { |
| 1680 | PyErr_SetString(PyExc_ValueError, |
| 1681 | "field elt is required for GeneratorExp"); |
| 1682 | return NULL; |
| 1683 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1684 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1685 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1686 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1687 | p->kind = GeneratorExp_kind; |
| 1688 | p->v.GeneratorExp.elt = elt; |
| 1689 | p->v.GeneratorExp.generators = generators; |
| 1690 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1691 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1692 | return p; |
| 1693 | } |
| 1694 | |
| 1695 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1696 | Yield(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1697 | { |
| 1698 | expr_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1699 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1700 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1701 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1702 | p->kind = Yield_kind; |
| 1703 | p->v.Yield.value = value; |
| 1704 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1705 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1706 | return p; |
| 1707 | } |
| 1708 | |
| 1709 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1710 | Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno, |
| 1711 | int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1712 | { |
| 1713 | expr_ty p; |
| 1714 | if (!left) { |
| 1715 | PyErr_SetString(PyExc_ValueError, |
| 1716 | "field left is required for Compare"); |
| 1717 | return NULL; |
| 1718 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1719 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1720 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1721 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1722 | p->kind = Compare_kind; |
| 1723 | p->v.Compare.left = left; |
| 1724 | p->v.Compare.ops = ops; |
| 1725 | p->v.Compare.comparators = comparators; |
| 1726 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1727 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1728 | return p; |
| 1729 | } |
| 1730 | |
| 1731 | expr_ty |
| 1732 | 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] | 1733 | expr_ty kwargs, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1734 | { |
| 1735 | expr_ty p; |
| 1736 | if (!func) { |
| 1737 | PyErr_SetString(PyExc_ValueError, |
| 1738 | "field func is required for Call"); |
| 1739 | return NULL; |
| 1740 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1741 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1742 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1743 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1744 | p->kind = Call_kind; |
| 1745 | p->v.Call.func = func; |
| 1746 | p->v.Call.args = args; |
| 1747 | p->v.Call.keywords = keywords; |
| 1748 | p->v.Call.starargs = starargs; |
| 1749 | p->v.Call.kwargs = kwargs; |
| 1750 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1751 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1752 | return p; |
| 1753 | } |
| 1754 | |
| 1755 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1756 | Num(object n, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1757 | { |
| 1758 | expr_ty p; |
| 1759 | if (!n) { |
| 1760 | PyErr_SetString(PyExc_ValueError, |
| 1761 | "field n is required for Num"); |
| 1762 | return NULL; |
| 1763 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1764 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1765 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1766 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1767 | p->kind = Num_kind; |
| 1768 | p->v.Num.n = n; |
| 1769 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1770 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1771 | return p; |
| 1772 | } |
| 1773 | |
| 1774 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1775 | Str(string s, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1776 | { |
| 1777 | expr_ty p; |
| 1778 | if (!s) { |
| 1779 | PyErr_SetString(PyExc_ValueError, |
| 1780 | "field s is required for Str"); |
| 1781 | return NULL; |
| 1782 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1783 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1784 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1785 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1786 | p->kind = Str_kind; |
| 1787 | p->v.Str.s = s; |
| 1788 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1789 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1790 | return p; |
| 1791 | } |
| 1792 | |
| 1793 | expr_ty |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1794 | Bytes(string s, int lineno, int col_offset, PyArena *arena) |
| 1795 | { |
| 1796 | expr_ty p; |
| 1797 | if (!s) { |
| 1798 | PyErr_SetString(PyExc_ValueError, |
| 1799 | "field s is required for Bytes"); |
| 1800 | return NULL; |
| 1801 | } |
| 1802 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1803 | if (!p) |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1804 | return NULL; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1805 | p->kind = Bytes_kind; |
| 1806 | p->v.Bytes.s = s; |
| 1807 | p->lineno = lineno; |
| 1808 | p->col_offset = col_offset; |
| 1809 | return p; |
| 1810 | } |
| 1811 | |
| 1812 | expr_ty |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1813 | Ellipsis(int lineno, int col_offset, PyArena *arena) |
| 1814 | { |
| 1815 | expr_ty p; |
| 1816 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1817 | if (!p) |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1818 | return NULL; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1819 | p->kind = Ellipsis_kind; |
| 1820 | p->lineno = lineno; |
| 1821 | p->col_offset = col_offset; |
| 1822 | return p; |
| 1823 | } |
| 1824 | |
| 1825 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1826 | Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int |
| 1827 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1828 | { |
| 1829 | expr_ty p; |
| 1830 | if (!value) { |
| 1831 | PyErr_SetString(PyExc_ValueError, |
| 1832 | "field value is required for Attribute"); |
| 1833 | return NULL; |
| 1834 | } |
| 1835 | if (!attr) { |
| 1836 | PyErr_SetString(PyExc_ValueError, |
| 1837 | "field attr is required for Attribute"); |
| 1838 | return NULL; |
| 1839 | } |
| 1840 | if (!ctx) { |
| 1841 | PyErr_SetString(PyExc_ValueError, |
| 1842 | "field ctx is required for Attribute"); |
| 1843 | return NULL; |
| 1844 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1845 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1846 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1847 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1848 | p->kind = Attribute_kind; |
| 1849 | p->v.Attribute.value = value; |
| 1850 | p->v.Attribute.attr = attr; |
| 1851 | p->v.Attribute.ctx = ctx; |
| 1852 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1853 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1854 | return p; |
| 1855 | } |
| 1856 | |
| 1857 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1858 | Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int |
| 1859 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1860 | { |
| 1861 | expr_ty p; |
| 1862 | if (!value) { |
| 1863 | PyErr_SetString(PyExc_ValueError, |
| 1864 | "field value is required for Subscript"); |
| 1865 | return NULL; |
| 1866 | } |
| 1867 | if (!slice) { |
| 1868 | PyErr_SetString(PyExc_ValueError, |
| 1869 | "field slice is required for Subscript"); |
| 1870 | return NULL; |
| 1871 | } |
| 1872 | if (!ctx) { |
| 1873 | PyErr_SetString(PyExc_ValueError, |
| 1874 | "field ctx is required for Subscript"); |
| 1875 | return NULL; |
| 1876 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1877 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1878 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1879 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1880 | p->kind = Subscript_kind; |
| 1881 | p->v.Subscript.value = value; |
| 1882 | p->v.Subscript.slice = slice; |
| 1883 | p->v.Subscript.ctx = ctx; |
| 1884 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1885 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1886 | return p; |
| 1887 | } |
| 1888 | |
| 1889 | expr_ty |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 1890 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1891 | *arena) |
| 1892 | { |
| 1893 | expr_ty p; |
| 1894 | if (!value) { |
| 1895 | PyErr_SetString(PyExc_ValueError, |
| 1896 | "field value is required for Starred"); |
| 1897 | return NULL; |
| 1898 | } |
| 1899 | if (!ctx) { |
| 1900 | PyErr_SetString(PyExc_ValueError, |
| 1901 | "field ctx is required for Starred"); |
| 1902 | return NULL; |
| 1903 | } |
| 1904 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1905 | if (!p) |
| 1906 | return NULL; |
| 1907 | p->kind = Starred_kind; |
| 1908 | p->v.Starred.value = value; |
| 1909 | p->v.Starred.ctx = ctx; |
| 1910 | p->lineno = lineno; |
| 1911 | p->col_offset = col_offset; |
| 1912 | return p; |
| 1913 | } |
| 1914 | |
| 1915 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1916 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1917 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1918 | { |
| 1919 | expr_ty p; |
| 1920 | if (!id) { |
| 1921 | PyErr_SetString(PyExc_ValueError, |
| 1922 | "field id is required for Name"); |
| 1923 | return NULL; |
| 1924 | } |
| 1925 | if (!ctx) { |
| 1926 | PyErr_SetString(PyExc_ValueError, |
| 1927 | "field ctx is required for Name"); |
| 1928 | return NULL; |
| 1929 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1930 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1931 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1932 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1933 | p->kind = Name_kind; |
| 1934 | p->v.Name.id = id; |
| 1935 | p->v.Name.ctx = ctx; |
| 1936 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1937 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1938 | return p; |
| 1939 | } |
| 1940 | |
| 1941 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1942 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1943 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1944 | { |
| 1945 | expr_ty p; |
| 1946 | if (!ctx) { |
| 1947 | PyErr_SetString(PyExc_ValueError, |
| 1948 | "field ctx is required for List"); |
| 1949 | return NULL; |
| 1950 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1951 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1952 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1953 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1954 | p->kind = List_kind; |
| 1955 | p->v.List.elts = elts; |
| 1956 | p->v.List.ctx = ctx; |
| 1957 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1958 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1959 | return p; |
| 1960 | } |
| 1961 | |
| 1962 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1963 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1964 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1965 | { |
| 1966 | expr_ty p; |
| 1967 | if (!ctx) { |
| 1968 | PyErr_SetString(PyExc_ValueError, |
| 1969 | "field ctx is required for Tuple"); |
| 1970 | return NULL; |
| 1971 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1972 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1973 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1974 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1975 | p->kind = Tuple_kind; |
| 1976 | p->v.Tuple.elts = elts; |
| 1977 | p->v.Tuple.ctx = ctx; |
| 1978 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1979 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1980 | return p; |
| 1981 | } |
| 1982 | |
| 1983 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1984 | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1985 | { |
| 1986 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1987 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1988 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1989 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1990 | p->kind = Slice_kind; |
| 1991 | p->v.Slice.lower = lower; |
| 1992 | p->v.Slice.upper = upper; |
| 1993 | p->v.Slice.step = step; |
| 1994 | return p; |
| 1995 | } |
| 1996 | |
| 1997 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1998 | ExtSlice(asdl_seq * dims, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1999 | { |
| 2000 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2001 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2002 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2003 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2004 | p->kind = ExtSlice_kind; |
| 2005 | p->v.ExtSlice.dims = dims; |
| 2006 | return p; |
| 2007 | } |
| 2008 | |
| 2009 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2010 | Index(expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2011 | { |
| 2012 | slice_ty p; |
| 2013 | if (!value) { |
| 2014 | PyErr_SetString(PyExc_ValueError, |
| 2015 | "field value is required for Index"); |
| 2016 | return NULL; |
| 2017 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2018 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2019 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2020 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2021 | p->kind = Index_kind; |
| 2022 | p->v.Index.value = value; |
| 2023 | return p; |
| 2024 | } |
| 2025 | |
| 2026 | comprehension_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2027 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2028 | { |
| 2029 | comprehension_ty p; |
| 2030 | if (!target) { |
| 2031 | PyErr_SetString(PyExc_ValueError, |
| 2032 | "field target is required for comprehension"); |
| 2033 | return NULL; |
| 2034 | } |
| 2035 | if (!iter) { |
| 2036 | PyErr_SetString(PyExc_ValueError, |
| 2037 | "field iter is required for comprehension"); |
| 2038 | return NULL; |
| 2039 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2040 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2041 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2042 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2043 | p->target = target; |
| 2044 | p->iter = iter; |
| 2045 | p->ifs = ifs; |
| 2046 | return p; |
| 2047 | } |
| 2048 | |
| 2049 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 2050 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2051 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2052 | { |
| 2053 | excepthandler_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2054 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2055 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2056 | return NULL; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 2057 | p->kind = ExceptHandler_kind; |
| 2058 | p->v.ExceptHandler.type = type; |
| 2059 | p->v.ExceptHandler.name = name; |
| 2060 | p->v.ExceptHandler.body = body; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2061 | p->lineno = lineno; |
| 2062 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2063 | return p; |
| 2064 | } |
| 2065 | |
| 2066 | arguments_ty |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2067 | arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation, |
| 2068 | asdl_seq * kwonlyargs, identifier kwarg, expr_ty kwargannotation, |
| 2069 | asdl_seq * defaults, asdl_seq * kw_defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2070 | { |
| 2071 | arguments_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2072 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2073 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2074 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2075 | p->args = args; |
| 2076 | p->vararg = vararg; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2077 | p->varargannotation = varargannotation; |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 2078 | p->kwonlyargs = kwonlyargs; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2079 | p->kwarg = kwarg; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2080 | p->kwargannotation = kwargannotation; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2081 | p->defaults = defaults; |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 2082 | p->kw_defaults = kw_defaults; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2083 | return p; |
| 2084 | } |
| 2085 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2086 | arg_ty |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2087 | arg(identifier arg, expr_ty annotation, PyArena *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2088 | { |
| 2089 | arg_ty p; |
| 2090 | if (!arg) { |
| 2091 | PyErr_SetString(PyExc_ValueError, |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2092 | "field arg is required for arg"); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2093 | return NULL; |
| 2094 | } |
| 2095 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2096 | if (!p) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2097 | return NULL; |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2098 | p->arg = arg; |
| 2099 | p->annotation = annotation; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2100 | return p; |
| 2101 | } |
| 2102 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2103 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2104 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2105 | { |
| 2106 | keyword_ty p; |
| 2107 | if (!arg) { |
| 2108 | PyErr_SetString(PyExc_ValueError, |
| 2109 | "field arg is required for keyword"); |
| 2110 | return NULL; |
| 2111 | } |
| 2112 | if (!value) { |
| 2113 | PyErr_SetString(PyExc_ValueError, |
| 2114 | "field value is required for keyword"); |
| 2115 | return NULL; |
| 2116 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2117 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2118 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2119 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2120 | p->arg = arg; |
| 2121 | p->value = value; |
| 2122 | return p; |
| 2123 | } |
| 2124 | |
| 2125 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2126 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2127 | { |
| 2128 | alias_ty p; |
| 2129 | if (!name) { |
| 2130 | PyErr_SetString(PyExc_ValueError, |
| 2131 | "field name is required for alias"); |
| 2132 | return NULL; |
| 2133 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2134 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2135 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2136 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2137 | p->name = name; |
| 2138 | p->asname = asname; |
| 2139 | return p; |
| 2140 | } |
| 2141 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2142 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2143 | PyObject* |
| 2144 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2145 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2146 | mod_ty o = (mod_ty)_o; |
| 2147 | PyObject *result = NULL, *value = NULL; |
| 2148 | if (!o) { |
| 2149 | Py_INCREF(Py_None); |
| 2150 | return Py_None; |
| 2151 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2152 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2153 | switch (o->kind) { |
| 2154 | case Module_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2155 | result = PyType_GenericNew(Module_type, NULL, NULL); |
| 2156 | if (!result) goto failed; |
| 2157 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 2158 | if (!value) goto failed; |
| 2159 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2160 | goto failed; |
| 2161 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2162 | break; |
| 2163 | case Interactive_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2164 | result = PyType_GenericNew(Interactive_type, NULL, NULL); |
| 2165 | if (!result) goto failed; |
| 2166 | value = ast2obj_list(o->v.Interactive.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 Expression_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2173 | result = PyType_GenericNew(Expression_type, NULL, NULL); |
| 2174 | if (!result) goto failed; |
| 2175 | value = ast2obj_expr(o->v.Expression.body); |
| 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 Suite_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2182 | result = PyType_GenericNew(Suite_type, NULL, NULL); |
| 2183 | if (!result) goto failed; |
| 2184 | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
| 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 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2191 | return result; |
| 2192 | failed: |
| 2193 | Py_XDECREF(value); |
| 2194 | Py_XDECREF(result); |
| 2195 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2196 | } |
| 2197 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2198 | PyObject* |
| 2199 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2200 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2201 | stmt_ty o = (stmt_ty)_o; |
| 2202 | PyObject *result = NULL, *value = NULL; |
| 2203 | if (!o) { |
| 2204 | Py_INCREF(Py_None); |
| 2205 | return Py_None; |
| 2206 | } |
| 2207 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2208 | switch (o->kind) { |
| 2209 | case FunctionDef_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2210 | result = PyType_GenericNew(FunctionDef_type, NULL, NULL); |
| 2211 | if (!result) goto failed; |
| 2212 | value = ast2obj_identifier(o->v.FunctionDef.name); |
| 2213 | if (!value) goto failed; |
| 2214 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 2215 | goto failed; |
| 2216 | Py_DECREF(value); |
| 2217 | value = ast2obj_arguments(o->v.FunctionDef.args); |
| 2218 | if (!value) goto failed; |
| 2219 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 2220 | goto failed; |
| 2221 | Py_DECREF(value); |
| 2222 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 2223 | if (!value) goto failed; |
| 2224 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2225 | goto failed; |
| 2226 | Py_DECREF(value); |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2227 | value = ast2obj_list(o->v.FunctionDef.decorator_list, |
| 2228 | ast2obj_expr); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2229 | if (!value) goto failed; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2230 | if (PyObject_SetAttrString(result, "decorator_list", value) == |
| 2231 | -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2232 | goto failed; |
| 2233 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2234 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 2235 | if (!value) goto failed; |
| 2236 | if (PyObject_SetAttrString(result, "returns", value) == -1) |
| 2237 | goto failed; |
| 2238 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2239 | break; |
| 2240 | case ClassDef_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2241 | result = PyType_GenericNew(ClassDef_type, NULL, NULL); |
| 2242 | if (!result) goto failed; |
| 2243 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 2244 | if (!value) goto failed; |
| 2245 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 2246 | goto failed; |
| 2247 | Py_DECREF(value); |
| 2248 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 2249 | if (!value) goto failed; |
| 2250 | if (PyObject_SetAttrString(result, "bases", value) == -1) |
| 2251 | goto failed; |
| 2252 | Py_DECREF(value); |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 2253 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 2254 | if (!value) goto failed; |
| 2255 | if (PyObject_SetAttrString(result, "keywords", value) == -1) |
| 2256 | goto failed; |
| 2257 | Py_DECREF(value); |
| 2258 | value = ast2obj_expr(o->v.ClassDef.starargs); |
| 2259 | if (!value) goto failed; |
| 2260 | if (PyObject_SetAttrString(result, "starargs", value) == -1) |
| 2261 | goto failed; |
| 2262 | Py_DECREF(value); |
| 2263 | value = ast2obj_expr(o->v.ClassDef.kwargs); |
| 2264 | if (!value) goto failed; |
| 2265 | if (PyObject_SetAttrString(result, "kwargs", value) == -1) |
| 2266 | goto failed; |
| 2267 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2268 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 2269 | if (!value) goto failed; |
| 2270 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2271 | goto failed; |
| 2272 | Py_DECREF(value); |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2273 | value = ast2obj_list(o->v.ClassDef.decorator_list, |
| 2274 | ast2obj_expr); |
| 2275 | if (!value) goto failed; |
| 2276 | if (PyObject_SetAttrString(result, "decorator_list", value) == |
| 2277 | -1) |
| 2278 | goto failed; |
| 2279 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2280 | break; |
| 2281 | case Return_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2282 | result = PyType_GenericNew(Return_type, NULL, NULL); |
| 2283 | if (!result) goto failed; |
| 2284 | value = ast2obj_expr(o->v.Return.value); |
| 2285 | if (!value) goto failed; |
| 2286 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2287 | goto failed; |
| 2288 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2289 | break; |
| 2290 | case Delete_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2291 | result = PyType_GenericNew(Delete_type, NULL, NULL); |
| 2292 | if (!result) goto failed; |
| 2293 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 2294 | if (!value) goto failed; |
| 2295 | if (PyObject_SetAttrString(result, "targets", 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 Assign_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2300 | result = PyType_GenericNew(Assign_type, NULL, NULL); |
| 2301 | if (!result) goto failed; |
| 2302 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 2303 | if (!value) goto failed; |
| 2304 | if (PyObject_SetAttrString(result, "targets", value) == -1) |
| 2305 | goto failed; |
| 2306 | Py_DECREF(value); |
| 2307 | value = ast2obj_expr(o->v.Assign.value); |
| 2308 | if (!value) goto failed; |
| 2309 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2310 | goto failed; |
| 2311 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2312 | break; |
| 2313 | case AugAssign_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2314 | result = PyType_GenericNew(AugAssign_type, NULL, NULL); |
| 2315 | if (!result) goto failed; |
| 2316 | value = ast2obj_expr(o->v.AugAssign.target); |
| 2317 | if (!value) goto failed; |
| 2318 | if (PyObject_SetAttrString(result, "target", value) == -1) |
| 2319 | goto failed; |
| 2320 | Py_DECREF(value); |
| 2321 | value = ast2obj_operator(o->v.AugAssign.op); |
| 2322 | if (!value) goto failed; |
| 2323 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2324 | goto failed; |
| 2325 | Py_DECREF(value); |
| 2326 | value = ast2obj_expr(o->v.AugAssign.value); |
| 2327 | if (!value) goto failed; |
| 2328 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2329 | goto failed; |
| 2330 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2331 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2332 | case For_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2333 | result = PyType_GenericNew(For_type, NULL, NULL); |
| 2334 | if (!result) goto failed; |
| 2335 | value = ast2obj_expr(o->v.For.target); |
| 2336 | if (!value) goto failed; |
| 2337 | if (PyObject_SetAttrString(result, "target", value) == -1) |
| 2338 | goto failed; |
| 2339 | Py_DECREF(value); |
| 2340 | value = ast2obj_expr(o->v.For.iter); |
| 2341 | if (!value) goto failed; |
| 2342 | if (PyObject_SetAttrString(result, "iter", value) == -1) |
| 2343 | goto failed; |
| 2344 | Py_DECREF(value); |
| 2345 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 2346 | if (!value) goto failed; |
| 2347 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2348 | goto failed; |
| 2349 | Py_DECREF(value); |
| 2350 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 2351 | if (!value) goto failed; |
| 2352 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2353 | goto failed; |
| 2354 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2355 | break; |
| 2356 | case While_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2357 | result = PyType_GenericNew(While_type, NULL, NULL); |
| 2358 | if (!result) goto failed; |
| 2359 | value = ast2obj_expr(o->v.While.test); |
| 2360 | if (!value) goto failed; |
| 2361 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2362 | goto failed; |
| 2363 | Py_DECREF(value); |
| 2364 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 2365 | if (!value) goto failed; |
| 2366 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2367 | goto failed; |
| 2368 | Py_DECREF(value); |
| 2369 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 2370 | if (!value) goto failed; |
| 2371 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2372 | goto failed; |
| 2373 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2374 | break; |
| 2375 | case If_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2376 | result = PyType_GenericNew(If_type, NULL, NULL); |
| 2377 | if (!result) goto failed; |
| 2378 | value = ast2obj_expr(o->v.If.test); |
| 2379 | if (!value) goto failed; |
| 2380 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2381 | goto failed; |
| 2382 | Py_DECREF(value); |
| 2383 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 2384 | if (!value) goto failed; |
| 2385 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2386 | goto failed; |
| 2387 | Py_DECREF(value); |
| 2388 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 2389 | if (!value) goto failed; |
| 2390 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2391 | goto failed; |
| 2392 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2393 | break; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2394 | case With_kind: |
| 2395 | result = PyType_GenericNew(With_type, NULL, NULL); |
| 2396 | if (!result) goto failed; |
| 2397 | value = ast2obj_expr(o->v.With.context_expr); |
| 2398 | if (!value) goto failed; |
| 2399 | if (PyObject_SetAttrString(result, "context_expr", value) == -1) |
| 2400 | goto failed; |
| 2401 | Py_DECREF(value); |
| 2402 | value = ast2obj_expr(o->v.With.optional_vars); |
| 2403 | if (!value) goto failed; |
| 2404 | if (PyObject_SetAttrString(result, "optional_vars", value) == |
| 2405 | -1) |
| 2406 | goto failed; |
| 2407 | Py_DECREF(value); |
| 2408 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 2409 | if (!value) goto failed; |
| 2410 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2411 | goto failed; |
| 2412 | Py_DECREF(value); |
| 2413 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2414 | case Raise_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2415 | result = PyType_GenericNew(Raise_type, NULL, NULL); |
| 2416 | if (!result) goto failed; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2417 | value = ast2obj_expr(o->v.Raise.exc); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2418 | if (!value) goto failed; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2419 | if (PyObject_SetAttrString(result, "exc", value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2420 | goto failed; |
| 2421 | Py_DECREF(value); |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2422 | value = ast2obj_expr(o->v.Raise.cause); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2423 | if (!value) goto failed; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2424 | if (PyObject_SetAttrString(result, "cause", value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2425 | goto failed; |
| 2426 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2427 | break; |
| 2428 | case TryExcept_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2429 | result = PyType_GenericNew(TryExcept_type, NULL, NULL); |
| 2430 | if (!result) goto failed; |
| 2431 | value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt); |
| 2432 | if (!value) goto failed; |
| 2433 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2434 | goto failed; |
| 2435 | Py_DECREF(value); |
| 2436 | value = ast2obj_list(o->v.TryExcept.handlers, |
| 2437 | ast2obj_excepthandler); |
| 2438 | if (!value) goto failed; |
| 2439 | if (PyObject_SetAttrString(result, "handlers", value) == -1) |
| 2440 | goto failed; |
| 2441 | Py_DECREF(value); |
| 2442 | value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt); |
| 2443 | if (!value) goto failed; |
| 2444 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2445 | goto failed; |
| 2446 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2447 | break; |
| 2448 | case TryFinally_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2449 | result = PyType_GenericNew(TryFinally_type, NULL, NULL); |
| 2450 | if (!result) goto failed; |
| 2451 | value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt); |
| 2452 | if (!value) goto failed; |
| 2453 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2454 | goto failed; |
| 2455 | Py_DECREF(value); |
| 2456 | value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt); |
| 2457 | if (!value) goto failed; |
| 2458 | if (PyObject_SetAttrString(result, "finalbody", value) == -1) |
| 2459 | goto failed; |
| 2460 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2461 | break; |
| 2462 | case Assert_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2463 | result = PyType_GenericNew(Assert_type, NULL, NULL); |
| 2464 | if (!result) goto failed; |
| 2465 | value = ast2obj_expr(o->v.Assert.test); |
| 2466 | if (!value) goto failed; |
| 2467 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2468 | goto failed; |
| 2469 | Py_DECREF(value); |
| 2470 | value = ast2obj_expr(o->v.Assert.msg); |
| 2471 | if (!value) goto failed; |
| 2472 | if (PyObject_SetAttrString(result, "msg", value) == -1) |
| 2473 | goto failed; |
| 2474 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2475 | break; |
| 2476 | case Import_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2477 | result = PyType_GenericNew(Import_type, NULL, NULL); |
| 2478 | if (!result) goto failed; |
| 2479 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 2480 | if (!value) goto failed; |
| 2481 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2482 | goto failed; |
| 2483 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2484 | break; |
| 2485 | case ImportFrom_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2486 | result = PyType_GenericNew(ImportFrom_type, NULL, NULL); |
| 2487 | if (!result) goto failed; |
| 2488 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 2489 | if (!value) goto failed; |
| 2490 | if (PyObject_SetAttrString(result, "module", value) == -1) |
| 2491 | goto failed; |
| 2492 | Py_DECREF(value); |
| 2493 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 2494 | if (!value) goto failed; |
| 2495 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2496 | goto failed; |
| 2497 | Py_DECREF(value); |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 2498 | value = ast2obj_int(o->v.ImportFrom.level); |
| 2499 | if (!value) goto failed; |
| 2500 | if (PyObject_SetAttrString(result, "level", value) == -1) |
| 2501 | goto failed; |
| 2502 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2503 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2504 | case Global_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2505 | result = PyType_GenericNew(Global_type, NULL, NULL); |
| 2506 | if (!result) goto failed; |
| 2507 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 2508 | if (!value) goto failed; |
| 2509 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2510 | goto failed; |
| 2511 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2512 | break; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2513 | case Nonlocal_kind: |
| 2514 | result = PyType_GenericNew(Nonlocal_type, NULL, NULL); |
| 2515 | if (!result) goto failed; |
| 2516 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 2517 | if (!value) goto failed; |
| 2518 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2519 | goto failed; |
| 2520 | Py_DECREF(value); |
| 2521 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2522 | case Expr_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2523 | result = PyType_GenericNew(Expr_type, NULL, NULL); |
| 2524 | if (!result) goto failed; |
| 2525 | value = ast2obj_expr(o->v.Expr.value); |
| 2526 | if (!value) goto failed; |
| 2527 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2528 | goto failed; |
| 2529 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2530 | break; |
| 2531 | case Pass_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2532 | result = PyType_GenericNew(Pass_type, NULL, NULL); |
| 2533 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2534 | break; |
| 2535 | case Break_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2536 | result = PyType_GenericNew(Break_type, NULL, NULL); |
| 2537 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2538 | break; |
| 2539 | case Continue_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2540 | result = PyType_GenericNew(Continue_type, NULL, NULL); |
| 2541 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2542 | break; |
| 2543 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2544 | value = ast2obj_int(o->lineno); |
| 2545 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2546 | if (PyObject_SetAttrString(result, "lineno", value) < 0) |
| 2547 | goto failed; |
| 2548 | Py_DECREF(value); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2549 | value = ast2obj_int(o->col_offset); |
| 2550 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2551 | if (PyObject_SetAttrString(result, "col_offset", value) < 0) |
| 2552 | goto failed; |
| 2553 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2554 | return result; |
| 2555 | failed: |
| 2556 | Py_XDECREF(value); |
| 2557 | Py_XDECREF(result); |
| 2558 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2559 | } |
| 2560 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2561 | PyObject* |
| 2562 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2563 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2564 | expr_ty o = (expr_ty)_o; |
| 2565 | PyObject *result = NULL, *value = NULL; |
| 2566 | if (!o) { |
| 2567 | Py_INCREF(Py_None); |
| 2568 | return Py_None; |
| 2569 | } |
| 2570 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2571 | switch (o->kind) { |
| 2572 | case BoolOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2573 | result = PyType_GenericNew(BoolOp_type, NULL, NULL); |
| 2574 | if (!result) goto failed; |
| 2575 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 2576 | if (!value) goto failed; |
| 2577 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2578 | goto failed; |
| 2579 | Py_DECREF(value); |
| 2580 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 2581 | if (!value) goto failed; |
| 2582 | if (PyObject_SetAttrString(result, "values", value) == -1) |
| 2583 | goto failed; |
| 2584 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2585 | break; |
| 2586 | case BinOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2587 | result = PyType_GenericNew(BinOp_type, NULL, NULL); |
| 2588 | if (!result) goto failed; |
| 2589 | value = ast2obj_expr(o->v.BinOp.left); |
| 2590 | if (!value) goto failed; |
| 2591 | if (PyObject_SetAttrString(result, "left", value) == -1) |
| 2592 | goto failed; |
| 2593 | Py_DECREF(value); |
| 2594 | value = ast2obj_operator(o->v.BinOp.op); |
| 2595 | if (!value) goto failed; |
| 2596 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2597 | goto failed; |
| 2598 | Py_DECREF(value); |
| 2599 | value = ast2obj_expr(o->v.BinOp.right); |
| 2600 | if (!value) goto failed; |
| 2601 | if (PyObject_SetAttrString(result, "right", value) == -1) |
| 2602 | goto failed; |
| 2603 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2604 | break; |
| 2605 | case UnaryOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2606 | result = PyType_GenericNew(UnaryOp_type, NULL, NULL); |
| 2607 | if (!result) goto failed; |
| 2608 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 2609 | if (!value) goto failed; |
| 2610 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2611 | goto failed; |
| 2612 | Py_DECREF(value); |
| 2613 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 2614 | if (!value) goto failed; |
| 2615 | if (PyObject_SetAttrString(result, "operand", value) == -1) |
| 2616 | goto failed; |
| 2617 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2618 | break; |
| 2619 | case Lambda_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2620 | result = PyType_GenericNew(Lambda_type, NULL, NULL); |
| 2621 | if (!result) goto failed; |
| 2622 | value = ast2obj_arguments(o->v.Lambda.args); |
| 2623 | if (!value) goto failed; |
| 2624 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 2625 | goto failed; |
| 2626 | Py_DECREF(value); |
| 2627 | value = ast2obj_expr(o->v.Lambda.body); |
| 2628 | if (!value) goto failed; |
| 2629 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2630 | goto failed; |
| 2631 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2632 | break; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2633 | case IfExp_kind: |
| 2634 | result = PyType_GenericNew(IfExp_type, NULL, NULL); |
| 2635 | if (!result) goto failed; |
| 2636 | value = ast2obj_expr(o->v.IfExp.test); |
| 2637 | if (!value) goto failed; |
| 2638 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2639 | goto failed; |
| 2640 | Py_DECREF(value); |
| 2641 | value = ast2obj_expr(o->v.IfExp.body); |
| 2642 | if (!value) goto failed; |
| 2643 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2644 | goto failed; |
| 2645 | Py_DECREF(value); |
| 2646 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 2647 | if (!value) goto failed; |
| 2648 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2649 | goto failed; |
| 2650 | Py_DECREF(value); |
| 2651 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2652 | case Dict_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2653 | result = PyType_GenericNew(Dict_type, NULL, NULL); |
| 2654 | if (!result) goto failed; |
| 2655 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 2656 | if (!value) goto failed; |
| 2657 | if (PyObject_SetAttrString(result, "keys", value) == -1) |
| 2658 | goto failed; |
| 2659 | Py_DECREF(value); |
| 2660 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 2661 | if (!value) goto failed; |
| 2662 | if (PyObject_SetAttrString(result, "values", value) == -1) |
| 2663 | goto failed; |
| 2664 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2665 | break; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2666 | case Set_kind: |
| 2667 | result = PyType_GenericNew(Set_type, NULL, NULL); |
| 2668 | if (!result) goto failed; |
| 2669 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 2670 | if (!value) goto failed; |
| 2671 | if (PyObject_SetAttrString(result, "elts", value) == -1) |
| 2672 | goto failed; |
| 2673 | Py_DECREF(value); |
| 2674 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2675 | case ListComp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2676 | result = PyType_GenericNew(ListComp_type, NULL, NULL); |
| 2677 | if (!result) goto failed; |
| 2678 | value = ast2obj_expr(o->v.ListComp.elt); |
| 2679 | if (!value) goto failed; |
| 2680 | if (PyObject_SetAttrString(result, "elt", value) == -1) |
| 2681 | goto failed; |
| 2682 | Py_DECREF(value); |
| 2683 | value = ast2obj_list(o->v.ListComp.generators, |
| 2684 | ast2obj_comprehension); |
| 2685 | if (!value) goto failed; |
| 2686 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2687 | goto failed; |
| 2688 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2689 | break; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2690 | case SetComp_kind: |
| 2691 | result = PyType_GenericNew(SetComp_type, NULL, NULL); |
| 2692 | if (!result) goto failed; |
| 2693 | value = ast2obj_expr(o->v.SetComp.elt); |
| 2694 | if (!value) goto failed; |
| 2695 | if (PyObject_SetAttrString(result, "elt", value) == -1) |
| 2696 | goto failed; |
| 2697 | Py_DECREF(value); |
| 2698 | value = ast2obj_list(o->v.SetComp.generators, |
| 2699 | ast2obj_comprehension); |
| 2700 | if (!value) goto failed; |
| 2701 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2702 | goto failed; |
| 2703 | Py_DECREF(value); |
| 2704 | break; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2705 | case DictComp_kind: |
| 2706 | result = PyType_GenericNew(DictComp_type, NULL, NULL); |
| 2707 | if (!result) goto failed; |
| 2708 | value = ast2obj_expr(o->v.DictComp.key); |
| 2709 | if (!value) goto failed; |
| 2710 | if (PyObject_SetAttrString(result, "key", value) == -1) |
| 2711 | goto failed; |
| 2712 | Py_DECREF(value); |
| 2713 | value = ast2obj_expr(o->v.DictComp.value); |
| 2714 | if (!value) goto failed; |
| 2715 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2716 | goto failed; |
| 2717 | Py_DECREF(value); |
| 2718 | value = ast2obj_list(o->v.DictComp.generators, |
| 2719 | ast2obj_comprehension); |
| 2720 | if (!value) goto failed; |
| 2721 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2722 | goto failed; |
| 2723 | Py_DECREF(value); |
| 2724 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2725 | case GeneratorExp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2726 | result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); |
| 2727 | if (!result) goto failed; |
| 2728 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 2729 | if (!value) goto failed; |
| 2730 | if (PyObject_SetAttrString(result, "elt", value) == -1) |
| 2731 | goto failed; |
| 2732 | Py_DECREF(value); |
| 2733 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 2734 | ast2obj_comprehension); |
| 2735 | if (!value) goto failed; |
| 2736 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2737 | goto failed; |
| 2738 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2739 | break; |
| 2740 | case Yield_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2741 | result = PyType_GenericNew(Yield_type, NULL, NULL); |
| 2742 | if (!result) goto failed; |
| 2743 | value = ast2obj_expr(o->v.Yield.value); |
| 2744 | if (!value) goto failed; |
| 2745 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2746 | goto failed; |
| 2747 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2748 | break; |
| 2749 | case Compare_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2750 | result = PyType_GenericNew(Compare_type, NULL, NULL); |
| 2751 | if (!result) goto failed; |
| 2752 | value = ast2obj_expr(o->v.Compare.left); |
| 2753 | if (!value) goto failed; |
| 2754 | if (PyObject_SetAttrString(result, "left", value) == -1) |
| 2755 | goto failed; |
| 2756 | Py_DECREF(value); |
Martin v. Löwis | ce1d5d2 | 2006-02-26 20:51:25 +0000 | [diff] [blame] | 2757 | { |
| 2758 | int i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 2759 | value = PyList_New(n); |
| 2760 | if (!value) goto failed; |
| 2761 | for(i = 0; i < n; i++) |
| 2762 | PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i))); |
| 2763 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2764 | if (!value) goto failed; |
| 2765 | if (PyObject_SetAttrString(result, "ops", value) == -1) |
| 2766 | goto failed; |
| 2767 | Py_DECREF(value); |
| 2768 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
| 2769 | if (!value) goto failed; |
| 2770 | if (PyObject_SetAttrString(result, "comparators", value) == -1) |
| 2771 | goto failed; |
| 2772 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2773 | break; |
| 2774 | case Call_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2775 | result = PyType_GenericNew(Call_type, NULL, NULL); |
| 2776 | if (!result) goto failed; |
| 2777 | value = ast2obj_expr(o->v.Call.func); |
| 2778 | if (!value) goto failed; |
| 2779 | if (PyObject_SetAttrString(result, "func", value) == -1) |
| 2780 | goto failed; |
| 2781 | Py_DECREF(value); |
| 2782 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 2783 | if (!value) goto failed; |
| 2784 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 2785 | goto failed; |
| 2786 | Py_DECREF(value); |
| 2787 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 2788 | if (!value) goto failed; |
| 2789 | if (PyObject_SetAttrString(result, "keywords", value) == -1) |
| 2790 | goto failed; |
| 2791 | Py_DECREF(value); |
| 2792 | value = ast2obj_expr(o->v.Call.starargs); |
| 2793 | if (!value) goto failed; |
| 2794 | if (PyObject_SetAttrString(result, "starargs", value) == -1) |
| 2795 | goto failed; |
| 2796 | Py_DECREF(value); |
| 2797 | value = ast2obj_expr(o->v.Call.kwargs); |
| 2798 | if (!value) goto failed; |
| 2799 | if (PyObject_SetAttrString(result, "kwargs", value) == -1) |
| 2800 | goto failed; |
| 2801 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2802 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2803 | case Num_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2804 | result = PyType_GenericNew(Num_type, NULL, NULL); |
| 2805 | if (!result) goto failed; |
| 2806 | value = ast2obj_object(o->v.Num.n); |
| 2807 | if (!value) goto failed; |
| 2808 | if (PyObject_SetAttrString(result, "n", value) == -1) |
| 2809 | goto failed; |
| 2810 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2811 | break; |
| 2812 | case Str_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2813 | result = PyType_GenericNew(Str_type, NULL, NULL); |
| 2814 | if (!result) goto failed; |
| 2815 | value = ast2obj_string(o->v.Str.s); |
| 2816 | if (!value) goto failed; |
| 2817 | if (PyObject_SetAttrString(result, "s", value) == -1) |
| 2818 | goto failed; |
| 2819 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2820 | break; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 2821 | case Bytes_kind: |
| 2822 | result = PyType_GenericNew(Bytes_type, NULL, NULL); |
| 2823 | if (!result) goto failed; |
| 2824 | value = ast2obj_string(o->v.Bytes.s); |
| 2825 | if (!value) goto failed; |
| 2826 | if (PyObject_SetAttrString(result, "s", value) == -1) |
| 2827 | goto failed; |
| 2828 | Py_DECREF(value); |
| 2829 | break; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 2830 | case Ellipsis_kind: |
| 2831 | result = PyType_GenericNew(Ellipsis_type, NULL, NULL); |
| 2832 | if (!result) goto failed; |
| 2833 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2834 | case Attribute_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2835 | result = PyType_GenericNew(Attribute_type, NULL, NULL); |
| 2836 | if (!result) goto failed; |
| 2837 | value = ast2obj_expr(o->v.Attribute.value); |
| 2838 | if (!value) goto failed; |
| 2839 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2840 | goto failed; |
| 2841 | Py_DECREF(value); |
| 2842 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 2843 | if (!value) goto failed; |
| 2844 | if (PyObject_SetAttrString(result, "attr", value) == -1) |
| 2845 | goto failed; |
| 2846 | Py_DECREF(value); |
| 2847 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 2848 | if (!value) goto failed; |
| 2849 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2850 | goto failed; |
| 2851 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2852 | break; |
| 2853 | case Subscript_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2854 | result = PyType_GenericNew(Subscript_type, NULL, NULL); |
| 2855 | if (!result) goto failed; |
| 2856 | value = ast2obj_expr(o->v.Subscript.value); |
| 2857 | if (!value) goto failed; |
| 2858 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2859 | goto failed; |
| 2860 | Py_DECREF(value); |
| 2861 | value = ast2obj_slice(o->v.Subscript.slice); |
| 2862 | if (!value) goto failed; |
| 2863 | if (PyObject_SetAttrString(result, "slice", value) == -1) |
| 2864 | goto failed; |
| 2865 | Py_DECREF(value); |
| 2866 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 2867 | if (!value) goto failed; |
| 2868 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2869 | goto failed; |
| 2870 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2871 | break; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2872 | case Starred_kind: |
| 2873 | result = PyType_GenericNew(Starred_type, NULL, NULL); |
| 2874 | if (!result) goto failed; |
| 2875 | value = ast2obj_expr(o->v.Starred.value); |
| 2876 | if (!value) goto failed; |
| 2877 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2878 | goto failed; |
| 2879 | Py_DECREF(value); |
| 2880 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 2881 | if (!value) goto failed; |
| 2882 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2883 | goto failed; |
| 2884 | Py_DECREF(value); |
| 2885 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2886 | case Name_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2887 | result = PyType_GenericNew(Name_type, NULL, NULL); |
| 2888 | if (!result) goto failed; |
| 2889 | value = ast2obj_identifier(o->v.Name.id); |
| 2890 | if (!value) goto failed; |
| 2891 | if (PyObject_SetAttrString(result, "id", value) == -1) |
| 2892 | goto failed; |
| 2893 | Py_DECREF(value); |
| 2894 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 2895 | if (!value) goto failed; |
| 2896 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2897 | goto failed; |
| 2898 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2899 | break; |
| 2900 | case List_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2901 | result = PyType_GenericNew(List_type, NULL, NULL); |
| 2902 | if (!result) goto failed; |
| 2903 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 2904 | if (!value) goto failed; |
| 2905 | if (PyObject_SetAttrString(result, "elts", value) == -1) |
| 2906 | goto failed; |
| 2907 | Py_DECREF(value); |
| 2908 | value = ast2obj_expr_context(o->v.List.ctx); |
| 2909 | if (!value) goto failed; |
| 2910 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2911 | goto failed; |
| 2912 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2913 | break; |
| 2914 | case Tuple_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2915 | result = PyType_GenericNew(Tuple_type, NULL, NULL); |
| 2916 | if (!result) goto failed; |
| 2917 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 2918 | if (!value) goto failed; |
| 2919 | if (PyObject_SetAttrString(result, "elts", value) == -1) |
| 2920 | goto failed; |
| 2921 | Py_DECREF(value); |
| 2922 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 2923 | if (!value) goto failed; |
| 2924 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2925 | goto failed; |
| 2926 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2927 | break; |
| 2928 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2929 | value = ast2obj_int(o->lineno); |
| 2930 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2931 | if (PyObject_SetAttrString(result, "lineno", value) < 0) |
| 2932 | goto failed; |
| 2933 | Py_DECREF(value); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2934 | value = ast2obj_int(o->col_offset); |
| 2935 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2936 | if (PyObject_SetAttrString(result, "col_offset", value) < 0) |
| 2937 | goto failed; |
| 2938 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2939 | return result; |
| 2940 | failed: |
| 2941 | Py_XDECREF(value); |
| 2942 | Py_XDECREF(result); |
| 2943 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2944 | } |
| 2945 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2946 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2947 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2948 | switch(o) { |
| 2949 | case Load: |
| 2950 | Py_INCREF(Load_singleton); |
| 2951 | return Load_singleton; |
| 2952 | case Store: |
| 2953 | Py_INCREF(Store_singleton); |
| 2954 | return Store_singleton; |
| 2955 | case Del: |
| 2956 | Py_INCREF(Del_singleton); |
| 2957 | return Del_singleton; |
| 2958 | case AugLoad: |
| 2959 | Py_INCREF(AugLoad_singleton); |
| 2960 | return AugLoad_singleton; |
| 2961 | case AugStore: |
| 2962 | Py_INCREF(AugStore_singleton); |
| 2963 | return AugStore_singleton; |
| 2964 | case Param: |
| 2965 | Py_INCREF(Param_singleton); |
| 2966 | return Param_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 2967 | default: |
| 2968 | /* should never happen, but just in case ... */ |
| 2969 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 2970 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2971 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2972 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2973 | PyObject* |
| 2974 | ast2obj_slice(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2975 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2976 | slice_ty o = (slice_ty)_o; |
| 2977 | PyObject *result = NULL, *value = NULL; |
| 2978 | if (!o) { |
| 2979 | Py_INCREF(Py_None); |
| 2980 | return Py_None; |
| 2981 | } |
| 2982 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2983 | switch (o->kind) { |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2984 | case Slice_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2985 | result = PyType_GenericNew(Slice_type, NULL, NULL); |
| 2986 | if (!result) goto failed; |
| 2987 | value = ast2obj_expr(o->v.Slice.lower); |
| 2988 | if (!value) goto failed; |
| 2989 | if (PyObject_SetAttrString(result, "lower", value) == -1) |
| 2990 | goto failed; |
| 2991 | Py_DECREF(value); |
| 2992 | value = ast2obj_expr(o->v.Slice.upper); |
| 2993 | if (!value) goto failed; |
| 2994 | if (PyObject_SetAttrString(result, "upper", value) == -1) |
| 2995 | goto failed; |
| 2996 | Py_DECREF(value); |
| 2997 | value = ast2obj_expr(o->v.Slice.step); |
| 2998 | if (!value) goto failed; |
| 2999 | if (PyObject_SetAttrString(result, "step", value) == -1) |
| 3000 | goto failed; |
| 3001 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3002 | break; |
| 3003 | case ExtSlice_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3004 | result = PyType_GenericNew(ExtSlice_type, NULL, NULL); |
| 3005 | if (!result) goto failed; |
| 3006 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 3007 | if (!value) goto failed; |
| 3008 | if (PyObject_SetAttrString(result, "dims", value) == -1) |
| 3009 | goto failed; |
| 3010 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3011 | break; |
| 3012 | case Index_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3013 | result = PyType_GenericNew(Index_type, NULL, NULL); |
| 3014 | if (!result) goto failed; |
| 3015 | value = ast2obj_expr(o->v.Index.value); |
| 3016 | if (!value) goto failed; |
| 3017 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 3018 | goto failed; |
| 3019 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3020 | break; |
| 3021 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3022 | return result; |
| 3023 | failed: |
| 3024 | Py_XDECREF(value); |
| 3025 | Py_XDECREF(result); |
| 3026 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3027 | } |
| 3028 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3029 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3030 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3031 | switch(o) { |
| 3032 | case And: |
| 3033 | Py_INCREF(And_singleton); |
| 3034 | return And_singleton; |
| 3035 | case Or: |
| 3036 | Py_INCREF(Or_singleton); |
| 3037 | return Or_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3038 | default: |
| 3039 | /* should never happen, but just in case ... */ |
| 3040 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 3041 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3042 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3043 | } |
| 3044 | PyObject* ast2obj_operator(operator_ty o) |
| 3045 | { |
| 3046 | switch(o) { |
| 3047 | case Add: |
| 3048 | Py_INCREF(Add_singleton); |
| 3049 | return Add_singleton; |
| 3050 | case Sub: |
| 3051 | Py_INCREF(Sub_singleton); |
| 3052 | return Sub_singleton; |
| 3053 | case Mult: |
| 3054 | Py_INCREF(Mult_singleton); |
| 3055 | return Mult_singleton; |
| 3056 | case Div: |
| 3057 | Py_INCREF(Div_singleton); |
| 3058 | return Div_singleton; |
| 3059 | case Mod: |
| 3060 | Py_INCREF(Mod_singleton); |
| 3061 | return Mod_singleton; |
| 3062 | case Pow: |
| 3063 | Py_INCREF(Pow_singleton); |
| 3064 | return Pow_singleton; |
| 3065 | case LShift: |
| 3066 | Py_INCREF(LShift_singleton); |
| 3067 | return LShift_singleton; |
| 3068 | case RShift: |
| 3069 | Py_INCREF(RShift_singleton); |
| 3070 | return RShift_singleton; |
| 3071 | case BitOr: |
| 3072 | Py_INCREF(BitOr_singleton); |
| 3073 | return BitOr_singleton; |
| 3074 | case BitXor: |
| 3075 | Py_INCREF(BitXor_singleton); |
| 3076 | return BitXor_singleton; |
| 3077 | case BitAnd: |
| 3078 | Py_INCREF(BitAnd_singleton); |
| 3079 | return BitAnd_singleton; |
| 3080 | case FloorDiv: |
| 3081 | Py_INCREF(FloorDiv_singleton); |
| 3082 | return FloorDiv_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3083 | default: |
| 3084 | /* should never happen, but just in case ... */ |
| 3085 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 3086 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3087 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3088 | } |
| 3089 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 3090 | { |
| 3091 | switch(o) { |
| 3092 | case Invert: |
| 3093 | Py_INCREF(Invert_singleton); |
| 3094 | return Invert_singleton; |
| 3095 | case Not: |
| 3096 | Py_INCREF(Not_singleton); |
| 3097 | return Not_singleton; |
| 3098 | case UAdd: |
| 3099 | Py_INCREF(UAdd_singleton); |
| 3100 | return UAdd_singleton; |
| 3101 | case USub: |
| 3102 | Py_INCREF(USub_singleton); |
| 3103 | return USub_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3104 | default: |
| 3105 | /* should never happen, but just in case ... */ |
| 3106 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 3107 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3108 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3109 | } |
| 3110 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 3111 | { |
| 3112 | switch(o) { |
| 3113 | case Eq: |
| 3114 | Py_INCREF(Eq_singleton); |
| 3115 | return Eq_singleton; |
| 3116 | case NotEq: |
| 3117 | Py_INCREF(NotEq_singleton); |
| 3118 | return NotEq_singleton; |
| 3119 | case Lt: |
| 3120 | Py_INCREF(Lt_singleton); |
| 3121 | return Lt_singleton; |
| 3122 | case LtE: |
| 3123 | Py_INCREF(LtE_singleton); |
| 3124 | return LtE_singleton; |
| 3125 | case Gt: |
| 3126 | Py_INCREF(Gt_singleton); |
| 3127 | return Gt_singleton; |
| 3128 | case GtE: |
| 3129 | Py_INCREF(GtE_singleton); |
| 3130 | return GtE_singleton; |
| 3131 | case Is: |
| 3132 | Py_INCREF(Is_singleton); |
| 3133 | return Is_singleton; |
| 3134 | case IsNot: |
| 3135 | Py_INCREF(IsNot_singleton); |
| 3136 | return IsNot_singleton; |
| 3137 | case In: |
| 3138 | Py_INCREF(In_singleton); |
| 3139 | return In_singleton; |
| 3140 | case NotIn: |
| 3141 | Py_INCREF(NotIn_singleton); |
| 3142 | return NotIn_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3143 | default: |
| 3144 | /* should never happen, but just in case ... */ |
| 3145 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 3146 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3147 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3148 | } |
| 3149 | PyObject* |
| 3150 | ast2obj_comprehension(void* _o) |
| 3151 | { |
| 3152 | comprehension_ty o = (comprehension_ty)_o; |
| 3153 | PyObject *result = NULL, *value = NULL; |
| 3154 | if (!o) { |
| 3155 | Py_INCREF(Py_None); |
| 3156 | return Py_None; |
| 3157 | } |
| 3158 | |
| 3159 | result = PyType_GenericNew(comprehension_type, NULL, NULL); |
| 3160 | if (!result) return NULL; |
| 3161 | value = ast2obj_expr(o->target); |
| 3162 | if (!value) goto failed; |
| 3163 | if (PyObject_SetAttrString(result, "target", value) == -1) |
| 3164 | goto failed; |
| 3165 | Py_DECREF(value); |
| 3166 | value = ast2obj_expr(o->iter); |
| 3167 | if (!value) goto failed; |
| 3168 | if (PyObject_SetAttrString(result, "iter", value) == -1) |
| 3169 | goto failed; |
| 3170 | Py_DECREF(value); |
| 3171 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 3172 | if (!value) goto failed; |
| 3173 | if (PyObject_SetAttrString(result, "ifs", value) == -1) |
| 3174 | goto failed; |
| 3175 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3176 | return result; |
| 3177 | failed: |
| 3178 | Py_XDECREF(value); |
| 3179 | Py_XDECREF(result); |
| 3180 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3181 | } |
| 3182 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3183 | PyObject* |
| 3184 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3185 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3186 | excepthandler_ty o = (excepthandler_ty)_o; |
| 3187 | PyObject *result = NULL, *value = NULL; |
| 3188 | if (!o) { |
| 3189 | Py_INCREF(Py_None); |
| 3190 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3191 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3192 | |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3193 | switch (o->kind) { |
| 3194 | case ExceptHandler_kind: |
| 3195 | result = PyType_GenericNew(ExceptHandler_type, NULL, NULL); |
| 3196 | if (!result) goto failed; |
| 3197 | value = ast2obj_expr(o->v.ExceptHandler.type); |
| 3198 | if (!value) goto failed; |
| 3199 | if (PyObject_SetAttrString(result, "type", value) == -1) |
| 3200 | goto failed; |
| 3201 | Py_DECREF(value); |
| 3202 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
| 3203 | if (!value) goto failed; |
| 3204 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 3205 | goto failed; |
| 3206 | Py_DECREF(value); |
| 3207 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 3208 | if (!value) goto failed; |
| 3209 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 3210 | goto failed; |
| 3211 | Py_DECREF(value); |
| 3212 | break; |
| 3213 | } |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3214 | value = ast2obj_int(o->lineno); |
| 3215 | if (!value) goto failed; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3216 | if (PyObject_SetAttrString(result, "lineno", value) < 0) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3217 | goto failed; |
| 3218 | Py_DECREF(value); |
| 3219 | value = ast2obj_int(o->col_offset); |
| 3220 | if (!value) goto failed; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3221 | if (PyObject_SetAttrString(result, "col_offset", value) < 0) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3222 | goto failed; |
| 3223 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3224 | return result; |
| 3225 | failed: |
| 3226 | Py_XDECREF(value); |
| 3227 | Py_XDECREF(result); |
| 3228 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3229 | } |
| 3230 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3231 | PyObject* |
| 3232 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3233 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3234 | arguments_ty o = (arguments_ty)_o; |
| 3235 | PyObject *result = NULL, *value = NULL; |
| 3236 | if (!o) { |
| 3237 | Py_INCREF(Py_None); |
| 3238 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3239 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3240 | |
| 3241 | result = PyType_GenericNew(arguments_type, NULL, NULL); |
| 3242 | if (!result) return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3243 | value = ast2obj_list(o->args, ast2obj_arg); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3244 | if (!value) goto failed; |
| 3245 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 3246 | goto failed; |
| 3247 | Py_DECREF(value); |
| 3248 | value = ast2obj_identifier(o->vararg); |
| 3249 | if (!value) goto failed; |
| 3250 | if (PyObject_SetAttrString(result, "vararg", value) == -1) |
| 3251 | goto failed; |
| 3252 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3253 | value = ast2obj_expr(o->varargannotation); |
| 3254 | if (!value) goto failed; |
| 3255 | if (PyObject_SetAttrString(result, "varargannotation", value) == -1) |
| 3256 | goto failed; |
| 3257 | Py_DECREF(value); |
| 3258 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 3259 | if (!value) goto failed; |
| 3260 | if (PyObject_SetAttrString(result, "kwonlyargs", value) == -1) |
| 3261 | goto failed; |
| 3262 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3263 | value = ast2obj_identifier(o->kwarg); |
| 3264 | if (!value) goto failed; |
| 3265 | if (PyObject_SetAttrString(result, "kwarg", value) == -1) |
| 3266 | goto failed; |
| 3267 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3268 | value = ast2obj_expr(o->kwargannotation); |
| 3269 | if (!value) goto failed; |
| 3270 | if (PyObject_SetAttrString(result, "kwargannotation", value) == -1) |
| 3271 | goto failed; |
| 3272 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3273 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 3274 | if (!value) goto failed; |
| 3275 | if (PyObject_SetAttrString(result, "defaults", value) == -1) |
| 3276 | goto failed; |
| 3277 | Py_DECREF(value); |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 3278 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
| 3279 | if (!value) goto failed; |
| 3280 | if (PyObject_SetAttrString(result, "kw_defaults", value) == -1) |
| 3281 | goto failed; |
| 3282 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3283 | return result; |
| 3284 | failed: |
| 3285 | Py_XDECREF(value); |
| 3286 | Py_XDECREF(result); |
| 3287 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3288 | } |
| 3289 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3290 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3291 | ast2obj_arg(void* _o) |
| 3292 | { |
| 3293 | arg_ty o = (arg_ty)_o; |
| 3294 | PyObject *result = NULL, *value = NULL; |
| 3295 | if (!o) { |
| 3296 | Py_INCREF(Py_None); |
| 3297 | return Py_None; |
| 3298 | } |
| 3299 | |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 3300 | result = PyType_GenericNew(arg_type, NULL, NULL); |
| 3301 | if (!result) return NULL; |
| 3302 | value = ast2obj_identifier(o->arg); |
| 3303 | if (!value) goto failed; |
| 3304 | if (PyObject_SetAttrString(result, "arg", value) == -1) |
| 3305 | goto failed; |
| 3306 | Py_DECREF(value); |
| 3307 | value = ast2obj_expr(o->annotation); |
| 3308 | if (!value) goto failed; |
| 3309 | if (PyObject_SetAttrString(result, "annotation", value) == -1) |
| 3310 | goto failed; |
| 3311 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3312 | return result; |
| 3313 | failed: |
| 3314 | Py_XDECREF(value); |
| 3315 | Py_XDECREF(result); |
| 3316 | return NULL; |
| 3317 | } |
| 3318 | |
| 3319 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3320 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3321 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3322 | keyword_ty o = (keyword_ty)_o; |
| 3323 | PyObject *result = NULL, *value = NULL; |
| 3324 | if (!o) { |
| 3325 | Py_INCREF(Py_None); |
| 3326 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3327 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3328 | |
| 3329 | result = PyType_GenericNew(keyword_type, NULL, NULL); |
| 3330 | if (!result) return NULL; |
| 3331 | value = ast2obj_identifier(o->arg); |
| 3332 | if (!value) goto failed; |
| 3333 | if (PyObject_SetAttrString(result, "arg", value) == -1) |
| 3334 | goto failed; |
| 3335 | Py_DECREF(value); |
| 3336 | value = ast2obj_expr(o->value); |
| 3337 | if (!value) goto failed; |
| 3338 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 3339 | goto failed; |
| 3340 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3341 | return result; |
| 3342 | failed: |
| 3343 | Py_XDECREF(value); |
| 3344 | Py_XDECREF(result); |
| 3345 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3346 | } |
| 3347 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3348 | PyObject* |
| 3349 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3350 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3351 | alias_ty o = (alias_ty)_o; |
| 3352 | PyObject *result = NULL, *value = NULL; |
| 3353 | if (!o) { |
| 3354 | Py_INCREF(Py_None); |
| 3355 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3356 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3357 | |
| 3358 | result = PyType_GenericNew(alias_type, NULL, NULL); |
| 3359 | if (!result) return NULL; |
| 3360 | value = ast2obj_identifier(o->name); |
| 3361 | if (!value) goto failed; |
| 3362 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 3363 | goto failed; |
| 3364 | Py_DECREF(value); |
| 3365 | value = ast2obj_identifier(o->asname); |
| 3366 | if (!value) goto failed; |
| 3367 | if (PyObject_SetAttrString(result, "asname", value) == -1) |
| 3368 | goto failed; |
| 3369 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3370 | return result; |
| 3371 | failed: |
| 3372 | Py_XDECREF(value); |
| 3373 | Py_XDECREF(result); |
| 3374 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3375 | } |
| 3376 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3377 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3378 | int |
| 3379 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 3380 | { |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 3381 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3382 | |
Benjamin Peterson | 787cddc | 2010-11-20 04:37:00 +0000 | [diff] [blame] | 3383 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3384 | |
| 3385 | if (obj == Py_None) { |
| 3386 | *out = NULL; |
| 3387 | return 0; |
| 3388 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 3389 | isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type); |
| 3390 | if (isinstance == -1) { |
| 3391 | return 1; |
| 3392 | } |
| 3393 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3394 | asdl_seq* body; |
| 3395 | |
| 3396 | if (PyObject_HasAttrString(obj, "body")) { |
| 3397 | int res; |
| 3398 | Py_ssize_t len; |
| 3399 | Py_ssize_t i; |
| 3400 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3401 | if (tmp == NULL) goto failed; |
| 3402 | if (!PyList_Check(tmp)) { |
| 3403 | PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3404 | goto failed; |
| 3405 | } |
| 3406 | len = PyList_GET_SIZE(tmp); |
| 3407 | body = asdl_seq_new(len, arena); |
| 3408 | if (body == NULL) goto failed; |
| 3409 | for (i = 0; i < len; i++) { |
| 3410 | stmt_ty value; |
| 3411 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3412 | if (res != 0) goto failed; |
| 3413 | asdl_seq_SET(body, i, value); |
| 3414 | } |
| 3415 | Py_XDECREF(tmp); |
| 3416 | tmp = NULL; |
| 3417 | } else { |
| 3418 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 3419 | return 1; |
| 3420 | } |
| 3421 | *out = Module(body, arena); |
| 3422 | if (*out == NULL) goto failed; |
| 3423 | return 0; |
| 3424 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 3425 | isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type); |
| 3426 | if (isinstance == -1) { |
| 3427 | return 1; |
| 3428 | } |
| 3429 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3430 | asdl_seq* body; |
| 3431 | |
| 3432 | if (PyObject_HasAttrString(obj, "body")) { |
| 3433 | int res; |
| 3434 | Py_ssize_t len; |
| 3435 | Py_ssize_t i; |
| 3436 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3437 | if (tmp == NULL) goto failed; |
| 3438 | if (!PyList_Check(tmp)) { |
| 3439 | PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3440 | goto failed; |
| 3441 | } |
| 3442 | len = PyList_GET_SIZE(tmp); |
| 3443 | body = asdl_seq_new(len, arena); |
| 3444 | if (body == NULL) goto failed; |
| 3445 | for (i = 0; i < len; i++) { |
| 3446 | stmt_ty value; |
| 3447 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3448 | if (res != 0) goto failed; |
| 3449 | asdl_seq_SET(body, i, value); |
| 3450 | } |
| 3451 | Py_XDECREF(tmp); |
| 3452 | tmp = NULL; |
| 3453 | } else { |
| 3454 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 3455 | return 1; |
| 3456 | } |
| 3457 | *out = Interactive(body, arena); |
| 3458 | if (*out == NULL) goto failed; |
| 3459 | return 0; |
| 3460 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 3461 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type); |
| 3462 | if (isinstance == -1) { |
| 3463 | return 1; |
| 3464 | } |
| 3465 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3466 | expr_ty body; |
| 3467 | |
| 3468 | if (PyObject_HasAttrString(obj, "body")) { |
| 3469 | int res; |
| 3470 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3471 | if (tmp == NULL) goto failed; |
| 3472 | res = obj2ast_expr(tmp, &body, arena); |
| 3473 | if (res != 0) goto failed; |
| 3474 | Py_XDECREF(tmp); |
| 3475 | tmp = NULL; |
| 3476 | } else { |
| 3477 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 3478 | return 1; |
| 3479 | } |
| 3480 | *out = Expression(body, arena); |
| 3481 | if (*out == NULL) goto failed; |
| 3482 | return 0; |
| 3483 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 3484 | isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type); |
| 3485 | if (isinstance == -1) { |
| 3486 | return 1; |
| 3487 | } |
| 3488 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3489 | asdl_seq* body; |
| 3490 | |
| 3491 | if (PyObject_HasAttrString(obj, "body")) { |
| 3492 | int res; |
| 3493 | Py_ssize_t len; |
| 3494 | Py_ssize_t i; |
| 3495 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3496 | if (tmp == NULL) goto failed; |
| 3497 | if (!PyList_Check(tmp)) { |
| 3498 | PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3499 | goto failed; |
| 3500 | } |
| 3501 | len = PyList_GET_SIZE(tmp); |
| 3502 | body = asdl_seq_new(len, arena); |
| 3503 | if (body == NULL) goto failed; |
| 3504 | for (i = 0; i < len; i++) { |
| 3505 | stmt_ty value; |
| 3506 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3507 | if (res != 0) goto failed; |
| 3508 | asdl_seq_SET(body, i, value); |
| 3509 | } |
| 3510 | Py_XDECREF(tmp); |
| 3511 | tmp = NULL; |
| 3512 | } else { |
| 3513 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite"); |
| 3514 | return 1; |
| 3515 | } |
| 3516 | *out = Suite(body, arena); |
| 3517 | if (*out == NULL) goto failed; |
| 3518 | return 0; |
| 3519 | } |
| 3520 | |
Benjamin Peterson | aab9585 | 2010-11-20 01:48:38 +0000 | [diff] [blame] | 3521 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
| 3522 | failed: |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3523 | return 1; |
| 3524 | } |
| 3525 | |
| 3526 | int |
| 3527 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 3528 | { |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 3529 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3530 | |
Benjamin Peterson | 787cddc | 2010-11-20 04:37:00 +0000 | [diff] [blame] | 3531 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3532 | int lineno; |
| 3533 | int col_offset; |
| 3534 | |
| 3535 | if (obj == Py_None) { |
| 3536 | *out = NULL; |
| 3537 | return 0; |
| 3538 | } |
| 3539 | if (PyObject_HasAttrString(obj, "lineno")) { |
| 3540 | int res; |
| 3541 | tmp = PyObject_GetAttrString(obj, "lineno"); |
| 3542 | if (tmp == NULL) goto failed; |
| 3543 | res = obj2ast_int(tmp, &lineno, arena); |
| 3544 | if (res != 0) goto failed; |
| 3545 | Py_XDECREF(tmp); |
| 3546 | tmp = NULL; |
| 3547 | } else { |
| 3548 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 3549 | return 1; |
| 3550 | } |
| 3551 | if (PyObject_HasAttrString(obj, "col_offset")) { |
| 3552 | int res; |
| 3553 | tmp = PyObject_GetAttrString(obj, "col_offset"); |
| 3554 | if (tmp == NULL) goto failed; |
| 3555 | res = obj2ast_int(tmp, &col_offset, arena); |
| 3556 | if (res != 0) goto failed; |
| 3557 | Py_XDECREF(tmp); |
| 3558 | tmp = NULL; |
| 3559 | } else { |
| 3560 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 3561 | return 1; |
| 3562 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 3563 | isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type); |
| 3564 | if (isinstance == -1) { |
| 3565 | return 1; |
| 3566 | } |
| 3567 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3568 | identifier name; |
| 3569 | arguments_ty args; |
| 3570 | asdl_seq* body; |
| 3571 | asdl_seq* decorator_list; |
| 3572 | expr_ty returns; |
| 3573 | |
| 3574 | if (PyObject_HasAttrString(obj, "name")) { |
| 3575 | int res; |
| 3576 | tmp = PyObject_GetAttrString(obj, "name"); |
| 3577 | if (tmp == NULL) goto failed; |
| 3578 | res = obj2ast_identifier(tmp, &name, arena); |
| 3579 | if (res != 0) goto failed; |
| 3580 | Py_XDECREF(tmp); |
| 3581 | tmp = NULL; |
| 3582 | } else { |
| 3583 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 3584 | return 1; |
| 3585 | } |
| 3586 | if (PyObject_HasAttrString(obj, "args")) { |
| 3587 | int res; |
| 3588 | tmp = PyObject_GetAttrString(obj, "args"); |
| 3589 | if (tmp == NULL) goto failed; |
| 3590 | res = obj2ast_arguments(tmp, &args, arena); |
| 3591 | if (res != 0) goto failed; |
| 3592 | Py_XDECREF(tmp); |
| 3593 | tmp = NULL; |
| 3594 | } else { |
| 3595 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 3596 | return 1; |
| 3597 | } |
| 3598 | if (PyObject_HasAttrString(obj, "body")) { |
| 3599 | int res; |
| 3600 | Py_ssize_t len; |
| 3601 | Py_ssize_t i; |
| 3602 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3603 | if (tmp == NULL) goto failed; |
| 3604 | if (!PyList_Check(tmp)) { |
| 3605 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3606 | goto failed; |
| 3607 | } |
| 3608 | len = PyList_GET_SIZE(tmp); |
| 3609 | body = asdl_seq_new(len, arena); |
| 3610 | if (body == NULL) goto failed; |
| 3611 | for (i = 0; i < len; i++) { |
| 3612 | stmt_ty value; |
| 3613 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3614 | if (res != 0) goto failed; |
| 3615 | asdl_seq_SET(body, i, value); |
| 3616 | } |
| 3617 | Py_XDECREF(tmp); |
| 3618 | tmp = NULL; |
| 3619 | } else { |
| 3620 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 3621 | return 1; |
| 3622 | } |
| 3623 | if (PyObject_HasAttrString(obj, "decorator_list")) { |
| 3624 | int res; |
| 3625 | Py_ssize_t len; |
| 3626 | Py_ssize_t i; |
| 3627 | tmp = PyObject_GetAttrString(obj, "decorator_list"); |
| 3628 | if (tmp == NULL) goto failed; |
| 3629 | if (!PyList_Check(tmp)) { |
| 3630 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3631 | goto failed; |
| 3632 | } |
| 3633 | len = PyList_GET_SIZE(tmp); |
| 3634 | decorator_list = asdl_seq_new(len, arena); |
| 3635 | if (decorator_list == NULL) goto failed; |
| 3636 | for (i = 0; i < len; i++) { |
| 3637 | expr_ty value; |
| 3638 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3639 | if (res != 0) goto failed; |
| 3640 | asdl_seq_SET(decorator_list, i, value); |
| 3641 | } |
| 3642 | Py_XDECREF(tmp); |
| 3643 | tmp = NULL; |
| 3644 | } else { |
| 3645 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 3646 | return 1; |
| 3647 | } |
| 3648 | if (PyObject_HasAttrString(obj, "returns")) { |
| 3649 | int res; |
| 3650 | tmp = PyObject_GetAttrString(obj, "returns"); |
| 3651 | if (tmp == NULL) goto failed; |
| 3652 | res = obj2ast_expr(tmp, &returns, arena); |
| 3653 | if (res != 0) goto failed; |
| 3654 | Py_XDECREF(tmp); |
| 3655 | tmp = NULL; |
| 3656 | } else { |
| 3657 | returns = NULL; |
| 3658 | } |
| 3659 | *out = FunctionDef(name, args, body, decorator_list, returns, |
| 3660 | lineno, col_offset, arena); |
| 3661 | if (*out == NULL) goto failed; |
| 3662 | return 0; |
| 3663 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 3664 | isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type); |
| 3665 | if (isinstance == -1) { |
| 3666 | return 1; |
| 3667 | } |
| 3668 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3669 | identifier name; |
| 3670 | asdl_seq* bases; |
| 3671 | asdl_seq* keywords; |
| 3672 | expr_ty starargs; |
| 3673 | expr_ty kwargs; |
| 3674 | asdl_seq* body; |
| 3675 | asdl_seq* decorator_list; |
| 3676 | |
| 3677 | if (PyObject_HasAttrString(obj, "name")) { |
| 3678 | int res; |
| 3679 | tmp = PyObject_GetAttrString(obj, "name"); |
| 3680 | if (tmp == NULL) goto failed; |
| 3681 | res = obj2ast_identifier(tmp, &name, arena); |
| 3682 | if (res != 0) goto failed; |
| 3683 | Py_XDECREF(tmp); |
| 3684 | tmp = NULL; |
| 3685 | } else { |
| 3686 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 3687 | return 1; |
| 3688 | } |
| 3689 | if (PyObject_HasAttrString(obj, "bases")) { |
| 3690 | int res; |
| 3691 | Py_ssize_t len; |
| 3692 | Py_ssize_t i; |
| 3693 | tmp = PyObject_GetAttrString(obj, "bases"); |
| 3694 | if (tmp == NULL) goto failed; |
| 3695 | if (!PyList_Check(tmp)) { |
| 3696 | PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3697 | goto failed; |
| 3698 | } |
| 3699 | len = PyList_GET_SIZE(tmp); |
| 3700 | bases = asdl_seq_new(len, arena); |
| 3701 | if (bases == NULL) goto failed; |
| 3702 | for (i = 0; i < len; i++) { |
| 3703 | expr_ty value; |
| 3704 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3705 | if (res != 0) goto failed; |
| 3706 | asdl_seq_SET(bases, i, value); |
| 3707 | } |
| 3708 | Py_XDECREF(tmp); |
| 3709 | tmp = NULL; |
| 3710 | } else { |
| 3711 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 3712 | return 1; |
| 3713 | } |
| 3714 | if (PyObject_HasAttrString(obj, "keywords")) { |
| 3715 | int res; |
| 3716 | Py_ssize_t len; |
| 3717 | Py_ssize_t i; |
| 3718 | tmp = PyObject_GetAttrString(obj, "keywords"); |
| 3719 | if (tmp == NULL) goto failed; |
| 3720 | if (!PyList_Check(tmp)) { |
| 3721 | PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3722 | goto failed; |
| 3723 | } |
| 3724 | len = PyList_GET_SIZE(tmp); |
| 3725 | keywords = asdl_seq_new(len, arena); |
| 3726 | if (keywords == NULL) goto failed; |
| 3727 | for (i = 0; i < len; i++) { |
| 3728 | keyword_ty value; |
| 3729 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3730 | if (res != 0) goto failed; |
| 3731 | asdl_seq_SET(keywords, i, value); |
| 3732 | } |
| 3733 | Py_XDECREF(tmp); |
| 3734 | tmp = NULL; |
| 3735 | } else { |
| 3736 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 3737 | return 1; |
| 3738 | } |
| 3739 | if (PyObject_HasAttrString(obj, "starargs")) { |
| 3740 | int res; |
| 3741 | tmp = PyObject_GetAttrString(obj, "starargs"); |
| 3742 | if (tmp == NULL) goto failed; |
| 3743 | res = obj2ast_expr(tmp, &starargs, arena); |
| 3744 | if (res != 0) goto failed; |
| 3745 | Py_XDECREF(tmp); |
| 3746 | tmp = NULL; |
| 3747 | } else { |
| 3748 | starargs = NULL; |
| 3749 | } |
| 3750 | if (PyObject_HasAttrString(obj, "kwargs")) { |
| 3751 | int res; |
| 3752 | tmp = PyObject_GetAttrString(obj, "kwargs"); |
| 3753 | if (tmp == NULL) goto failed; |
| 3754 | res = obj2ast_expr(tmp, &kwargs, arena); |
| 3755 | if (res != 0) goto failed; |
| 3756 | Py_XDECREF(tmp); |
| 3757 | tmp = NULL; |
| 3758 | } else { |
| 3759 | kwargs = NULL; |
| 3760 | } |
| 3761 | if (PyObject_HasAttrString(obj, "body")) { |
| 3762 | int res; |
| 3763 | Py_ssize_t len; |
| 3764 | Py_ssize_t i; |
| 3765 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3766 | if (tmp == NULL) goto failed; |
| 3767 | if (!PyList_Check(tmp)) { |
| 3768 | PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3769 | goto failed; |
| 3770 | } |
| 3771 | len = PyList_GET_SIZE(tmp); |
| 3772 | body = asdl_seq_new(len, arena); |
| 3773 | if (body == NULL) goto failed; |
| 3774 | for (i = 0; i < len; i++) { |
| 3775 | stmt_ty value; |
| 3776 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3777 | if (res != 0) goto failed; |
| 3778 | asdl_seq_SET(body, i, value); |
| 3779 | } |
| 3780 | Py_XDECREF(tmp); |
| 3781 | tmp = NULL; |
| 3782 | } else { |
| 3783 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 3784 | return 1; |
| 3785 | } |
| 3786 | if (PyObject_HasAttrString(obj, "decorator_list")) { |
| 3787 | int res; |
| 3788 | Py_ssize_t len; |
| 3789 | Py_ssize_t i; |
| 3790 | tmp = PyObject_GetAttrString(obj, "decorator_list"); |
| 3791 | if (tmp == NULL) goto failed; |
| 3792 | if (!PyList_Check(tmp)) { |
| 3793 | PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3794 | goto failed; |
| 3795 | } |
| 3796 | len = PyList_GET_SIZE(tmp); |
| 3797 | decorator_list = asdl_seq_new(len, arena); |
| 3798 | if (decorator_list == NULL) goto failed; |
| 3799 | for (i = 0; i < len; i++) { |
| 3800 | expr_ty value; |
| 3801 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3802 | if (res != 0) goto failed; |
| 3803 | asdl_seq_SET(decorator_list, i, value); |
| 3804 | } |
| 3805 | Py_XDECREF(tmp); |
| 3806 | tmp = NULL; |
| 3807 | } else { |
| 3808 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 3809 | return 1; |
| 3810 | } |
| 3811 | *out = ClassDef(name, bases, keywords, starargs, kwargs, body, |
| 3812 | decorator_list, lineno, col_offset, arena); |
| 3813 | if (*out == NULL) goto failed; |
| 3814 | return 0; |
| 3815 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 3816 | isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type); |
| 3817 | if (isinstance == -1) { |
| 3818 | return 1; |
| 3819 | } |
| 3820 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3821 | expr_ty value; |
| 3822 | |
| 3823 | if (PyObject_HasAttrString(obj, "value")) { |
| 3824 | int res; |
| 3825 | tmp = PyObject_GetAttrString(obj, "value"); |
| 3826 | if (tmp == NULL) goto failed; |
| 3827 | res = obj2ast_expr(tmp, &value, arena); |
| 3828 | if (res != 0) goto failed; |
| 3829 | Py_XDECREF(tmp); |
| 3830 | tmp = NULL; |
| 3831 | } else { |
| 3832 | value = NULL; |
| 3833 | } |
| 3834 | *out = Return(value, lineno, col_offset, arena); |
| 3835 | if (*out == NULL) goto failed; |
| 3836 | return 0; |
| 3837 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 3838 | isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type); |
| 3839 | if (isinstance == -1) { |
| 3840 | return 1; |
| 3841 | } |
| 3842 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3843 | asdl_seq* targets; |
| 3844 | |
| 3845 | if (PyObject_HasAttrString(obj, "targets")) { |
| 3846 | int res; |
| 3847 | Py_ssize_t len; |
| 3848 | Py_ssize_t i; |
| 3849 | tmp = PyObject_GetAttrString(obj, "targets"); |
| 3850 | if (tmp == NULL) goto failed; |
| 3851 | if (!PyList_Check(tmp)) { |
| 3852 | PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3853 | goto failed; |
| 3854 | } |
| 3855 | len = PyList_GET_SIZE(tmp); |
| 3856 | targets = asdl_seq_new(len, arena); |
| 3857 | if (targets == NULL) goto failed; |
| 3858 | for (i = 0; i < len; i++) { |
| 3859 | expr_ty value; |
| 3860 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3861 | if (res != 0) goto failed; |
| 3862 | asdl_seq_SET(targets, i, value); |
| 3863 | } |
| 3864 | Py_XDECREF(tmp); |
| 3865 | tmp = NULL; |
| 3866 | } else { |
| 3867 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 3868 | return 1; |
| 3869 | } |
| 3870 | *out = Delete(targets, lineno, col_offset, arena); |
| 3871 | if (*out == NULL) goto failed; |
| 3872 | return 0; |
| 3873 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 3874 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type); |
| 3875 | if (isinstance == -1) { |
| 3876 | return 1; |
| 3877 | } |
| 3878 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3879 | asdl_seq* targets; |
| 3880 | expr_ty value; |
| 3881 | |
| 3882 | if (PyObject_HasAttrString(obj, "targets")) { |
| 3883 | int res; |
| 3884 | Py_ssize_t len; |
| 3885 | Py_ssize_t i; |
| 3886 | tmp = PyObject_GetAttrString(obj, "targets"); |
| 3887 | if (tmp == NULL) goto failed; |
| 3888 | if (!PyList_Check(tmp)) { |
| 3889 | PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3890 | goto failed; |
| 3891 | } |
| 3892 | len = PyList_GET_SIZE(tmp); |
| 3893 | targets = asdl_seq_new(len, arena); |
| 3894 | if (targets == NULL) goto failed; |
| 3895 | for (i = 0; i < len; i++) { |
| 3896 | expr_ty value; |
| 3897 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3898 | if (res != 0) goto failed; |
| 3899 | asdl_seq_SET(targets, i, value); |
| 3900 | } |
| 3901 | Py_XDECREF(tmp); |
| 3902 | tmp = NULL; |
| 3903 | } else { |
| 3904 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 3905 | return 1; |
| 3906 | } |
| 3907 | if (PyObject_HasAttrString(obj, "value")) { |
| 3908 | int res; |
| 3909 | tmp = PyObject_GetAttrString(obj, "value"); |
| 3910 | if (tmp == NULL) goto failed; |
| 3911 | res = obj2ast_expr(tmp, &value, arena); |
| 3912 | if (res != 0) goto failed; |
| 3913 | Py_XDECREF(tmp); |
| 3914 | tmp = NULL; |
| 3915 | } else { |
| 3916 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 3917 | return 1; |
| 3918 | } |
| 3919 | *out = Assign(targets, value, lineno, col_offset, arena); |
| 3920 | if (*out == NULL) goto failed; |
| 3921 | return 0; |
| 3922 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 3923 | isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type); |
| 3924 | if (isinstance == -1) { |
| 3925 | return 1; |
| 3926 | } |
| 3927 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3928 | expr_ty target; |
| 3929 | operator_ty op; |
| 3930 | expr_ty value; |
| 3931 | |
| 3932 | if (PyObject_HasAttrString(obj, "target")) { |
| 3933 | int res; |
| 3934 | tmp = PyObject_GetAttrString(obj, "target"); |
| 3935 | if (tmp == NULL) goto failed; |
| 3936 | res = obj2ast_expr(tmp, &target, arena); |
| 3937 | if (res != 0) goto failed; |
| 3938 | Py_XDECREF(tmp); |
| 3939 | tmp = NULL; |
| 3940 | } else { |
| 3941 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 3942 | return 1; |
| 3943 | } |
| 3944 | if (PyObject_HasAttrString(obj, "op")) { |
| 3945 | int res; |
| 3946 | tmp = PyObject_GetAttrString(obj, "op"); |
| 3947 | if (tmp == NULL) goto failed; |
| 3948 | res = obj2ast_operator(tmp, &op, arena); |
| 3949 | if (res != 0) goto failed; |
| 3950 | Py_XDECREF(tmp); |
| 3951 | tmp = NULL; |
| 3952 | } else { |
| 3953 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 3954 | return 1; |
| 3955 | } |
| 3956 | if (PyObject_HasAttrString(obj, "value")) { |
| 3957 | int res; |
| 3958 | tmp = PyObject_GetAttrString(obj, "value"); |
| 3959 | if (tmp == NULL) goto failed; |
| 3960 | res = obj2ast_expr(tmp, &value, arena); |
| 3961 | if (res != 0) goto failed; |
| 3962 | Py_XDECREF(tmp); |
| 3963 | tmp = NULL; |
| 3964 | } else { |
| 3965 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 3966 | return 1; |
| 3967 | } |
| 3968 | *out = AugAssign(target, op, value, lineno, col_offset, arena); |
| 3969 | if (*out == NULL) goto failed; |
| 3970 | return 0; |
| 3971 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 3972 | isinstance = PyObject_IsInstance(obj, (PyObject*)For_type); |
| 3973 | if (isinstance == -1) { |
| 3974 | return 1; |
| 3975 | } |
| 3976 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3977 | expr_ty target; |
| 3978 | expr_ty iter; |
| 3979 | asdl_seq* body; |
| 3980 | asdl_seq* orelse; |
| 3981 | |
| 3982 | if (PyObject_HasAttrString(obj, "target")) { |
| 3983 | int res; |
| 3984 | tmp = PyObject_GetAttrString(obj, "target"); |
| 3985 | if (tmp == NULL) goto failed; |
| 3986 | res = obj2ast_expr(tmp, &target, arena); |
| 3987 | if (res != 0) goto failed; |
| 3988 | Py_XDECREF(tmp); |
| 3989 | tmp = NULL; |
| 3990 | } else { |
| 3991 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 3992 | return 1; |
| 3993 | } |
| 3994 | if (PyObject_HasAttrString(obj, "iter")) { |
| 3995 | int res; |
| 3996 | tmp = PyObject_GetAttrString(obj, "iter"); |
| 3997 | if (tmp == NULL) goto failed; |
| 3998 | res = obj2ast_expr(tmp, &iter, arena); |
| 3999 | if (res != 0) goto failed; |
| 4000 | Py_XDECREF(tmp); |
| 4001 | tmp = NULL; |
| 4002 | } else { |
| 4003 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 4004 | return 1; |
| 4005 | } |
| 4006 | if (PyObject_HasAttrString(obj, "body")) { |
| 4007 | int res; |
| 4008 | Py_ssize_t len; |
| 4009 | Py_ssize_t i; |
| 4010 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4011 | if (tmp == NULL) goto failed; |
| 4012 | if (!PyList_Check(tmp)) { |
| 4013 | PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4014 | goto failed; |
| 4015 | } |
| 4016 | len = PyList_GET_SIZE(tmp); |
| 4017 | body = asdl_seq_new(len, arena); |
| 4018 | if (body == NULL) goto failed; |
| 4019 | for (i = 0; i < len; i++) { |
| 4020 | stmt_ty value; |
| 4021 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4022 | if (res != 0) goto failed; |
| 4023 | asdl_seq_SET(body, i, value); |
| 4024 | } |
| 4025 | Py_XDECREF(tmp); |
| 4026 | tmp = NULL; |
| 4027 | } else { |
| 4028 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 4029 | return 1; |
| 4030 | } |
| 4031 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4032 | int res; |
| 4033 | Py_ssize_t len; |
| 4034 | Py_ssize_t i; |
| 4035 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4036 | if (tmp == NULL) goto failed; |
| 4037 | if (!PyList_Check(tmp)) { |
| 4038 | PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4039 | goto failed; |
| 4040 | } |
| 4041 | len = PyList_GET_SIZE(tmp); |
| 4042 | orelse = asdl_seq_new(len, arena); |
| 4043 | if (orelse == NULL) goto failed; |
| 4044 | for (i = 0; i < len; i++) { |
| 4045 | stmt_ty value; |
| 4046 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4047 | if (res != 0) goto failed; |
| 4048 | asdl_seq_SET(orelse, i, value); |
| 4049 | } |
| 4050 | Py_XDECREF(tmp); |
| 4051 | tmp = NULL; |
| 4052 | } else { |
| 4053 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 4054 | return 1; |
| 4055 | } |
| 4056 | *out = For(target, iter, body, orelse, lineno, col_offset, |
| 4057 | arena); |
| 4058 | if (*out == NULL) goto failed; |
| 4059 | return 0; |
| 4060 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 4061 | isinstance = PyObject_IsInstance(obj, (PyObject*)While_type); |
| 4062 | if (isinstance == -1) { |
| 4063 | return 1; |
| 4064 | } |
| 4065 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4066 | expr_ty test; |
| 4067 | asdl_seq* body; |
| 4068 | asdl_seq* orelse; |
| 4069 | |
| 4070 | if (PyObject_HasAttrString(obj, "test")) { |
| 4071 | int res; |
| 4072 | tmp = PyObject_GetAttrString(obj, "test"); |
| 4073 | if (tmp == NULL) goto failed; |
| 4074 | res = obj2ast_expr(tmp, &test, arena); |
| 4075 | if (res != 0) goto failed; |
| 4076 | Py_XDECREF(tmp); |
| 4077 | tmp = NULL; |
| 4078 | } else { |
| 4079 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 4080 | return 1; |
| 4081 | } |
| 4082 | if (PyObject_HasAttrString(obj, "body")) { |
| 4083 | int res; |
| 4084 | Py_ssize_t len; |
| 4085 | Py_ssize_t i; |
| 4086 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4087 | if (tmp == NULL) goto failed; |
| 4088 | if (!PyList_Check(tmp)) { |
| 4089 | PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4090 | goto failed; |
| 4091 | } |
| 4092 | len = PyList_GET_SIZE(tmp); |
| 4093 | body = asdl_seq_new(len, arena); |
| 4094 | if (body == NULL) goto failed; |
| 4095 | for (i = 0; i < len; i++) { |
| 4096 | stmt_ty value; |
| 4097 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4098 | if (res != 0) goto failed; |
| 4099 | asdl_seq_SET(body, i, value); |
| 4100 | } |
| 4101 | Py_XDECREF(tmp); |
| 4102 | tmp = NULL; |
| 4103 | } else { |
| 4104 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 4105 | return 1; |
| 4106 | } |
| 4107 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4108 | int res; |
| 4109 | Py_ssize_t len; |
| 4110 | Py_ssize_t i; |
| 4111 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4112 | if (tmp == NULL) goto failed; |
| 4113 | if (!PyList_Check(tmp)) { |
| 4114 | PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4115 | goto failed; |
| 4116 | } |
| 4117 | len = PyList_GET_SIZE(tmp); |
| 4118 | orelse = asdl_seq_new(len, arena); |
| 4119 | if (orelse == NULL) goto failed; |
| 4120 | for (i = 0; i < len; i++) { |
| 4121 | stmt_ty value; |
| 4122 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4123 | if (res != 0) goto failed; |
| 4124 | asdl_seq_SET(orelse, i, value); |
| 4125 | } |
| 4126 | Py_XDECREF(tmp); |
| 4127 | tmp = NULL; |
| 4128 | } else { |
| 4129 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 4130 | return 1; |
| 4131 | } |
| 4132 | *out = While(test, body, orelse, lineno, col_offset, arena); |
| 4133 | if (*out == NULL) goto failed; |
| 4134 | return 0; |
| 4135 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 4136 | isinstance = PyObject_IsInstance(obj, (PyObject*)If_type); |
| 4137 | if (isinstance == -1) { |
| 4138 | return 1; |
| 4139 | } |
| 4140 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4141 | expr_ty test; |
| 4142 | asdl_seq* body; |
| 4143 | asdl_seq* orelse; |
| 4144 | |
| 4145 | if (PyObject_HasAttrString(obj, "test")) { |
| 4146 | int res; |
| 4147 | tmp = PyObject_GetAttrString(obj, "test"); |
| 4148 | if (tmp == NULL) goto failed; |
| 4149 | res = obj2ast_expr(tmp, &test, arena); |
| 4150 | if (res != 0) goto failed; |
| 4151 | Py_XDECREF(tmp); |
| 4152 | tmp = NULL; |
| 4153 | } else { |
| 4154 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 4155 | return 1; |
| 4156 | } |
| 4157 | if (PyObject_HasAttrString(obj, "body")) { |
| 4158 | int res; |
| 4159 | Py_ssize_t len; |
| 4160 | Py_ssize_t i; |
| 4161 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4162 | if (tmp == NULL) goto failed; |
| 4163 | if (!PyList_Check(tmp)) { |
| 4164 | PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4165 | goto failed; |
| 4166 | } |
| 4167 | len = PyList_GET_SIZE(tmp); |
| 4168 | body = asdl_seq_new(len, arena); |
| 4169 | if (body == NULL) goto failed; |
| 4170 | for (i = 0; i < len; i++) { |
| 4171 | stmt_ty value; |
| 4172 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4173 | if (res != 0) goto failed; |
| 4174 | asdl_seq_SET(body, i, value); |
| 4175 | } |
| 4176 | Py_XDECREF(tmp); |
| 4177 | tmp = NULL; |
| 4178 | } else { |
| 4179 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 4180 | return 1; |
| 4181 | } |
| 4182 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4183 | int res; |
| 4184 | Py_ssize_t len; |
| 4185 | Py_ssize_t i; |
| 4186 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4187 | if (tmp == NULL) goto failed; |
| 4188 | if (!PyList_Check(tmp)) { |
| 4189 | PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4190 | goto failed; |
| 4191 | } |
| 4192 | len = PyList_GET_SIZE(tmp); |
| 4193 | orelse = asdl_seq_new(len, arena); |
| 4194 | if (orelse == NULL) goto failed; |
| 4195 | for (i = 0; i < len; i++) { |
| 4196 | stmt_ty value; |
| 4197 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4198 | if (res != 0) goto failed; |
| 4199 | asdl_seq_SET(orelse, i, value); |
| 4200 | } |
| 4201 | Py_XDECREF(tmp); |
| 4202 | tmp = NULL; |
| 4203 | } else { |
| 4204 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 4205 | return 1; |
| 4206 | } |
| 4207 | *out = If(test, body, orelse, lineno, col_offset, arena); |
| 4208 | if (*out == NULL) goto failed; |
| 4209 | return 0; |
| 4210 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 4211 | isinstance = PyObject_IsInstance(obj, (PyObject*)With_type); |
| 4212 | if (isinstance == -1) { |
| 4213 | return 1; |
| 4214 | } |
| 4215 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4216 | expr_ty context_expr; |
| 4217 | expr_ty optional_vars; |
| 4218 | asdl_seq* body; |
| 4219 | |
| 4220 | if (PyObject_HasAttrString(obj, "context_expr")) { |
| 4221 | int res; |
| 4222 | tmp = PyObject_GetAttrString(obj, "context_expr"); |
| 4223 | if (tmp == NULL) goto failed; |
| 4224 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 4225 | if (res != 0) goto failed; |
| 4226 | Py_XDECREF(tmp); |
| 4227 | tmp = NULL; |
| 4228 | } else { |
| 4229 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from With"); |
| 4230 | return 1; |
| 4231 | } |
| 4232 | if (PyObject_HasAttrString(obj, "optional_vars")) { |
| 4233 | int res; |
| 4234 | tmp = PyObject_GetAttrString(obj, "optional_vars"); |
| 4235 | if (tmp == NULL) goto failed; |
| 4236 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 4237 | if (res != 0) goto failed; |
| 4238 | Py_XDECREF(tmp); |
| 4239 | tmp = NULL; |
| 4240 | } else { |
| 4241 | optional_vars = NULL; |
| 4242 | } |
| 4243 | if (PyObject_HasAttrString(obj, "body")) { |
| 4244 | int res; |
| 4245 | Py_ssize_t len; |
| 4246 | Py_ssize_t i; |
| 4247 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4248 | if (tmp == NULL) goto failed; |
| 4249 | if (!PyList_Check(tmp)) { |
| 4250 | PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4251 | goto failed; |
| 4252 | } |
| 4253 | len = PyList_GET_SIZE(tmp); |
| 4254 | body = asdl_seq_new(len, arena); |
| 4255 | if (body == NULL) goto failed; |
| 4256 | for (i = 0; i < len; i++) { |
| 4257 | stmt_ty value; |
| 4258 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4259 | if (res != 0) goto failed; |
| 4260 | asdl_seq_SET(body, i, value); |
| 4261 | } |
| 4262 | Py_XDECREF(tmp); |
| 4263 | tmp = NULL; |
| 4264 | } else { |
| 4265 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 4266 | return 1; |
| 4267 | } |
| 4268 | *out = With(context_expr, optional_vars, body, lineno, |
| 4269 | col_offset, arena); |
| 4270 | if (*out == NULL) goto failed; |
| 4271 | return 0; |
| 4272 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 4273 | isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type); |
| 4274 | if (isinstance == -1) { |
| 4275 | return 1; |
| 4276 | } |
| 4277 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4278 | expr_ty exc; |
| 4279 | expr_ty cause; |
| 4280 | |
| 4281 | if (PyObject_HasAttrString(obj, "exc")) { |
| 4282 | int res; |
| 4283 | tmp = PyObject_GetAttrString(obj, "exc"); |
| 4284 | if (tmp == NULL) goto failed; |
| 4285 | res = obj2ast_expr(tmp, &exc, arena); |
| 4286 | if (res != 0) goto failed; |
| 4287 | Py_XDECREF(tmp); |
| 4288 | tmp = NULL; |
| 4289 | } else { |
| 4290 | exc = NULL; |
| 4291 | } |
| 4292 | if (PyObject_HasAttrString(obj, "cause")) { |
| 4293 | int res; |
| 4294 | tmp = PyObject_GetAttrString(obj, "cause"); |
| 4295 | if (tmp == NULL) goto failed; |
| 4296 | res = obj2ast_expr(tmp, &cause, arena); |
| 4297 | if (res != 0) goto failed; |
| 4298 | Py_XDECREF(tmp); |
| 4299 | tmp = NULL; |
| 4300 | } else { |
| 4301 | cause = NULL; |
| 4302 | } |
| 4303 | *out = Raise(exc, cause, lineno, col_offset, arena); |
| 4304 | if (*out == NULL) goto failed; |
| 4305 | return 0; |
| 4306 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 4307 | isinstance = PyObject_IsInstance(obj, (PyObject*)TryExcept_type); |
| 4308 | if (isinstance == -1) { |
| 4309 | return 1; |
| 4310 | } |
| 4311 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4312 | asdl_seq* body; |
| 4313 | asdl_seq* handlers; |
| 4314 | asdl_seq* orelse; |
| 4315 | |
| 4316 | if (PyObject_HasAttrString(obj, "body")) { |
| 4317 | int res; |
| 4318 | Py_ssize_t len; |
| 4319 | Py_ssize_t i; |
| 4320 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4321 | if (tmp == NULL) goto failed; |
| 4322 | if (!PyList_Check(tmp)) { |
| 4323 | PyErr_Format(PyExc_TypeError, "TryExcept field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4324 | goto failed; |
| 4325 | } |
| 4326 | len = PyList_GET_SIZE(tmp); |
| 4327 | body = asdl_seq_new(len, arena); |
| 4328 | if (body == NULL) goto failed; |
| 4329 | for (i = 0; i < len; i++) { |
| 4330 | stmt_ty value; |
| 4331 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4332 | if (res != 0) goto failed; |
| 4333 | asdl_seq_SET(body, i, value); |
| 4334 | } |
| 4335 | Py_XDECREF(tmp); |
| 4336 | tmp = NULL; |
| 4337 | } else { |
| 4338 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryExcept"); |
| 4339 | return 1; |
| 4340 | } |
| 4341 | if (PyObject_HasAttrString(obj, "handlers")) { |
| 4342 | int res; |
| 4343 | Py_ssize_t len; |
| 4344 | Py_ssize_t i; |
| 4345 | tmp = PyObject_GetAttrString(obj, "handlers"); |
| 4346 | if (tmp == NULL) goto failed; |
| 4347 | if (!PyList_Check(tmp)) { |
| 4348 | PyErr_Format(PyExc_TypeError, "TryExcept field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4349 | goto failed; |
| 4350 | } |
| 4351 | len = PyList_GET_SIZE(tmp); |
| 4352 | handlers = asdl_seq_new(len, arena); |
| 4353 | if (handlers == NULL) goto failed; |
| 4354 | for (i = 0; i < len; i++) { |
| 4355 | excepthandler_ty value; |
| 4356 | res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4357 | if (res != 0) goto failed; |
| 4358 | asdl_seq_SET(handlers, i, value); |
| 4359 | } |
| 4360 | Py_XDECREF(tmp); |
| 4361 | tmp = NULL; |
| 4362 | } else { |
| 4363 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from TryExcept"); |
| 4364 | return 1; |
| 4365 | } |
| 4366 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4367 | int res; |
| 4368 | Py_ssize_t len; |
| 4369 | Py_ssize_t i; |
| 4370 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4371 | if (tmp == NULL) goto failed; |
| 4372 | if (!PyList_Check(tmp)) { |
| 4373 | PyErr_Format(PyExc_TypeError, "TryExcept field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4374 | goto failed; |
| 4375 | } |
| 4376 | len = PyList_GET_SIZE(tmp); |
| 4377 | orelse = asdl_seq_new(len, arena); |
| 4378 | if (orelse == NULL) goto failed; |
| 4379 | for (i = 0; i < len; i++) { |
| 4380 | stmt_ty value; |
| 4381 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4382 | if (res != 0) goto failed; |
| 4383 | asdl_seq_SET(orelse, i, value); |
| 4384 | } |
| 4385 | Py_XDECREF(tmp); |
| 4386 | tmp = NULL; |
| 4387 | } else { |
| 4388 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from TryExcept"); |
| 4389 | return 1; |
| 4390 | } |
| 4391 | *out = TryExcept(body, handlers, orelse, lineno, col_offset, |
| 4392 | arena); |
| 4393 | if (*out == NULL) goto failed; |
| 4394 | return 0; |
| 4395 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 4396 | isinstance = PyObject_IsInstance(obj, (PyObject*)TryFinally_type); |
| 4397 | if (isinstance == -1) { |
| 4398 | return 1; |
| 4399 | } |
| 4400 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4401 | asdl_seq* body; |
| 4402 | asdl_seq* finalbody; |
| 4403 | |
| 4404 | if (PyObject_HasAttrString(obj, "body")) { |
| 4405 | int res; |
| 4406 | Py_ssize_t len; |
| 4407 | Py_ssize_t i; |
| 4408 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4409 | if (tmp == NULL) goto failed; |
| 4410 | if (!PyList_Check(tmp)) { |
| 4411 | PyErr_Format(PyExc_TypeError, "TryFinally field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4412 | goto failed; |
| 4413 | } |
| 4414 | len = PyList_GET_SIZE(tmp); |
| 4415 | body = asdl_seq_new(len, arena); |
| 4416 | if (body == NULL) goto failed; |
| 4417 | for (i = 0; i < len; i++) { |
| 4418 | stmt_ty value; |
| 4419 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4420 | if (res != 0) goto failed; |
| 4421 | asdl_seq_SET(body, i, value); |
| 4422 | } |
| 4423 | Py_XDECREF(tmp); |
| 4424 | tmp = NULL; |
| 4425 | } else { |
| 4426 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryFinally"); |
| 4427 | return 1; |
| 4428 | } |
| 4429 | if (PyObject_HasAttrString(obj, "finalbody")) { |
| 4430 | int res; |
| 4431 | Py_ssize_t len; |
| 4432 | Py_ssize_t i; |
| 4433 | tmp = PyObject_GetAttrString(obj, "finalbody"); |
| 4434 | if (tmp == NULL) goto failed; |
| 4435 | if (!PyList_Check(tmp)) { |
| 4436 | PyErr_Format(PyExc_TypeError, "TryFinally field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4437 | goto failed; |
| 4438 | } |
| 4439 | len = PyList_GET_SIZE(tmp); |
| 4440 | finalbody = asdl_seq_new(len, arena); |
| 4441 | if (finalbody == NULL) goto failed; |
| 4442 | for (i = 0; i < len; i++) { |
| 4443 | stmt_ty value; |
| 4444 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4445 | if (res != 0) goto failed; |
| 4446 | asdl_seq_SET(finalbody, i, value); |
| 4447 | } |
| 4448 | Py_XDECREF(tmp); |
| 4449 | tmp = NULL; |
| 4450 | } else { |
| 4451 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from TryFinally"); |
| 4452 | return 1; |
| 4453 | } |
| 4454 | *out = TryFinally(body, finalbody, lineno, col_offset, arena); |
| 4455 | if (*out == NULL) goto failed; |
| 4456 | return 0; |
| 4457 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 4458 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type); |
| 4459 | if (isinstance == -1) { |
| 4460 | return 1; |
| 4461 | } |
| 4462 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4463 | expr_ty test; |
| 4464 | expr_ty msg; |
| 4465 | |
| 4466 | if (PyObject_HasAttrString(obj, "test")) { |
| 4467 | int res; |
| 4468 | tmp = PyObject_GetAttrString(obj, "test"); |
| 4469 | if (tmp == NULL) goto failed; |
| 4470 | res = obj2ast_expr(tmp, &test, arena); |
| 4471 | if (res != 0) goto failed; |
| 4472 | Py_XDECREF(tmp); |
| 4473 | tmp = NULL; |
| 4474 | } else { |
| 4475 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 4476 | return 1; |
| 4477 | } |
| 4478 | if (PyObject_HasAttrString(obj, "msg")) { |
| 4479 | int res; |
| 4480 | tmp = PyObject_GetAttrString(obj, "msg"); |
| 4481 | if (tmp == NULL) goto failed; |
| 4482 | res = obj2ast_expr(tmp, &msg, arena); |
| 4483 | if (res != 0) goto failed; |
| 4484 | Py_XDECREF(tmp); |
| 4485 | tmp = NULL; |
| 4486 | } else { |
| 4487 | msg = NULL; |
| 4488 | } |
| 4489 | *out = Assert(test, msg, lineno, col_offset, arena); |
| 4490 | if (*out == NULL) goto failed; |
| 4491 | return 0; |
| 4492 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 4493 | isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type); |
| 4494 | if (isinstance == -1) { |
| 4495 | return 1; |
| 4496 | } |
| 4497 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4498 | asdl_seq* names; |
| 4499 | |
| 4500 | if (PyObject_HasAttrString(obj, "names")) { |
| 4501 | int res; |
| 4502 | Py_ssize_t len; |
| 4503 | Py_ssize_t i; |
| 4504 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4505 | if (tmp == NULL) goto failed; |
| 4506 | if (!PyList_Check(tmp)) { |
| 4507 | PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4508 | goto failed; |
| 4509 | } |
| 4510 | len = PyList_GET_SIZE(tmp); |
| 4511 | names = asdl_seq_new(len, arena); |
| 4512 | if (names == NULL) goto failed; |
| 4513 | for (i = 0; i < len; i++) { |
| 4514 | alias_ty value; |
| 4515 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4516 | if (res != 0) goto failed; |
| 4517 | asdl_seq_SET(names, i, value); |
| 4518 | } |
| 4519 | Py_XDECREF(tmp); |
| 4520 | tmp = NULL; |
| 4521 | } else { |
| 4522 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 4523 | return 1; |
| 4524 | } |
| 4525 | *out = Import(names, lineno, col_offset, arena); |
| 4526 | if (*out == NULL) goto failed; |
| 4527 | return 0; |
| 4528 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 4529 | isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type); |
| 4530 | if (isinstance == -1) { |
| 4531 | return 1; |
| 4532 | } |
| 4533 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4534 | identifier module; |
| 4535 | asdl_seq* names; |
| 4536 | int level; |
| 4537 | |
| 4538 | if (PyObject_HasAttrString(obj, "module")) { |
| 4539 | int res; |
| 4540 | tmp = PyObject_GetAttrString(obj, "module"); |
| 4541 | if (tmp == NULL) goto failed; |
| 4542 | res = obj2ast_identifier(tmp, &module, arena); |
| 4543 | if (res != 0) goto failed; |
| 4544 | Py_XDECREF(tmp); |
| 4545 | tmp = NULL; |
| 4546 | } else { |
| 4547 | PyErr_SetString(PyExc_TypeError, "required field \"module\" missing from ImportFrom"); |
| 4548 | return 1; |
| 4549 | } |
| 4550 | if (PyObject_HasAttrString(obj, "names")) { |
| 4551 | int res; |
| 4552 | Py_ssize_t len; |
| 4553 | Py_ssize_t i; |
| 4554 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4555 | if (tmp == NULL) goto failed; |
| 4556 | if (!PyList_Check(tmp)) { |
| 4557 | PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4558 | goto failed; |
| 4559 | } |
| 4560 | len = PyList_GET_SIZE(tmp); |
| 4561 | names = asdl_seq_new(len, arena); |
| 4562 | if (names == NULL) goto failed; |
| 4563 | for (i = 0; i < len; i++) { |
| 4564 | alias_ty value; |
| 4565 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4566 | if (res != 0) goto failed; |
| 4567 | asdl_seq_SET(names, i, value); |
| 4568 | } |
| 4569 | Py_XDECREF(tmp); |
| 4570 | tmp = NULL; |
| 4571 | } else { |
| 4572 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 4573 | return 1; |
| 4574 | } |
| 4575 | if (PyObject_HasAttrString(obj, "level")) { |
| 4576 | int res; |
| 4577 | tmp = PyObject_GetAttrString(obj, "level"); |
| 4578 | if (tmp == NULL) goto failed; |
| 4579 | res = obj2ast_int(tmp, &level, arena); |
| 4580 | if (res != 0) goto failed; |
| 4581 | Py_XDECREF(tmp); |
| 4582 | tmp = NULL; |
| 4583 | } else { |
| 4584 | level = 0; |
| 4585 | } |
| 4586 | *out = ImportFrom(module, names, level, lineno, col_offset, |
| 4587 | arena); |
| 4588 | if (*out == NULL) goto failed; |
| 4589 | return 0; |
| 4590 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 4591 | isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type); |
| 4592 | if (isinstance == -1) { |
| 4593 | return 1; |
| 4594 | } |
| 4595 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4596 | asdl_seq* names; |
| 4597 | |
| 4598 | if (PyObject_HasAttrString(obj, "names")) { |
| 4599 | int res; |
| 4600 | Py_ssize_t len; |
| 4601 | Py_ssize_t i; |
| 4602 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4603 | if (tmp == NULL) goto failed; |
| 4604 | if (!PyList_Check(tmp)) { |
| 4605 | PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4606 | goto failed; |
| 4607 | } |
| 4608 | len = PyList_GET_SIZE(tmp); |
| 4609 | names = asdl_seq_new(len, arena); |
| 4610 | if (names == NULL) goto failed; |
| 4611 | for (i = 0; i < len; i++) { |
| 4612 | identifier value; |
| 4613 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4614 | if (res != 0) goto failed; |
| 4615 | asdl_seq_SET(names, i, value); |
| 4616 | } |
| 4617 | Py_XDECREF(tmp); |
| 4618 | tmp = NULL; |
| 4619 | } else { |
| 4620 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 4621 | return 1; |
| 4622 | } |
| 4623 | *out = Global(names, lineno, col_offset, arena); |
| 4624 | if (*out == NULL) goto failed; |
| 4625 | return 0; |
| 4626 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 4627 | isinstance = PyObject_IsInstance(obj, (PyObject*)Nonlocal_type); |
| 4628 | if (isinstance == -1) { |
| 4629 | return 1; |
| 4630 | } |
| 4631 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4632 | asdl_seq* names; |
| 4633 | |
| 4634 | if (PyObject_HasAttrString(obj, "names")) { |
| 4635 | int res; |
| 4636 | Py_ssize_t len; |
| 4637 | Py_ssize_t i; |
| 4638 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4639 | if (tmp == NULL) goto failed; |
| 4640 | if (!PyList_Check(tmp)) { |
| 4641 | PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4642 | goto failed; |
| 4643 | } |
| 4644 | len = PyList_GET_SIZE(tmp); |
| 4645 | names = asdl_seq_new(len, arena); |
| 4646 | if (names == NULL) goto failed; |
| 4647 | for (i = 0; i < len; i++) { |
| 4648 | identifier value; |
| 4649 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4650 | if (res != 0) goto failed; |
| 4651 | asdl_seq_SET(names, i, value); |
| 4652 | } |
| 4653 | Py_XDECREF(tmp); |
| 4654 | tmp = NULL; |
| 4655 | } else { |
| 4656 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 4657 | return 1; |
| 4658 | } |
| 4659 | *out = Nonlocal(names, lineno, col_offset, arena); |
| 4660 | if (*out == NULL) goto failed; |
| 4661 | return 0; |
| 4662 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 4663 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type); |
| 4664 | if (isinstance == -1) { |
| 4665 | return 1; |
| 4666 | } |
| 4667 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4668 | expr_ty value; |
| 4669 | |
| 4670 | if (PyObject_HasAttrString(obj, "value")) { |
| 4671 | int res; |
| 4672 | tmp = PyObject_GetAttrString(obj, "value"); |
| 4673 | if (tmp == NULL) goto failed; |
| 4674 | res = obj2ast_expr(tmp, &value, arena); |
| 4675 | if (res != 0) goto failed; |
| 4676 | Py_XDECREF(tmp); |
| 4677 | tmp = NULL; |
| 4678 | } else { |
| 4679 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 4680 | return 1; |
| 4681 | } |
| 4682 | *out = Expr(value, lineno, col_offset, arena); |
| 4683 | if (*out == NULL) goto failed; |
| 4684 | return 0; |
| 4685 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 4686 | isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type); |
| 4687 | if (isinstance == -1) { |
| 4688 | return 1; |
| 4689 | } |
| 4690 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4691 | |
| 4692 | *out = Pass(lineno, col_offset, arena); |
| 4693 | if (*out == NULL) goto failed; |
| 4694 | return 0; |
| 4695 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 4696 | isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type); |
| 4697 | if (isinstance == -1) { |
| 4698 | return 1; |
| 4699 | } |
| 4700 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4701 | |
| 4702 | *out = Break(lineno, col_offset, arena); |
| 4703 | if (*out == NULL) goto failed; |
| 4704 | return 0; |
| 4705 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 4706 | isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type); |
| 4707 | if (isinstance == -1) { |
| 4708 | return 1; |
| 4709 | } |
| 4710 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4711 | |
| 4712 | *out = Continue(lineno, col_offset, arena); |
| 4713 | if (*out == NULL) goto failed; |
| 4714 | return 0; |
| 4715 | } |
| 4716 | |
Benjamin Peterson | aab9585 | 2010-11-20 01:48:38 +0000 | [diff] [blame] | 4717 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
| 4718 | failed: |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4719 | return 1; |
| 4720 | } |
| 4721 | |
| 4722 | int |
| 4723 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 4724 | { |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 4725 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4726 | |
Benjamin Peterson | 787cddc | 2010-11-20 04:37:00 +0000 | [diff] [blame] | 4727 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4728 | int lineno; |
| 4729 | int col_offset; |
| 4730 | |
| 4731 | if (obj == Py_None) { |
| 4732 | *out = NULL; |
| 4733 | return 0; |
| 4734 | } |
| 4735 | if (PyObject_HasAttrString(obj, "lineno")) { |
| 4736 | int res; |
| 4737 | tmp = PyObject_GetAttrString(obj, "lineno"); |
| 4738 | if (tmp == NULL) goto failed; |
| 4739 | res = obj2ast_int(tmp, &lineno, arena); |
| 4740 | if (res != 0) goto failed; |
| 4741 | Py_XDECREF(tmp); |
| 4742 | tmp = NULL; |
| 4743 | } else { |
| 4744 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 4745 | return 1; |
| 4746 | } |
| 4747 | if (PyObject_HasAttrString(obj, "col_offset")) { |
| 4748 | int res; |
| 4749 | tmp = PyObject_GetAttrString(obj, "col_offset"); |
| 4750 | if (tmp == NULL) goto failed; |
| 4751 | res = obj2ast_int(tmp, &col_offset, arena); |
| 4752 | if (res != 0) goto failed; |
| 4753 | Py_XDECREF(tmp); |
| 4754 | tmp = NULL; |
| 4755 | } else { |
| 4756 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 4757 | return 1; |
| 4758 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 4759 | isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type); |
| 4760 | if (isinstance == -1) { |
| 4761 | return 1; |
| 4762 | } |
| 4763 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4764 | boolop_ty op; |
| 4765 | asdl_seq* values; |
| 4766 | |
| 4767 | if (PyObject_HasAttrString(obj, "op")) { |
| 4768 | int res; |
| 4769 | tmp = PyObject_GetAttrString(obj, "op"); |
| 4770 | if (tmp == NULL) goto failed; |
| 4771 | res = obj2ast_boolop(tmp, &op, arena); |
| 4772 | if (res != 0) goto failed; |
| 4773 | Py_XDECREF(tmp); |
| 4774 | tmp = NULL; |
| 4775 | } else { |
| 4776 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 4777 | return 1; |
| 4778 | } |
| 4779 | if (PyObject_HasAttrString(obj, "values")) { |
| 4780 | int res; |
| 4781 | Py_ssize_t len; |
| 4782 | Py_ssize_t i; |
| 4783 | tmp = PyObject_GetAttrString(obj, "values"); |
| 4784 | if (tmp == NULL) goto failed; |
| 4785 | if (!PyList_Check(tmp)) { |
| 4786 | PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4787 | goto failed; |
| 4788 | } |
| 4789 | len = PyList_GET_SIZE(tmp); |
| 4790 | values = asdl_seq_new(len, arena); |
| 4791 | if (values == NULL) goto failed; |
| 4792 | for (i = 0; i < len; i++) { |
| 4793 | expr_ty value; |
| 4794 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4795 | if (res != 0) goto failed; |
| 4796 | asdl_seq_SET(values, i, value); |
| 4797 | } |
| 4798 | Py_XDECREF(tmp); |
| 4799 | tmp = NULL; |
| 4800 | } else { |
| 4801 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 4802 | return 1; |
| 4803 | } |
| 4804 | *out = BoolOp(op, values, lineno, col_offset, arena); |
| 4805 | if (*out == NULL) goto failed; |
| 4806 | return 0; |
| 4807 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 4808 | isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type); |
| 4809 | if (isinstance == -1) { |
| 4810 | return 1; |
| 4811 | } |
| 4812 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4813 | expr_ty left; |
| 4814 | operator_ty op; |
| 4815 | expr_ty right; |
| 4816 | |
| 4817 | if (PyObject_HasAttrString(obj, "left")) { |
| 4818 | int res; |
| 4819 | tmp = PyObject_GetAttrString(obj, "left"); |
| 4820 | if (tmp == NULL) goto failed; |
| 4821 | res = obj2ast_expr(tmp, &left, arena); |
| 4822 | if (res != 0) goto failed; |
| 4823 | Py_XDECREF(tmp); |
| 4824 | tmp = NULL; |
| 4825 | } else { |
| 4826 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 4827 | return 1; |
| 4828 | } |
| 4829 | if (PyObject_HasAttrString(obj, "op")) { |
| 4830 | int res; |
| 4831 | tmp = PyObject_GetAttrString(obj, "op"); |
| 4832 | if (tmp == NULL) goto failed; |
| 4833 | res = obj2ast_operator(tmp, &op, arena); |
| 4834 | if (res != 0) goto failed; |
| 4835 | Py_XDECREF(tmp); |
| 4836 | tmp = NULL; |
| 4837 | } else { |
| 4838 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 4839 | return 1; |
| 4840 | } |
| 4841 | if (PyObject_HasAttrString(obj, "right")) { |
| 4842 | int res; |
| 4843 | tmp = PyObject_GetAttrString(obj, "right"); |
| 4844 | if (tmp == NULL) goto failed; |
| 4845 | res = obj2ast_expr(tmp, &right, arena); |
| 4846 | if (res != 0) goto failed; |
| 4847 | Py_XDECREF(tmp); |
| 4848 | tmp = NULL; |
| 4849 | } else { |
| 4850 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 4851 | return 1; |
| 4852 | } |
| 4853 | *out = BinOp(left, op, right, lineno, col_offset, arena); |
| 4854 | if (*out == NULL) goto failed; |
| 4855 | return 0; |
| 4856 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 4857 | isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type); |
| 4858 | if (isinstance == -1) { |
| 4859 | return 1; |
| 4860 | } |
| 4861 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4862 | unaryop_ty op; |
| 4863 | expr_ty operand; |
| 4864 | |
| 4865 | if (PyObject_HasAttrString(obj, "op")) { |
| 4866 | int res; |
| 4867 | tmp = PyObject_GetAttrString(obj, "op"); |
| 4868 | if (tmp == NULL) goto failed; |
| 4869 | res = obj2ast_unaryop(tmp, &op, arena); |
| 4870 | if (res != 0) goto failed; |
| 4871 | Py_XDECREF(tmp); |
| 4872 | tmp = NULL; |
| 4873 | } else { |
| 4874 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 4875 | return 1; |
| 4876 | } |
| 4877 | if (PyObject_HasAttrString(obj, "operand")) { |
| 4878 | int res; |
| 4879 | tmp = PyObject_GetAttrString(obj, "operand"); |
| 4880 | if (tmp == NULL) goto failed; |
| 4881 | res = obj2ast_expr(tmp, &operand, arena); |
| 4882 | if (res != 0) goto failed; |
| 4883 | Py_XDECREF(tmp); |
| 4884 | tmp = NULL; |
| 4885 | } else { |
| 4886 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 4887 | return 1; |
| 4888 | } |
| 4889 | *out = UnaryOp(op, operand, lineno, col_offset, arena); |
| 4890 | if (*out == NULL) goto failed; |
| 4891 | return 0; |
| 4892 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 4893 | isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type); |
| 4894 | if (isinstance == -1) { |
| 4895 | return 1; |
| 4896 | } |
| 4897 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4898 | arguments_ty args; |
| 4899 | expr_ty body; |
| 4900 | |
| 4901 | if (PyObject_HasAttrString(obj, "args")) { |
| 4902 | int res; |
| 4903 | tmp = PyObject_GetAttrString(obj, "args"); |
| 4904 | if (tmp == NULL) goto failed; |
| 4905 | res = obj2ast_arguments(tmp, &args, arena); |
| 4906 | if (res != 0) goto failed; |
| 4907 | Py_XDECREF(tmp); |
| 4908 | tmp = NULL; |
| 4909 | } else { |
| 4910 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 4911 | return 1; |
| 4912 | } |
| 4913 | if (PyObject_HasAttrString(obj, "body")) { |
| 4914 | int res; |
| 4915 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4916 | if (tmp == NULL) goto failed; |
| 4917 | res = obj2ast_expr(tmp, &body, arena); |
| 4918 | if (res != 0) goto failed; |
| 4919 | Py_XDECREF(tmp); |
| 4920 | tmp = NULL; |
| 4921 | } else { |
| 4922 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 4923 | return 1; |
| 4924 | } |
| 4925 | *out = Lambda(args, body, lineno, col_offset, arena); |
| 4926 | if (*out == NULL) goto failed; |
| 4927 | return 0; |
| 4928 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 4929 | isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type); |
| 4930 | if (isinstance == -1) { |
| 4931 | return 1; |
| 4932 | } |
| 4933 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4934 | expr_ty test; |
| 4935 | expr_ty body; |
| 4936 | expr_ty orelse; |
| 4937 | |
| 4938 | if (PyObject_HasAttrString(obj, "test")) { |
| 4939 | int res; |
| 4940 | tmp = PyObject_GetAttrString(obj, "test"); |
| 4941 | if (tmp == NULL) goto failed; |
| 4942 | res = obj2ast_expr(tmp, &test, arena); |
| 4943 | if (res != 0) goto failed; |
| 4944 | Py_XDECREF(tmp); |
| 4945 | tmp = NULL; |
| 4946 | } else { |
| 4947 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 4948 | return 1; |
| 4949 | } |
| 4950 | if (PyObject_HasAttrString(obj, "body")) { |
| 4951 | int res; |
| 4952 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4953 | if (tmp == NULL) goto failed; |
| 4954 | res = obj2ast_expr(tmp, &body, arena); |
| 4955 | if (res != 0) goto failed; |
| 4956 | Py_XDECREF(tmp); |
| 4957 | tmp = NULL; |
| 4958 | } else { |
| 4959 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 4960 | return 1; |
| 4961 | } |
| 4962 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4963 | int res; |
| 4964 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4965 | if (tmp == NULL) goto failed; |
| 4966 | res = obj2ast_expr(tmp, &orelse, arena); |
| 4967 | if (res != 0) goto failed; |
| 4968 | Py_XDECREF(tmp); |
| 4969 | tmp = NULL; |
| 4970 | } else { |
| 4971 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 4972 | return 1; |
| 4973 | } |
| 4974 | *out = IfExp(test, body, orelse, lineno, col_offset, arena); |
| 4975 | if (*out == NULL) goto failed; |
| 4976 | return 0; |
| 4977 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 4978 | isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type); |
| 4979 | if (isinstance == -1) { |
| 4980 | return 1; |
| 4981 | } |
| 4982 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4983 | asdl_seq* keys; |
| 4984 | asdl_seq* values; |
| 4985 | |
| 4986 | if (PyObject_HasAttrString(obj, "keys")) { |
| 4987 | int res; |
| 4988 | Py_ssize_t len; |
| 4989 | Py_ssize_t i; |
| 4990 | tmp = PyObject_GetAttrString(obj, "keys"); |
| 4991 | if (tmp == NULL) goto failed; |
| 4992 | if (!PyList_Check(tmp)) { |
| 4993 | PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4994 | goto failed; |
| 4995 | } |
| 4996 | len = PyList_GET_SIZE(tmp); |
| 4997 | keys = asdl_seq_new(len, arena); |
| 4998 | if (keys == NULL) goto failed; |
| 4999 | for (i = 0; i < len; i++) { |
| 5000 | expr_ty value; |
| 5001 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5002 | if (res != 0) goto failed; |
| 5003 | asdl_seq_SET(keys, i, value); |
| 5004 | } |
| 5005 | Py_XDECREF(tmp); |
| 5006 | tmp = NULL; |
| 5007 | } else { |
| 5008 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 5009 | return 1; |
| 5010 | } |
| 5011 | if (PyObject_HasAttrString(obj, "values")) { |
| 5012 | int res; |
| 5013 | Py_ssize_t len; |
| 5014 | Py_ssize_t i; |
| 5015 | tmp = PyObject_GetAttrString(obj, "values"); |
| 5016 | if (tmp == NULL) goto failed; |
| 5017 | if (!PyList_Check(tmp)) { |
| 5018 | PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5019 | goto failed; |
| 5020 | } |
| 5021 | len = PyList_GET_SIZE(tmp); |
| 5022 | values = asdl_seq_new(len, arena); |
| 5023 | if (values == NULL) goto failed; |
| 5024 | for (i = 0; i < len; i++) { |
| 5025 | expr_ty value; |
| 5026 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5027 | if (res != 0) goto failed; |
| 5028 | asdl_seq_SET(values, i, value); |
| 5029 | } |
| 5030 | Py_XDECREF(tmp); |
| 5031 | tmp = NULL; |
| 5032 | } else { |
| 5033 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 5034 | return 1; |
| 5035 | } |
| 5036 | *out = Dict(keys, values, lineno, col_offset, arena); |
| 5037 | if (*out == NULL) goto failed; |
| 5038 | return 0; |
| 5039 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 5040 | isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type); |
| 5041 | if (isinstance == -1) { |
| 5042 | return 1; |
| 5043 | } |
| 5044 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5045 | asdl_seq* elts; |
| 5046 | |
| 5047 | if (PyObject_HasAttrString(obj, "elts")) { |
| 5048 | int res; |
| 5049 | Py_ssize_t len; |
| 5050 | Py_ssize_t i; |
| 5051 | tmp = PyObject_GetAttrString(obj, "elts"); |
| 5052 | if (tmp == NULL) goto failed; |
| 5053 | if (!PyList_Check(tmp)) { |
| 5054 | PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5055 | goto failed; |
| 5056 | } |
| 5057 | len = PyList_GET_SIZE(tmp); |
| 5058 | elts = asdl_seq_new(len, arena); |
| 5059 | if (elts == NULL) goto failed; |
| 5060 | for (i = 0; i < len; i++) { |
| 5061 | expr_ty value; |
| 5062 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5063 | if (res != 0) goto failed; |
| 5064 | asdl_seq_SET(elts, i, value); |
| 5065 | } |
| 5066 | Py_XDECREF(tmp); |
| 5067 | tmp = NULL; |
| 5068 | } else { |
| 5069 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 5070 | return 1; |
| 5071 | } |
| 5072 | *out = Set(elts, lineno, col_offset, arena); |
| 5073 | if (*out == NULL) goto failed; |
| 5074 | return 0; |
| 5075 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 5076 | isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type); |
| 5077 | if (isinstance == -1) { |
| 5078 | return 1; |
| 5079 | } |
| 5080 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5081 | expr_ty elt; |
| 5082 | asdl_seq* generators; |
| 5083 | |
| 5084 | if (PyObject_HasAttrString(obj, "elt")) { |
| 5085 | int res; |
| 5086 | tmp = PyObject_GetAttrString(obj, "elt"); |
| 5087 | if (tmp == NULL) goto failed; |
| 5088 | res = obj2ast_expr(tmp, &elt, arena); |
| 5089 | if (res != 0) goto failed; |
| 5090 | Py_XDECREF(tmp); |
| 5091 | tmp = NULL; |
| 5092 | } else { |
| 5093 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 5094 | return 1; |
| 5095 | } |
| 5096 | if (PyObject_HasAttrString(obj, "generators")) { |
| 5097 | int res; |
| 5098 | Py_ssize_t len; |
| 5099 | Py_ssize_t i; |
| 5100 | tmp = PyObject_GetAttrString(obj, "generators"); |
| 5101 | if (tmp == NULL) goto failed; |
| 5102 | if (!PyList_Check(tmp)) { |
| 5103 | PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5104 | goto failed; |
| 5105 | } |
| 5106 | len = PyList_GET_SIZE(tmp); |
| 5107 | generators = asdl_seq_new(len, arena); |
| 5108 | if (generators == NULL) goto failed; |
| 5109 | for (i = 0; i < len; i++) { |
| 5110 | comprehension_ty value; |
| 5111 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5112 | if (res != 0) goto failed; |
| 5113 | asdl_seq_SET(generators, i, value); |
| 5114 | } |
| 5115 | Py_XDECREF(tmp); |
| 5116 | tmp = NULL; |
| 5117 | } else { |
| 5118 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 5119 | return 1; |
| 5120 | } |
| 5121 | *out = ListComp(elt, generators, lineno, col_offset, arena); |
| 5122 | if (*out == NULL) goto failed; |
| 5123 | return 0; |
| 5124 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 5125 | isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type); |
| 5126 | if (isinstance == -1) { |
| 5127 | return 1; |
| 5128 | } |
| 5129 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5130 | expr_ty elt; |
| 5131 | asdl_seq* generators; |
| 5132 | |
| 5133 | if (PyObject_HasAttrString(obj, "elt")) { |
| 5134 | int res; |
| 5135 | tmp = PyObject_GetAttrString(obj, "elt"); |
| 5136 | if (tmp == NULL) goto failed; |
| 5137 | res = obj2ast_expr(tmp, &elt, arena); |
| 5138 | if (res != 0) goto failed; |
| 5139 | Py_XDECREF(tmp); |
| 5140 | tmp = NULL; |
| 5141 | } else { |
| 5142 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 5143 | return 1; |
| 5144 | } |
| 5145 | if (PyObject_HasAttrString(obj, "generators")) { |
| 5146 | int res; |
| 5147 | Py_ssize_t len; |
| 5148 | Py_ssize_t i; |
| 5149 | tmp = PyObject_GetAttrString(obj, "generators"); |
| 5150 | if (tmp == NULL) goto failed; |
| 5151 | if (!PyList_Check(tmp)) { |
| 5152 | PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5153 | goto failed; |
| 5154 | } |
| 5155 | len = PyList_GET_SIZE(tmp); |
| 5156 | generators = asdl_seq_new(len, arena); |
| 5157 | if (generators == NULL) goto failed; |
| 5158 | for (i = 0; i < len; i++) { |
| 5159 | comprehension_ty value; |
| 5160 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5161 | if (res != 0) goto failed; |
| 5162 | asdl_seq_SET(generators, i, value); |
| 5163 | } |
| 5164 | Py_XDECREF(tmp); |
| 5165 | tmp = NULL; |
| 5166 | } else { |
| 5167 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 5168 | return 1; |
| 5169 | } |
| 5170 | *out = SetComp(elt, generators, lineno, col_offset, arena); |
| 5171 | if (*out == NULL) goto failed; |
| 5172 | return 0; |
| 5173 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 5174 | isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type); |
| 5175 | if (isinstance == -1) { |
| 5176 | return 1; |
| 5177 | } |
| 5178 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5179 | expr_ty key; |
| 5180 | expr_ty value; |
| 5181 | asdl_seq* generators; |
| 5182 | |
| 5183 | if (PyObject_HasAttrString(obj, "key")) { |
| 5184 | int res; |
| 5185 | tmp = PyObject_GetAttrString(obj, "key"); |
| 5186 | if (tmp == NULL) goto failed; |
| 5187 | res = obj2ast_expr(tmp, &key, arena); |
| 5188 | if (res != 0) goto failed; |
| 5189 | Py_XDECREF(tmp); |
| 5190 | tmp = NULL; |
| 5191 | } else { |
| 5192 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 5193 | return 1; |
| 5194 | } |
| 5195 | if (PyObject_HasAttrString(obj, "value")) { |
| 5196 | int res; |
| 5197 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5198 | if (tmp == NULL) goto failed; |
| 5199 | res = obj2ast_expr(tmp, &value, arena); |
| 5200 | if (res != 0) goto failed; |
| 5201 | Py_XDECREF(tmp); |
| 5202 | tmp = NULL; |
| 5203 | } else { |
| 5204 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 5205 | return 1; |
| 5206 | } |
| 5207 | if (PyObject_HasAttrString(obj, "generators")) { |
| 5208 | int res; |
| 5209 | Py_ssize_t len; |
| 5210 | Py_ssize_t i; |
| 5211 | tmp = PyObject_GetAttrString(obj, "generators"); |
| 5212 | if (tmp == NULL) goto failed; |
| 5213 | if (!PyList_Check(tmp)) { |
| 5214 | PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5215 | goto failed; |
| 5216 | } |
| 5217 | len = PyList_GET_SIZE(tmp); |
| 5218 | generators = asdl_seq_new(len, arena); |
| 5219 | if (generators == NULL) goto failed; |
| 5220 | for (i = 0; i < len; i++) { |
| 5221 | comprehension_ty value; |
| 5222 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5223 | if (res != 0) goto failed; |
| 5224 | asdl_seq_SET(generators, i, value); |
| 5225 | } |
| 5226 | Py_XDECREF(tmp); |
| 5227 | tmp = NULL; |
| 5228 | } else { |
| 5229 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 5230 | return 1; |
| 5231 | } |
| 5232 | *out = DictComp(key, value, generators, lineno, col_offset, |
| 5233 | arena); |
| 5234 | if (*out == NULL) goto failed; |
| 5235 | return 0; |
| 5236 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 5237 | isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type); |
| 5238 | if (isinstance == -1) { |
| 5239 | return 1; |
| 5240 | } |
| 5241 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5242 | expr_ty elt; |
| 5243 | asdl_seq* generators; |
| 5244 | |
| 5245 | if (PyObject_HasAttrString(obj, "elt")) { |
| 5246 | int res; |
| 5247 | tmp = PyObject_GetAttrString(obj, "elt"); |
| 5248 | if (tmp == NULL) goto failed; |
| 5249 | res = obj2ast_expr(tmp, &elt, arena); |
| 5250 | if (res != 0) goto failed; |
| 5251 | Py_XDECREF(tmp); |
| 5252 | tmp = NULL; |
| 5253 | } else { |
| 5254 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 5255 | return 1; |
| 5256 | } |
| 5257 | if (PyObject_HasAttrString(obj, "generators")) { |
| 5258 | int res; |
| 5259 | Py_ssize_t len; |
| 5260 | Py_ssize_t i; |
| 5261 | tmp = PyObject_GetAttrString(obj, "generators"); |
| 5262 | if (tmp == NULL) goto failed; |
| 5263 | if (!PyList_Check(tmp)) { |
| 5264 | PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5265 | goto failed; |
| 5266 | } |
| 5267 | len = PyList_GET_SIZE(tmp); |
| 5268 | generators = asdl_seq_new(len, arena); |
| 5269 | if (generators == NULL) goto failed; |
| 5270 | for (i = 0; i < len; i++) { |
| 5271 | comprehension_ty value; |
| 5272 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5273 | if (res != 0) goto failed; |
| 5274 | asdl_seq_SET(generators, i, value); |
| 5275 | } |
| 5276 | Py_XDECREF(tmp); |
| 5277 | tmp = NULL; |
| 5278 | } else { |
| 5279 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 5280 | return 1; |
| 5281 | } |
| 5282 | *out = GeneratorExp(elt, generators, lineno, col_offset, arena); |
| 5283 | if (*out == NULL) goto failed; |
| 5284 | return 0; |
| 5285 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 5286 | isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); |
| 5287 | if (isinstance == -1) { |
| 5288 | return 1; |
| 5289 | } |
| 5290 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5291 | expr_ty value; |
| 5292 | |
| 5293 | if (PyObject_HasAttrString(obj, "value")) { |
| 5294 | int res; |
| 5295 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5296 | if (tmp == NULL) goto failed; |
| 5297 | res = obj2ast_expr(tmp, &value, arena); |
| 5298 | if (res != 0) goto failed; |
| 5299 | Py_XDECREF(tmp); |
| 5300 | tmp = NULL; |
| 5301 | } else { |
| 5302 | value = NULL; |
| 5303 | } |
| 5304 | *out = Yield(value, lineno, col_offset, arena); |
| 5305 | if (*out == NULL) goto failed; |
| 5306 | return 0; |
| 5307 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 5308 | isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); |
| 5309 | if (isinstance == -1) { |
| 5310 | return 1; |
| 5311 | } |
| 5312 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5313 | expr_ty left; |
| 5314 | asdl_int_seq* ops; |
| 5315 | asdl_seq* comparators; |
| 5316 | |
| 5317 | if (PyObject_HasAttrString(obj, "left")) { |
| 5318 | int res; |
| 5319 | tmp = PyObject_GetAttrString(obj, "left"); |
| 5320 | if (tmp == NULL) goto failed; |
| 5321 | res = obj2ast_expr(tmp, &left, arena); |
| 5322 | if (res != 0) goto failed; |
| 5323 | Py_XDECREF(tmp); |
| 5324 | tmp = NULL; |
| 5325 | } else { |
| 5326 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 5327 | return 1; |
| 5328 | } |
| 5329 | if (PyObject_HasAttrString(obj, "ops")) { |
| 5330 | int res; |
| 5331 | Py_ssize_t len; |
| 5332 | Py_ssize_t i; |
| 5333 | tmp = PyObject_GetAttrString(obj, "ops"); |
| 5334 | if (tmp == NULL) goto failed; |
| 5335 | if (!PyList_Check(tmp)) { |
| 5336 | PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5337 | goto failed; |
| 5338 | } |
| 5339 | len = PyList_GET_SIZE(tmp); |
| 5340 | ops = asdl_int_seq_new(len, arena); |
| 5341 | if (ops == NULL) goto failed; |
| 5342 | for (i = 0; i < len; i++) { |
| 5343 | cmpop_ty value; |
| 5344 | res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5345 | if (res != 0) goto failed; |
| 5346 | asdl_seq_SET(ops, i, value); |
| 5347 | } |
| 5348 | Py_XDECREF(tmp); |
| 5349 | tmp = NULL; |
| 5350 | } else { |
| 5351 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 5352 | return 1; |
| 5353 | } |
| 5354 | if (PyObject_HasAttrString(obj, "comparators")) { |
| 5355 | int res; |
| 5356 | Py_ssize_t len; |
| 5357 | Py_ssize_t i; |
| 5358 | tmp = PyObject_GetAttrString(obj, "comparators"); |
| 5359 | if (tmp == NULL) goto failed; |
| 5360 | if (!PyList_Check(tmp)) { |
| 5361 | PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5362 | goto failed; |
| 5363 | } |
| 5364 | len = PyList_GET_SIZE(tmp); |
| 5365 | comparators = asdl_seq_new(len, arena); |
| 5366 | if (comparators == NULL) goto failed; |
| 5367 | for (i = 0; i < len; i++) { |
| 5368 | expr_ty value; |
| 5369 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5370 | if (res != 0) goto failed; |
| 5371 | asdl_seq_SET(comparators, i, value); |
| 5372 | } |
| 5373 | Py_XDECREF(tmp); |
| 5374 | tmp = NULL; |
| 5375 | } else { |
| 5376 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 5377 | return 1; |
| 5378 | } |
| 5379 | *out = Compare(left, ops, comparators, lineno, col_offset, |
| 5380 | arena); |
| 5381 | if (*out == NULL) goto failed; |
| 5382 | return 0; |
| 5383 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 5384 | isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type); |
| 5385 | if (isinstance == -1) { |
| 5386 | return 1; |
| 5387 | } |
| 5388 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5389 | expr_ty func; |
| 5390 | asdl_seq* args; |
| 5391 | asdl_seq* keywords; |
| 5392 | expr_ty starargs; |
| 5393 | expr_ty kwargs; |
| 5394 | |
| 5395 | if (PyObject_HasAttrString(obj, "func")) { |
| 5396 | int res; |
| 5397 | tmp = PyObject_GetAttrString(obj, "func"); |
| 5398 | if (tmp == NULL) goto failed; |
| 5399 | res = obj2ast_expr(tmp, &func, arena); |
| 5400 | if (res != 0) goto failed; |
| 5401 | Py_XDECREF(tmp); |
| 5402 | tmp = NULL; |
| 5403 | } else { |
| 5404 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 5405 | return 1; |
| 5406 | } |
| 5407 | if (PyObject_HasAttrString(obj, "args")) { |
| 5408 | int res; |
| 5409 | Py_ssize_t len; |
| 5410 | Py_ssize_t i; |
| 5411 | tmp = PyObject_GetAttrString(obj, "args"); |
| 5412 | if (tmp == NULL) goto failed; |
| 5413 | if (!PyList_Check(tmp)) { |
| 5414 | PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5415 | goto failed; |
| 5416 | } |
| 5417 | len = PyList_GET_SIZE(tmp); |
| 5418 | args = asdl_seq_new(len, arena); |
| 5419 | if (args == NULL) goto failed; |
| 5420 | for (i = 0; i < len; i++) { |
| 5421 | expr_ty value; |
| 5422 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5423 | if (res != 0) goto failed; |
| 5424 | asdl_seq_SET(args, i, value); |
| 5425 | } |
| 5426 | Py_XDECREF(tmp); |
| 5427 | tmp = NULL; |
| 5428 | } else { |
| 5429 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 5430 | return 1; |
| 5431 | } |
| 5432 | if (PyObject_HasAttrString(obj, "keywords")) { |
| 5433 | int res; |
| 5434 | Py_ssize_t len; |
| 5435 | Py_ssize_t i; |
| 5436 | tmp = PyObject_GetAttrString(obj, "keywords"); |
| 5437 | if (tmp == NULL) goto failed; |
| 5438 | if (!PyList_Check(tmp)) { |
| 5439 | PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5440 | goto failed; |
| 5441 | } |
| 5442 | len = PyList_GET_SIZE(tmp); |
| 5443 | keywords = asdl_seq_new(len, arena); |
| 5444 | if (keywords == NULL) goto failed; |
| 5445 | for (i = 0; i < len; i++) { |
| 5446 | keyword_ty value; |
| 5447 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5448 | if (res != 0) goto failed; |
| 5449 | asdl_seq_SET(keywords, i, value); |
| 5450 | } |
| 5451 | Py_XDECREF(tmp); |
| 5452 | tmp = NULL; |
| 5453 | } else { |
| 5454 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 5455 | return 1; |
| 5456 | } |
| 5457 | if (PyObject_HasAttrString(obj, "starargs")) { |
| 5458 | int res; |
| 5459 | tmp = PyObject_GetAttrString(obj, "starargs"); |
| 5460 | if (tmp == NULL) goto failed; |
| 5461 | res = obj2ast_expr(tmp, &starargs, arena); |
| 5462 | if (res != 0) goto failed; |
| 5463 | Py_XDECREF(tmp); |
| 5464 | tmp = NULL; |
| 5465 | } else { |
| 5466 | starargs = NULL; |
| 5467 | } |
| 5468 | if (PyObject_HasAttrString(obj, "kwargs")) { |
| 5469 | int res; |
| 5470 | tmp = PyObject_GetAttrString(obj, "kwargs"); |
| 5471 | if (tmp == NULL) goto failed; |
| 5472 | res = obj2ast_expr(tmp, &kwargs, arena); |
| 5473 | if (res != 0) goto failed; |
| 5474 | Py_XDECREF(tmp); |
| 5475 | tmp = NULL; |
| 5476 | } else { |
| 5477 | kwargs = NULL; |
| 5478 | } |
| 5479 | *out = Call(func, args, keywords, starargs, kwargs, lineno, |
| 5480 | col_offset, arena); |
| 5481 | if (*out == NULL) goto failed; |
| 5482 | return 0; |
| 5483 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 5484 | isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type); |
| 5485 | if (isinstance == -1) { |
| 5486 | return 1; |
| 5487 | } |
| 5488 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5489 | object n; |
| 5490 | |
| 5491 | if (PyObject_HasAttrString(obj, "n")) { |
| 5492 | int res; |
| 5493 | tmp = PyObject_GetAttrString(obj, "n"); |
| 5494 | if (tmp == NULL) goto failed; |
| 5495 | res = obj2ast_object(tmp, &n, arena); |
| 5496 | if (res != 0) goto failed; |
| 5497 | Py_XDECREF(tmp); |
| 5498 | tmp = NULL; |
| 5499 | } else { |
| 5500 | PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num"); |
| 5501 | return 1; |
| 5502 | } |
| 5503 | *out = Num(n, lineno, col_offset, arena); |
| 5504 | if (*out == NULL) goto failed; |
| 5505 | return 0; |
| 5506 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 5507 | isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type); |
| 5508 | if (isinstance == -1) { |
| 5509 | return 1; |
| 5510 | } |
| 5511 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5512 | string s; |
| 5513 | |
| 5514 | if (PyObject_HasAttrString(obj, "s")) { |
| 5515 | int res; |
| 5516 | tmp = PyObject_GetAttrString(obj, "s"); |
| 5517 | if (tmp == NULL) goto failed; |
| 5518 | res = obj2ast_string(tmp, &s, arena); |
| 5519 | if (res != 0) goto failed; |
| 5520 | Py_XDECREF(tmp); |
| 5521 | tmp = NULL; |
| 5522 | } else { |
| 5523 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str"); |
| 5524 | return 1; |
| 5525 | } |
| 5526 | *out = Str(s, lineno, col_offset, arena); |
| 5527 | if (*out == NULL) goto failed; |
| 5528 | return 0; |
| 5529 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 5530 | isinstance = PyObject_IsInstance(obj, (PyObject*)Bytes_type); |
| 5531 | if (isinstance == -1) { |
| 5532 | return 1; |
| 5533 | } |
| 5534 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5535 | string s; |
| 5536 | |
| 5537 | if (PyObject_HasAttrString(obj, "s")) { |
| 5538 | int res; |
| 5539 | tmp = PyObject_GetAttrString(obj, "s"); |
| 5540 | if (tmp == NULL) goto failed; |
| 5541 | res = obj2ast_string(tmp, &s, arena); |
| 5542 | if (res != 0) goto failed; |
| 5543 | Py_XDECREF(tmp); |
| 5544 | tmp = NULL; |
| 5545 | } else { |
| 5546 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Bytes"); |
| 5547 | return 1; |
| 5548 | } |
| 5549 | *out = Bytes(s, lineno, col_offset, arena); |
| 5550 | if (*out == NULL) goto failed; |
| 5551 | return 0; |
| 5552 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 5553 | isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type); |
| 5554 | if (isinstance == -1) { |
| 5555 | return 1; |
| 5556 | } |
| 5557 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5558 | |
| 5559 | *out = Ellipsis(lineno, col_offset, arena); |
| 5560 | if (*out == NULL) goto failed; |
| 5561 | return 0; |
| 5562 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 5563 | isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type); |
| 5564 | if (isinstance == -1) { |
| 5565 | return 1; |
| 5566 | } |
| 5567 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5568 | expr_ty value; |
| 5569 | identifier attr; |
| 5570 | expr_context_ty ctx; |
| 5571 | |
| 5572 | if (PyObject_HasAttrString(obj, "value")) { |
| 5573 | int res; |
| 5574 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5575 | if (tmp == NULL) goto failed; |
| 5576 | res = obj2ast_expr(tmp, &value, arena); |
| 5577 | if (res != 0) goto failed; |
| 5578 | Py_XDECREF(tmp); |
| 5579 | tmp = NULL; |
| 5580 | } else { |
| 5581 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 5582 | return 1; |
| 5583 | } |
| 5584 | if (PyObject_HasAttrString(obj, "attr")) { |
| 5585 | int res; |
| 5586 | tmp = PyObject_GetAttrString(obj, "attr"); |
| 5587 | if (tmp == NULL) goto failed; |
| 5588 | res = obj2ast_identifier(tmp, &attr, arena); |
| 5589 | if (res != 0) goto failed; |
| 5590 | Py_XDECREF(tmp); |
| 5591 | tmp = NULL; |
| 5592 | } else { |
| 5593 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 5594 | return 1; |
| 5595 | } |
| 5596 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5597 | int res; |
| 5598 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5599 | if (tmp == NULL) goto failed; |
| 5600 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5601 | if (res != 0) goto failed; |
| 5602 | Py_XDECREF(tmp); |
| 5603 | tmp = NULL; |
| 5604 | } else { |
| 5605 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 5606 | return 1; |
| 5607 | } |
| 5608 | *out = Attribute(value, attr, ctx, lineno, col_offset, arena); |
| 5609 | if (*out == NULL) goto failed; |
| 5610 | return 0; |
| 5611 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 5612 | isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type); |
| 5613 | if (isinstance == -1) { |
| 5614 | return 1; |
| 5615 | } |
| 5616 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5617 | expr_ty value; |
| 5618 | slice_ty slice; |
| 5619 | expr_context_ty ctx; |
| 5620 | |
| 5621 | if (PyObject_HasAttrString(obj, "value")) { |
| 5622 | int res; |
| 5623 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5624 | if (tmp == NULL) goto failed; |
| 5625 | res = obj2ast_expr(tmp, &value, arena); |
| 5626 | if (res != 0) goto failed; |
| 5627 | Py_XDECREF(tmp); |
| 5628 | tmp = NULL; |
| 5629 | } else { |
| 5630 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 5631 | return 1; |
| 5632 | } |
| 5633 | if (PyObject_HasAttrString(obj, "slice")) { |
| 5634 | int res; |
| 5635 | tmp = PyObject_GetAttrString(obj, "slice"); |
| 5636 | if (tmp == NULL) goto failed; |
| 5637 | res = obj2ast_slice(tmp, &slice, arena); |
| 5638 | if (res != 0) goto failed; |
| 5639 | Py_XDECREF(tmp); |
| 5640 | tmp = NULL; |
| 5641 | } else { |
| 5642 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 5643 | return 1; |
| 5644 | } |
| 5645 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5646 | int res; |
| 5647 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5648 | if (tmp == NULL) goto failed; |
| 5649 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5650 | if (res != 0) goto failed; |
| 5651 | Py_XDECREF(tmp); |
| 5652 | tmp = NULL; |
| 5653 | } else { |
| 5654 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 5655 | return 1; |
| 5656 | } |
| 5657 | *out = Subscript(value, slice, ctx, lineno, col_offset, arena); |
| 5658 | if (*out == NULL) goto failed; |
| 5659 | return 0; |
| 5660 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 5661 | isinstance = PyObject_IsInstance(obj, (PyObject*)Starred_type); |
| 5662 | if (isinstance == -1) { |
| 5663 | return 1; |
| 5664 | } |
| 5665 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5666 | expr_ty value; |
| 5667 | expr_context_ty ctx; |
| 5668 | |
| 5669 | if (PyObject_HasAttrString(obj, "value")) { |
| 5670 | int res; |
| 5671 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5672 | if (tmp == NULL) goto failed; |
| 5673 | res = obj2ast_expr(tmp, &value, arena); |
| 5674 | if (res != 0) goto failed; |
| 5675 | Py_XDECREF(tmp); |
| 5676 | tmp = NULL; |
| 5677 | } else { |
| 5678 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 5679 | return 1; |
| 5680 | } |
| 5681 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5682 | int res; |
| 5683 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5684 | if (tmp == NULL) goto failed; |
| 5685 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5686 | if (res != 0) goto failed; |
| 5687 | Py_XDECREF(tmp); |
| 5688 | tmp = NULL; |
| 5689 | } else { |
| 5690 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 5691 | return 1; |
| 5692 | } |
| 5693 | *out = Starred(value, ctx, lineno, col_offset, arena); |
| 5694 | if (*out == NULL) goto failed; |
| 5695 | return 0; |
| 5696 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 5697 | isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type); |
| 5698 | if (isinstance == -1) { |
| 5699 | return 1; |
| 5700 | } |
| 5701 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5702 | identifier id; |
| 5703 | expr_context_ty ctx; |
| 5704 | |
| 5705 | if (PyObject_HasAttrString(obj, "id")) { |
| 5706 | int res; |
| 5707 | tmp = PyObject_GetAttrString(obj, "id"); |
| 5708 | if (tmp == NULL) goto failed; |
| 5709 | res = obj2ast_identifier(tmp, &id, arena); |
| 5710 | if (res != 0) goto failed; |
| 5711 | Py_XDECREF(tmp); |
| 5712 | tmp = NULL; |
| 5713 | } else { |
| 5714 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 5715 | return 1; |
| 5716 | } |
| 5717 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5718 | int res; |
| 5719 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5720 | if (tmp == NULL) goto failed; |
| 5721 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5722 | if (res != 0) goto failed; |
| 5723 | Py_XDECREF(tmp); |
| 5724 | tmp = NULL; |
| 5725 | } else { |
| 5726 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 5727 | return 1; |
| 5728 | } |
| 5729 | *out = Name(id, ctx, lineno, col_offset, arena); |
| 5730 | if (*out == NULL) goto failed; |
| 5731 | return 0; |
| 5732 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 5733 | isinstance = PyObject_IsInstance(obj, (PyObject*)List_type); |
| 5734 | if (isinstance == -1) { |
| 5735 | return 1; |
| 5736 | } |
| 5737 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5738 | asdl_seq* elts; |
| 5739 | expr_context_ty ctx; |
| 5740 | |
| 5741 | if (PyObject_HasAttrString(obj, "elts")) { |
| 5742 | int res; |
| 5743 | Py_ssize_t len; |
| 5744 | Py_ssize_t i; |
| 5745 | tmp = PyObject_GetAttrString(obj, "elts"); |
| 5746 | if (tmp == NULL) goto failed; |
| 5747 | if (!PyList_Check(tmp)) { |
| 5748 | PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5749 | goto failed; |
| 5750 | } |
| 5751 | len = PyList_GET_SIZE(tmp); |
| 5752 | elts = asdl_seq_new(len, arena); |
| 5753 | if (elts == NULL) goto failed; |
| 5754 | for (i = 0; i < len; i++) { |
| 5755 | expr_ty value; |
| 5756 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5757 | if (res != 0) goto failed; |
| 5758 | asdl_seq_SET(elts, i, value); |
| 5759 | } |
| 5760 | Py_XDECREF(tmp); |
| 5761 | tmp = NULL; |
| 5762 | } else { |
| 5763 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 5764 | return 1; |
| 5765 | } |
| 5766 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5767 | int res; |
| 5768 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5769 | if (tmp == NULL) goto failed; |
| 5770 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5771 | if (res != 0) goto failed; |
| 5772 | Py_XDECREF(tmp); |
| 5773 | tmp = NULL; |
| 5774 | } else { |
| 5775 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 5776 | return 1; |
| 5777 | } |
| 5778 | *out = List(elts, ctx, lineno, col_offset, arena); |
| 5779 | if (*out == NULL) goto failed; |
| 5780 | return 0; |
| 5781 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 5782 | isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type); |
| 5783 | if (isinstance == -1) { |
| 5784 | return 1; |
| 5785 | } |
| 5786 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5787 | asdl_seq* elts; |
| 5788 | expr_context_ty ctx; |
| 5789 | |
| 5790 | if (PyObject_HasAttrString(obj, "elts")) { |
| 5791 | int res; |
| 5792 | Py_ssize_t len; |
| 5793 | Py_ssize_t i; |
| 5794 | tmp = PyObject_GetAttrString(obj, "elts"); |
| 5795 | if (tmp == NULL) goto failed; |
| 5796 | if (!PyList_Check(tmp)) { |
| 5797 | PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5798 | goto failed; |
| 5799 | } |
| 5800 | len = PyList_GET_SIZE(tmp); |
| 5801 | elts = asdl_seq_new(len, arena); |
| 5802 | if (elts == NULL) goto failed; |
| 5803 | for (i = 0; i < len; i++) { |
| 5804 | expr_ty value; |
| 5805 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5806 | if (res != 0) goto failed; |
| 5807 | asdl_seq_SET(elts, i, value); |
| 5808 | } |
| 5809 | Py_XDECREF(tmp); |
| 5810 | tmp = NULL; |
| 5811 | } else { |
| 5812 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 5813 | return 1; |
| 5814 | } |
| 5815 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5816 | int res; |
| 5817 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5818 | if (tmp == NULL) goto failed; |
| 5819 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5820 | if (res != 0) goto failed; |
| 5821 | Py_XDECREF(tmp); |
| 5822 | tmp = NULL; |
| 5823 | } else { |
| 5824 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 5825 | return 1; |
| 5826 | } |
| 5827 | *out = Tuple(elts, ctx, lineno, col_offset, arena); |
| 5828 | if (*out == NULL) goto failed; |
| 5829 | return 0; |
| 5830 | } |
| 5831 | |
Benjamin Peterson | aab9585 | 2010-11-20 01:48:38 +0000 | [diff] [blame] | 5832 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
| 5833 | failed: |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5834 | return 1; |
| 5835 | } |
| 5836 | |
| 5837 | int |
| 5838 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 5839 | { |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 5840 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5841 | |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 5842 | isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); |
| 5843 | if (isinstance == -1) { |
| 5844 | return 1; |
| 5845 | } |
| 5846 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5847 | *out = Load; |
| 5848 | return 0; |
| 5849 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 5850 | isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type); |
| 5851 | if (isinstance == -1) { |
| 5852 | return 1; |
| 5853 | } |
| 5854 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5855 | *out = Store; |
| 5856 | return 0; |
| 5857 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 5858 | isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type); |
| 5859 | if (isinstance == -1) { |
| 5860 | return 1; |
| 5861 | } |
| 5862 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5863 | *out = Del; |
| 5864 | return 0; |
| 5865 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 5866 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type); |
| 5867 | if (isinstance == -1) { |
| 5868 | return 1; |
| 5869 | } |
| 5870 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5871 | *out = AugLoad; |
| 5872 | return 0; |
| 5873 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 5874 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type); |
| 5875 | if (isinstance == -1) { |
| 5876 | return 1; |
| 5877 | } |
| 5878 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5879 | *out = AugStore; |
| 5880 | return 0; |
| 5881 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 5882 | isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type); |
| 5883 | if (isinstance == -1) { |
| 5884 | return 1; |
| 5885 | } |
| 5886 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5887 | *out = Param; |
| 5888 | return 0; |
| 5889 | } |
| 5890 | |
Benjamin Peterson | aab9585 | 2010-11-20 01:48:38 +0000 | [diff] [blame] | 5891 | 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] | 5892 | return 1; |
| 5893 | } |
| 5894 | |
| 5895 | int |
| 5896 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
| 5897 | { |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 5898 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5899 | |
Benjamin Peterson | 787cddc | 2010-11-20 04:37:00 +0000 | [diff] [blame] | 5900 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5901 | |
| 5902 | if (obj == Py_None) { |
| 5903 | *out = NULL; |
| 5904 | return 0; |
| 5905 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 5906 | isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type); |
| 5907 | if (isinstance == -1) { |
| 5908 | return 1; |
| 5909 | } |
| 5910 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5911 | expr_ty lower; |
| 5912 | expr_ty upper; |
| 5913 | expr_ty step; |
| 5914 | |
| 5915 | if (PyObject_HasAttrString(obj, "lower")) { |
| 5916 | int res; |
| 5917 | tmp = PyObject_GetAttrString(obj, "lower"); |
| 5918 | if (tmp == NULL) goto failed; |
| 5919 | res = obj2ast_expr(tmp, &lower, arena); |
| 5920 | if (res != 0) goto failed; |
| 5921 | Py_XDECREF(tmp); |
| 5922 | tmp = NULL; |
| 5923 | } else { |
| 5924 | lower = NULL; |
| 5925 | } |
| 5926 | if (PyObject_HasAttrString(obj, "upper")) { |
| 5927 | int res; |
| 5928 | tmp = PyObject_GetAttrString(obj, "upper"); |
| 5929 | if (tmp == NULL) goto failed; |
| 5930 | res = obj2ast_expr(tmp, &upper, arena); |
| 5931 | if (res != 0) goto failed; |
| 5932 | Py_XDECREF(tmp); |
| 5933 | tmp = NULL; |
| 5934 | } else { |
| 5935 | upper = NULL; |
| 5936 | } |
| 5937 | if (PyObject_HasAttrString(obj, "step")) { |
| 5938 | int res; |
| 5939 | tmp = PyObject_GetAttrString(obj, "step"); |
| 5940 | if (tmp == NULL) goto failed; |
| 5941 | res = obj2ast_expr(tmp, &step, arena); |
| 5942 | if (res != 0) goto failed; |
| 5943 | Py_XDECREF(tmp); |
| 5944 | tmp = NULL; |
| 5945 | } else { |
| 5946 | step = NULL; |
| 5947 | } |
| 5948 | *out = Slice(lower, upper, step, arena); |
| 5949 | if (*out == NULL) goto failed; |
| 5950 | return 0; |
| 5951 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 5952 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type); |
| 5953 | if (isinstance == -1) { |
| 5954 | return 1; |
| 5955 | } |
| 5956 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5957 | asdl_seq* dims; |
| 5958 | |
| 5959 | if (PyObject_HasAttrString(obj, "dims")) { |
| 5960 | int res; |
| 5961 | Py_ssize_t len; |
| 5962 | Py_ssize_t i; |
| 5963 | tmp = PyObject_GetAttrString(obj, "dims"); |
| 5964 | if (tmp == NULL) goto failed; |
| 5965 | if (!PyList_Check(tmp)) { |
| 5966 | PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5967 | goto failed; |
| 5968 | } |
| 5969 | len = PyList_GET_SIZE(tmp); |
| 5970 | dims = asdl_seq_new(len, arena); |
| 5971 | if (dims == NULL) goto failed; |
| 5972 | for (i = 0; i < len; i++) { |
| 5973 | slice_ty value; |
| 5974 | res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5975 | if (res != 0) goto failed; |
| 5976 | asdl_seq_SET(dims, i, value); |
| 5977 | } |
| 5978 | Py_XDECREF(tmp); |
| 5979 | tmp = NULL; |
| 5980 | } else { |
| 5981 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
| 5982 | return 1; |
| 5983 | } |
| 5984 | *out = ExtSlice(dims, arena); |
| 5985 | if (*out == NULL) goto failed; |
| 5986 | return 0; |
| 5987 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 5988 | isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type); |
| 5989 | if (isinstance == -1) { |
| 5990 | return 1; |
| 5991 | } |
| 5992 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5993 | expr_ty value; |
| 5994 | |
| 5995 | if (PyObject_HasAttrString(obj, "value")) { |
| 5996 | int res; |
| 5997 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5998 | if (tmp == NULL) goto failed; |
| 5999 | res = obj2ast_expr(tmp, &value, arena); |
| 6000 | if (res != 0) goto failed; |
| 6001 | Py_XDECREF(tmp); |
| 6002 | tmp = NULL; |
| 6003 | } else { |
| 6004 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
| 6005 | return 1; |
| 6006 | } |
| 6007 | *out = Index(value, arena); |
| 6008 | if (*out == NULL) goto failed; |
| 6009 | return 0; |
| 6010 | } |
| 6011 | |
Benjamin Peterson | aab9585 | 2010-11-20 01:48:38 +0000 | [diff] [blame] | 6012 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj); |
| 6013 | failed: |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6014 | return 1; |
| 6015 | } |
| 6016 | |
| 6017 | int |
| 6018 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 6019 | { |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6020 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6021 | |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6022 | isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); |
| 6023 | if (isinstance == -1) { |
| 6024 | return 1; |
| 6025 | } |
| 6026 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6027 | *out = And; |
| 6028 | return 0; |
| 6029 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6030 | isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type); |
| 6031 | if (isinstance == -1) { |
| 6032 | return 1; |
| 6033 | } |
| 6034 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6035 | *out = Or; |
| 6036 | return 0; |
| 6037 | } |
| 6038 | |
Benjamin Peterson | aab9585 | 2010-11-20 01:48:38 +0000 | [diff] [blame] | 6039 | 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] | 6040 | return 1; |
| 6041 | } |
| 6042 | |
| 6043 | int |
| 6044 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 6045 | { |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6046 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6047 | |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6048 | isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); |
| 6049 | if (isinstance == -1) { |
| 6050 | return 1; |
| 6051 | } |
| 6052 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6053 | *out = Add; |
| 6054 | return 0; |
| 6055 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6056 | isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type); |
| 6057 | if (isinstance == -1) { |
| 6058 | return 1; |
| 6059 | } |
| 6060 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6061 | *out = Sub; |
| 6062 | return 0; |
| 6063 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6064 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type); |
| 6065 | if (isinstance == -1) { |
| 6066 | return 1; |
| 6067 | } |
| 6068 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6069 | *out = Mult; |
| 6070 | return 0; |
| 6071 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6072 | isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type); |
| 6073 | if (isinstance == -1) { |
| 6074 | return 1; |
| 6075 | } |
| 6076 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6077 | *out = Div; |
| 6078 | return 0; |
| 6079 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6080 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type); |
| 6081 | if (isinstance == -1) { |
| 6082 | return 1; |
| 6083 | } |
| 6084 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6085 | *out = Mod; |
| 6086 | return 0; |
| 6087 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6088 | isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type); |
| 6089 | if (isinstance == -1) { |
| 6090 | return 1; |
| 6091 | } |
| 6092 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6093 | *out = Pow; |
| 6094 | return 0; |
| 6095 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6096 | isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type); |
| 6097 | if (isinstance == -1) { |
| 6098 | return 1; |
| 6099 | } |
| 6100 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6101 | *out = LShift; |
| 6102 | return 0; |
| 6103 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6104 | isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type); |
| 6105 | if (isinstance == -1) { |
| 6106 | return 1; |
| 6107 | } |
| 6108 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6109 | *out = RShift; |
| 6110 | return 0; |
| 6111 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6112 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type); |
| 6113 | if (isinstance == -1) { |
| 6114 | return 1; |
| 6115 | } |
| 6116 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6117 | *out = BitOr; |
| 6118 | return 0; |
| 6119 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6120 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type); |
| 6121 | if (isinstance == -1) { |
| 6122 | return 1; |
| 6123 | } |
| 6124 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6125 | *out = BitXor; |
| 6126 | return 0; |
| 6127 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6128 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type); |
| 6129 | if (isinstance == -1) { |
| 6130 | return 1; |
| 6131 | } |
| 6132 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6133 | *out = BitAnd; |
| 6134 | return 0; |
| 6135 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6136 | isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type); |
| 6137 | if (isinstance == -1) { |
| 6138 | return 1; |
| 6139 | } |
| 6140 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6141 | *out = FloorDiv; |
| 6142 | return 0; |
| 6143 | } |
| 6144 | |
Benjamin Peterson | aab9585 | 2010-11-20 01:48:38 +0000 | [diff] [blame] | 6145 | 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] | 6146 | return 1; |
| 6147 | } |
| 6148 | |
| 6149 | int |
| 6150 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 6151 | { |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6152 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6153 | |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6154 | isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); |
| 6155 | if (isinstance == -1) { |
| 6156 | return 1; |
| 6157 | } |
| 6158 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6159 | *out = Invert; |
| 6160 | return 0; |
| 6161 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6162 | isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type); |
| 6163 | if (isinstance == -1) { |
| 6164 | return 1; |
| 6165 | } |
| 6166 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6167 | *out = Not; |
| 6168 | return 0; |
| 6169 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6170 | isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type); |
| 6171 | if (isinstance == -1) { |
| 6172 | return 1; |
| 6173 | } |
| 6174 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6175 | *out = UAdd; |
| 6176 | return 0; |
| 6177 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6178 | isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type); |
| 6179 | if (isinstance == -1) { |
| 6180 | return 1; |
| 6181 | } |
| 6182 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6183 | *out = USub; |
| 6184 | return 0; |
| 6185 | } |
| 6186 | |
Benjamin Peterson | aab9585 | 2010-11-20 01:48:38 +0000 | [diff] [blame] | 6187 | 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] | 6188 | return 1; |
| 6189 | } |
| 6190 | |
| 6191 | int |
| 6192 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 6193 | { |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6194 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6195 | |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6196 | isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); |
| 6197 | if (isinstance == -1) { |
| 6198 | return 1; |
| 6199 | } |
| 6200 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6201 | *out = Eq; |
| 6202 | return 0; |
| 6203 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6204 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type); |
| 6205 | if (isinstance == -1) { |
| 6206 | return 1; |
| 6207 | } |
| 6208 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6209 | *out = NotEq; |
| 6210 | return 0; |
| 6211 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6212 | isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type); |
| 6213 | if (isinstance == -1) { |
| 6214 | return 1; |
| 6215 | } |
| 6216 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6217 | *out = Lt; |
| 6218 | return 0; |
| 6219 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6220 | isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type); |
| 6221 | if (isinstance == -1) { |
| 6222 | return 1; |
| 6223 | } |
| 6224 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6225 | *out = LtE; |
| 6226 | return 0; |
| 6227 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6228 | isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type); |
| 6229 | if (isinstance == -1) { |
| 6230 | return 1; |
| 6231 | } |
| 6232 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6233 | *out = Gt; |
| 6234 | return 0; |
| 6235 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6236 | isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type); |
| 6237 | if (isinstance == -1) { |
| 6238 | return 1; |
| 6239 | } |
| 6240 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6241 | *out = GtE; |
| 6242 | return 0; |
| 6243 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6244 | isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type); |
| 6245 | if (isinstance == -1) { |
| 6246 | return 1; |
| 6247 | } |
| 6248 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6249 | *out = Is; |
| 6250 | return 0; |
| 6251 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6252 | isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type); |
| 6253 | if (isinstance == -1) { |
| 6254 | return 1; |
| 6255 | } |
| 6256 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6257 | *out = IsNot; |
| 6258 | return 0; |
| 6259 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6260 | isinstance = PyObject_IsInstance(obj, (PyObject *)In_type); |
| 6261 | if (isinstance == -1) { |
| 6262 | return 1; |
| 6263 | } |
| 6264 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6265 | *out = In; |
| 6266 | return 0; |
| 6267 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6268 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type); |
| 6269 | if (isinstance == -1) { |
| 6270 | return 1; |
| 6271 | } |
| 6272 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6273 | *out = NotIn; |
| 6274 | return 0; |
| 6275 | } |
| 6276 | |
Benjamin Peterson | aab9585 | 2010-11-20 01:48:38 +0000 | [diff] [blame] | 6277 | 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] | 6278 | return 1; |
| 6279 | } |
| 6280 | |
| 6281 | int |
| 6282 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 6283 | { |
| 6284 | PyObject* tmp = NULL; |
| 6285 | expr_ty target; |
| 6286 | expr_ty iter; |
| 6287 | asdl_seq* ifs; |
| 6288 | |
| 6289 | if (PyObject_HasAttrString(obj, "target")) { |
| 6290 | int res; |
| 6291 | tmp = PyObject_GetAttrString(obj, "target"); |
| 6292 | if (tmp == NULL) goto failed; |
| 6293 | res = obj2ast_expr(tmp, &target, arena); |
| 6294 | if (res != 0) goto failed; |
| 6295 | Py_XDECREF(tmp); |
| 6296 | tmp = NULL; |
| 6297 | } else { |
| 6298 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 6299 | return 1; |
| 6300 | } |
| 6301 | if (PyObject_HasAttrString(obj, "iter")) { |
| 6302 | int res; |
| 6303 | tmp = PyObject_GetAttrString(obj, "iter"); |
| 6304 | if (tmp == NULL) goto failed; |
| 6305 | res = obj2ast_expr(tmp, &iter, arena); |
| 6306 | if (res != 0) goto failed; |
| 6307 | Py_XDECREF(tmp); |
| 6308 | tmp = NULL; |
| 6309 | } else { |
| 6310 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 6311 | return 1; |
| 6312 | } |
| 6313 | if (PyObject_HasAttrString(obj, "ifs")) { |
| 6314 | int res; |
| 6315 | Py_ssize_t len; |
| 6316 | Py_ssize_t i; |
| 6317 | tmp = PyObject_GetAttrString(obj, "ifs"); |
| 6318 | if (tmp == NULL) goto failed; |
| 6319 | if (!PyList_Check(tmp)) { |
| 6320 | PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6321 | goto failed; |
| 6322 | } |
| 6323 | len = PyList_GET_SIZE(tmp); |
| 6324 | ifs = asdl_seq_new(len, arena); |
| 6325 | if (ifs == NULL) goto failed; |
| 6326 | for (i = 0; i < len; i++) { |
| 6327 | expr_ty value; |
| 6328 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6329 | if (res != 0) goto failed; |
| 6330 | asdl_seq_SET(ifs, i, value); |
| 6331 | } |
| 6332 | Py_XDECREF(tmp); |
| 6333 | tmp = NULL; |
| 6334 | } else { |
| 6335 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 6336 | return 1; |
| 6337 | } |
| 6338 | *out = comprehension(target, iter, ifs, arena); |
| 6339 | return 0; |
| 6340 | failed: |
| 6341 | Py_XDECREF(tmp); |
| 6342 | return 1; |
| 6343 | } |
| 6344 | |
| 6345 | int |
| 6346 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 6347 | { |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6348 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6349 | |
Benjamin Peterson | 787cddc | 2010-11-20 04:37:00 +0000 | [diff] [blame] | 6350 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6351 | int lineno; |
| 6352 | int col_offset; |
| 6353 | |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6354 | if (obj == Py_None) { |
| 6355 | *out = NULL; |
| 6356 | return 0; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6357 | } |
| 6358 | if (PyObject_HasAttrString(obj, "lineno")) { |
| 6359 | int res; |
| 6360 | tmp = PyObject_GetAttrString(obj, "lineno"); |
| 6361 | if (tmp == NULL) goto failed; |
| 6362 | res = obj2ast_int(tmp, &lineno, arena); |
| 6363 | if (res != 0) goto failed; |
| 6364 | Py_XDECREF(tmp); |
| 6365 | tmp = NULL; |
| 6366 | } else { |
| 6367 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 6368 | return 1; |
| 6369 | } |
| 6370 | if (PyObject_HasAttrString(obj, "col_offset")) { |
| 6371 | int res; |
| 6372 | tmp = PyObject_GetAttrString(obj, "col_offset"); |
| 6373 | if (tmp == NULL) goto failed; |
| 6374 | res = obj2ast_int(tmp, &col_offset, arena); |
| 6375 | if (res != 0) goto failed; |
| 6376 | Py_XDECREF(tmp); |
| 6377 | tmp = NULL; |
| 6378 | } else { |
| 6379 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 6380 | return 1; |
| 6381 | } |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6382 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type); |
| 6383 | if (isinstance == -1) { |
| 6384 | return 1; |
| 6385 | } |
| 6386 | if (isinstance) { |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6387 | expr_ty type; |
| 6388 | identifier name; |
| 6389 | asdl_seq* body; |
| 6390 | |
| 6391 | if (PyObject_HasAttrString(obj, "type")) { |
| 6392 | int res; |
| 6393 | tmp = PyObject_GetAttrString(obj, "type"); |
| 6394 | if (tmp == NULL) goto failed; |
| 6395 | res = obj2ast_expr(tmp, &type, arena); |
| 6396 | if (res != 0) goto failed; |
| 6397 | Py_XDECREF(tmp); |
| 6398 | tmp = NULL; |
| 6399 | } else { |
| 6400 | type = NULL; |
| 6401 | } |
| 6402 | if (PyObject_HasAttrString(obj, "name")) { |
| 6403 | int res; |
| 6404 | tmp = PyObject_GetAttrString(obj, "name"); |
| 6405 | if (tmp == NULL) goto failed; |
| 6406 | res = obj2ast_identifier(tmp, &name, arena); |
| 6407 | if (res != 0) goto failed; |
| 6408 | Py_XDECREF(tmp); |
| 6409 | tmp = NULL; |
| 6410 | } else { |
| 6411 | name = NULL; |
| 6412 | } |
| 6413 | if (PyObject_HasAttrString(obj, "body")) { |
| 6414 | int res; |
| 6415 | Py_ssize_t len; |
| 6416 | Py_ssize_t i; |
| 6417 | tmp = PyObject_GetAttrString(obj, "body"); |
| 6418 | if (tmp == NULL) goto failed; |
| 6419 | if (!PyList_Check(tmp)) { |
| 6420 | PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6421 | goto failed; |
| 6422 | } |
| 6423 | len = PyList_GET_SIZE(tmp); |
| 6424 | body = asdl_seq_new(len, arena); |
| 6425 | if (body == NULL) goto failed; |
| 6426 | for (i = 0; i < len; i++) { |
| 6427 | stmt_ty value; |
| 6428 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6429 | if (res != 0) goto failed; |
| 6430 | asdl_seq_SET(body, i, value); |
| 6431 | } |
| 6432 | Py_XDECREF(tmp); |
| 6433 | tmp = NULL; |
| 6434 | } else { |
| 6435 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 6436 | return 1; |
| 6437 | } |
| 6438 | *out = ExceptHandler(type, name, body, lineno, col_offset, |
| 6439 | arena); |
| 6440 | if (*out == NULL) goto failed; |
| 6441 | return 0; |
| 6442 | } |
| 6443 | |
Benjamin Peterson | aab9585 | 2010-11-20 01:48:38 +0000 | [diff] [blame] | 6444 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
| 6445 | failed: |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6446 | return 1; |
| 6447 | } |
| 6448 | |
| 6449 | int |
| 6450 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 6451 | { |
| 6452 | PyObject* tmp = NULL; |
| 6453 | asdl_seq* args; |
| 6454 | identifier vararg; |
| 6455 | expr_ty varargannotation; |
| 6456 | asdl_seq* kwonlyargs; |
| 6457 | identifier kwarg; |
| 6458 | expr_ty kwargannotation; |
| 6459 | asdl_seq* defaults; |
| 6460 | asdl_seq* kw_defaults; |
| 6461 | |
| 6462 | if (PyObject_HasAttrString(obj, "args")) { |
| 6463 | int res; |
| 6464 | Py_ssize_t len; |
| 6465 | Py_ssize_t i; |
| 6466 | tmp = PyObject_GetAttrString(obj, "args"); |
| 6467 | if (tmp == NULL) goto failed; |
| 6468 | if (!PyList_Check(tmp)) { |
| 6469 | PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6470 | goto failed; |
| 6471 | } |
| 6472 | len = PyList_GET_SIZE(tmp); |
| 6473 | args = asdl_seq_new(len, arena); |
| 6474 | if (args == NULL) goto failed; |
| 6475 | for (i = 0; i < len; i++) { |
| 6476 | arg_ty value; |
| 6477 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6478 | if (res != 0) goto failed; |
| 6479 | asdl_seq_SET(args, i, value); |
| 6480 | } |
| 6481 | Py_XDECREF(tmp); |
| 6482 | tmp = NULL; |
| 6483 | } else { |
| 6484 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 6485 | return 1; |
| 6486 | } |
| 6487 | if (PyObject_HasAttrString(obj, "vararg")) { |
| 6488 | int res; |
| 6489 | tmp = PyObject_GetAttrString(obj, "vararg"); |
| 6490 | if (tmp == NULL) goto failed; |
| 6491 | res = obj2ast_identifier(tmp, &vararg, arena); |
| 6492 | if (res != 0) goto failed; |
| 6493 | Py_XDECREF(tmp); |
| 6494 | tmp = NULL; |
| 6495 | } else { |
| 6496 | vararg = NULL; |
| 6497 | } |
| 6498 | if (PyObject_HasAttrString(obj, "varargannotation")) { |
| 6499 | int res; |
| 6500 | tmp = PyObject_GetAttrString(obj, "varargannotation"); |
| 6501 | if (tmp == NULL) goto failed; |
| 6502 | res = obj2ast_expr(tmp, &varargannotation, arena); |
| 6503 | if (res != 0) goto failed; |
| 6504 | Py_XDECREF(tmp); |
| 6505 | tmp = NULL; |
| 6506 | } else { |
| 6507 | varargannotation = NULL; |
| 6508 | } |
| 6509 | if (PyObject_HasAttrString(obj, "kwonlyargs")) { |
| 6510 | int res; |
| 6511 | Py_ssize_t len; |
| 6512 | Py_ssize_t i; |
| 6513 | tmp = PyObject_GetAttrString(obj, "kwonlyargs"); |
| 6514 | if (tmp == NULL) goto failed; |
| 6515 | if (!PyList_Check(tmp)) { |
| 6516 | PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6517 | goto failed; |
| 6518 | } |
| 6519 | len = PyList_GET_SIZE(tmp); |
| 6520 | kwonlyargs = asdl_seq_new(len, arena); |
| 6521 | if (kwonlyargs == NULL) goto failed; |
| 6522 | for (i = 0; i < len; i++) { |
| 6523 | arg_ty value; |
| 6524 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6525 | if (res != 0) goto failed; |
| 6526 | asdl_seq_SET(kwonlyargs, i, value); |
| 6527 | } |
| 6528 | Py_XDECREF(tmp); |
| 6529 | tmp = NULL; |
| 6530 | } else { |
| 6531 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 6532 | return 1; |
| 6533 | } |
| 6534 | if (PyObject_HasAttrString(obj, "kwarg")) { |
| 6535 | int res; |
| 6536 | tmp = PyObject_GetAttrString(obj, "kwarg"); |
| 6537 | if (tmp == NULL) goto failed; |
| 6538 | res = obj2ast_identifier(tmp, &kwarg, arena); |
| 6539 | if (res != 0) goto failed; |
| 6540 | Py_XDECREF(tmp); |
| 6541 | tmp = NULL; |
| 6542 | } else { |
| 6543 | kwarg = NULL; |
| 6544 | } |
| 6545 | if (PyObject_HasAttrString(obj, "kwargannotation")) { |
| 6546 | int res; |
| 6547 | tmp = PyObject_GetAttrString(obj, "kwargannotation"); |
| 6548 | if (tmp == NULL) goto failed; |
| 6549 | res = obj2ast_expr(tmp, &kwargannotation, arena); |
| 6550 | if (res != 0) goto failed; |
| 6551 | Py_XDECREF(tmp); |
| 6552 | tmp = NULL; |
| 6553 | } else { |
| 6554 | kwargannotation = NULL; |
| 6555 | } |
| 6556 | if (PyObject_HasAttrString(obj, "defaults")) { |
| 6557 | int res; |
| 6558 | Py_ssize_t len; |
| 6559 | Py_ssize_t i; |
| 6560 | tmp = PyObject_GetAttrString(obj, "defaults"); |
| 6561 | if (tmp == NULL) goto failed; |
| 6562 | if (!PyList_Check(tmp)) { |
| 6563 | PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6564 | goto failed; |
| 6565 | } |
| 6566 | len = PyList_GET_SIZE(tmp); |
| 6567 | defaults = asdl_seq_new(len, arena); |
| 6568 | if (defaults == NULL) goto failed; |
| 6569 | for (i = 0; i < len; i++) { |
| 6570 | expr_ty value; |
| 6571 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6572 | if (res != 0) goto failed; |
| 6573 | asdl_seq_SET(defaults, i, value); |
| 6574 | } |
| 6575 | Py_XDECREF(tmp); |
| 6576 | tmp = NULL; |
| 6577 | } else { |
| 6578 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 6579 | return 1; |
| 6580 | } |
| 6581 | if (PyObject_HasAttrString(obj, "kw_defaults")) { |
| 6582 | int res; |
| 6583 | Py_ssize_t len; |
| 6584 | Py_ssize_t i; |
| 6585 | tmp = PyObject_GetAttrString(obj, "kw_defaults"); |
| 6586 | if (tmp == NULL) goto failed; |
| 6587 | if (!PyList_Check(tmp)) { |
| 6588 | PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6589 | goto failed; |
| 6590 | } |
| 6591 | len = PyList_GET_SIZE(tmp); |
| 6592 | kw_defaults = asdl_seq_new(len, arena); |
| 6593 | if (kw_defaults == NULL) goto failed; |
| 6594 | for (i = 0; i < len; i++) { |
| 6595 | expr_ty value; |
| 6596 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6597 | if (res != 0) goto failed; |
| 6598 | asdl_seq_SET(kw_defaults, i, value); |
| 6599 | } |
| 6600 | Py_XDECREF(tmp); |
| 6601 | tmp = NULL; |
| 6602 | } else { |
| 6603 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 6604 | return 1; |
| 6605 | } |
| 6606 | *out = arguments(args, vararg, varargannotation, kwonlyargs, kwarg, |
| 6607 | kwargannotation, defaults, kw_defaults, arena); |
| 6608 | return 0; |
| 6609 | failed: |
| 6610 | Py_XDECREF(tmp); |
| 6611 | return 1; |
| 6612 | } |
| 6613 | |
| 6614 | int |
| 6615 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 6616 | { |
| 6617 | PyObject* tmp = NULL; |
| 6618 | identifier arg; |
| 6619 | expr_ty annotation; |
| 6620 | |
| 6621 | if (PyObject_HasAttrString(obj, "arg")) { |
| 6622 | int res; |
| 6623 | tmp = PyObject_GetAttrString(obj, "arg"); |
| 6624 | if (tmp == NULL) goto failed; |
| 6625 | res = obj2ast_identifier(tmp, &arg, arena); |
| 6626 | if (res != 0) goto failed; |
| 6627 | Py_XDECREF(tmp); |
| 6628 | tmp = NULL; |
| 6629 | } else { |
| 6630 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
| 6631 | return 1; |
| 6632 | } |
| 6633 | if (PyObject_HasAttrString(obj, "annotation")) { |
| 6634 | int res; |
| 6635 | tmp = PyObject_GetAttrString(obj, "annotation"); |
| 6636 | if (tmp == NULL) goto failed; |
| 6637 | res = obj2ast_expr(tmp, &annotation, arena); |
| 6638 | if (res != 0) goto failed; |
| 6639 | Py_XDECREF(tmp); |
| 6640 | tmp = NULL; |
| 6641 | } else { |
| 6642 | annotation = NULL; |
| 6643 | } |
| 6644 | *out = arg(arg, annotation, arena); |
| 6645 | return 0; |
| 6646 | failed: |
| 6647 | Py_XDECREF(tmp); |
| 6648 | return 1; |
| 6649 | } |
| 6650 | |
| 6651 | int |
| 6652 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 6653 | { |
| 6654 | PyObject* tmp = NULL; |
| 6655 | identifier arg; |
| 6656 | expr_ty value; |
| 6657 | |
| 6658 | if (PyObject_HasAttrString(obj, "arg")) { |
| 6659 | int res; |
| 6660 | tmp = PyObject_GetAttrString(obj, "arg"); |
| 6661 | if (tmp == NULL) goto failed; |
| 6662 | res = obj2ast_identifier(tmp, &arg, arena); |
| 6663 | if (res != 0) goto failed; |
| 6664 | Py_XDECREF(tmp); |
| 6665 | tmp = NULL; |
| 6666 | } else { |
| 6667 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from keyword"); |
| 6668 | return 1; |
| 6669 | } |
| 6670 | if (PyObject_HasAttrString(obj, "value")) { |
| 6671 | int res; |
| 6672 | tmp = PyObject_GetAttrString(obj, "value"); |
| 6673 | if (tmp == NULL) goto failed; |
| 6674 | res = obj2ast_expr(tmp, &value, arena); |
| 6675 | if (res != 0) goto failed; |
| 6676 | Py_XDECREF(tmp); |
| 6677 | tmp = NULL; |
| 6678 | } else { |
| 6679 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 6680 | return 1; |
| 6681 | } |
| 6682 | *out = keyword(arg, value, arena); |
| 6683 | return 0; |
| 6684 | failed: |
| 6685 | Py_XDECREF(tmp); |
| 6686 | return 1; |
| 6687 | } |
| 6688 | |
| 6689 | int |
| 6690 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 6691 | { |
| 6692 | PyObject* tmp = NULL; |
| 6693 | identifier name; |
| 6694 | identifier asname; |
| 6695 | |
| 6696 | if (PyObject_HasAttrString(obj, "name")) { |
| 6697 | int res; |
| 6698 | tmp = PyObject_GetAttrString(obj, "name"); |
| 6699 | if (tmp == NULL) goto failed; |
| 6700 | res = obj2ast_identifier(tmp, &name, arena); |
| 6701 | if (res != 0) goto failed; |
| 6702 | Py_XDECREF(tmp); |
| 6703 | tmp = NULL; |
| 6704 | } else { |
| 6705 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 6706 | return 1; |
| 6707 | } |
| 6708 | if (PyObject_HasAttrString(obj, "asname")) { |
| 6709 | int res; |
| 6710 | tmp = PyObject_GetAttrString(obj, "asname"); |
| 6711 | if (tmp == NULL) goto failed; |
| 6712 | res = obj2ast_identifier(tmp, &asname, arena); |
| 6713 | if (res != 0) goto failed; |
| 6714 | Py_XDECREF(tmp); |
| 6715 | tmp = NULL; |
| 6716 | } else { |
| 6717 | asname = NULL; |
| 6718 | } |
| 6719 | *out = alias(name, asname, arena); |
| 6720 | return 0; |
| 6721 | failed: |
| 6722 | Py_XDECREF(tmp); |
| 6723 | return 1; |
| 6724 | } |
| 6725 | |
| 6726 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6727 | static struct PyModuleDef _astmodule = { |
| 6728 | PyModuleDef_HEAD_INIT, "_ast" |
| 6729 | }; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6730 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6731 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6732 | { |
| 6733 | PyObject *m, *d; |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6734 | if (!init_types()) return NULL; |
| 6735 | m = PyModule_Create(&_astmodule); |
| 6736 | if (!m) return NULL; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6737 | d = PyModule_GetDict(m); |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6738 | if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return |
| 6739 | NULL; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6740 | 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] | 6741 | return NULL; |
Benjamin Peterson | e6d4a9b | 2008-12-06 18:33:20 +0000 | [diff] [blame] | 6742 | if (PyModule_AddStringConstant(m, "__version__", "67616") < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6743 | return NULL; |
| 6744 | if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return |
| 6745 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6746 | if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6747 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6748 | if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6749 | < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6750 | if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6751 | 0) return NULL; |
| 6752 | if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return |
| 6753 | NULL; |
| 6754 | if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return |
| 6755 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6756 | if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6757 | < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6758 | if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6759 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6760 | if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6761 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6762 | if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6763 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6764 | if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6765 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6766 | if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6767 | 0) return NULL; |
| 6768 | if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return |
| 6769 | NULL; |
| 6770 | if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return |
| 6771 | NULL; |
| 6772 | if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return NULL; |
| 6773 | if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return |
| 6774 | NULL; |
| 6775 | if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return |
| 6776 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6777 | if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6778 | 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6779 | if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6780 | 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6781 | if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6782 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6783 | if (PyDict_SetItemString(d, "Import", (PyObject*)Import_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, "ImportFrom", (PyObject*)ImportFrom_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6786 | 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6787 | if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6788 | return NULL; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 6789 | if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6790 | return NULL; |
| 6791 | if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return |
| 6792 | NULL; |
| 6793 | if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return |
| 6794 | NULL; |
| 6795 | if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return |
| 6796 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6797 | if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6798 | return NULL; |
| 6799 | if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return |
| 6800 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6801 | if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6802 | return NULL; |
| 6803 | if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return |
| 6804 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6805 | if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6806 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6807 | if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6808 | return NULL; |
| 6809 | if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return |
| 6810 | NULL; |
| 6811 | if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return |
| 6812 | NULL; |
| 6813 | if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return |
| 6814 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6815 | if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6816 | return NULL; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 6817 | if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6818 | return NULL; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 6819 | if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6820 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6821 | if (PyDict_SetItemString(d, "GeneratorExp", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6822 | (PyObject*)GeneratorExp_type) < 0) return NULL; |
| 6823 | if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return |
| 6824 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6825 | if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6826 | return NULL; |
| 6827 | if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return |
| 6828 | NULL; |
| 6829 | if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return |
| 6830 | NULL; |
| 6831 | if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return |
| 6832 | NULL; |
| 6833 | if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return |
| 6834 | NULL; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 6835 | if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6836 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6837 | if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6838 | 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6839 | if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6840 | 0) return NULL; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 6841 | if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6842 | return NULL; |
| 6843 | if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return |
| 6844 | NULL; |
| 6845 | if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return |
| 6846 | NULL; |
| 6847 | if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return |
| 6848 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6849 | if (PyDict_SetItemString(d, "expr_context", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6850 | (PyObject*)expr_context_type) < 0) return NULL; |
| 6851 | if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return |
| 6852 | NULL; |
| 6853 | if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return |
| 6854 | NULL; |
| 6855 | if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return |
| 6856 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6857 | if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6858 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6859 | if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6860 | return NULL; |
| 6861 | if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return |
| 6862 | NULL; |
| 6863 | if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return |
| 6864 | NULL; |
| 6865 | if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return |
| 6866 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6867 | if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6868 | return NULL; |
| 6869 | if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return |
| 6870 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6871 | if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6872 | return NULL; |
| 6873 | if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return |
| 6874 | NULL; |
| 6875 | if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6876 | if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6877 | return NULL; |
| 6878 | if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return |
| 6879 | NULL; |
| 6880 | if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return |
| 6881 | NULL; |
| 6882 | if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return |
| 6883 | NULL; |
| 6884 | if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return |
| 6885 | NULL; |
| 6886 | if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return |
| 6887 | NULL; |
| 6888 | if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return |
| 6889 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6890 | if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6891 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6892 | if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6893 | return NULL; |
| 6894 | if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return |
| 6895 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6896 | if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6897 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6898 | if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6899 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6900 | if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6901 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6902 | if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6903 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6904 | if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6905 | return NULL; |
| 6906 | if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return |
| 6907 | NULL; |
| 6908 | if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return |
| 6909 | NULL; |
| 6910 | if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return |
| 6911 | NULL; |
| 6912 | if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return |
| 6913 | NULL; |
| 6914 | if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return NULL; |
| 6915 | if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return |
| 6916 | NULL; |
| 6917 | if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return NULL; |
| 6918 | if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return |
| 6919 | NULL; |
| 6920 | if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return NULL; |
| 6921 | if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return |
| 6922 | NULL; |
| 6923 | if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return NULL; |
| 6924 | if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return |
| 6925 | NULL; |
| 6926 | if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return NULL; |
| 6927 | if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return |
| 6928 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6929 | if (PyDict_SetItemString(d, "comprehension", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6930 | (PyObject*)comprehension_type) < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6931 | if (PyDict_SetItemString(d, "excepthandler", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6932 | (PyObject*)excepthandler_type) < 0) return NULL; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6933 | if (PyDict_SetItemString(d, "ExceptHandler", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6934 | (PyObject*)ExceptHandler_type) < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6935 | if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6936 | 0) return NULL; |
| 6937 | if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return |
| 6938 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6939 | if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6940 | return NULL; |
| 6941 | if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return |
| 6942 | NULL; |
| 6943 | return m; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6944 | } |
| 6945 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 6946 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 6947 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 6948 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 6949 | init_types(); |
| 6950 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 6951 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 6952 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 6953 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 6954 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6955 | { |
| 6956 | mod_ty res; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 6957 | PyObject *req_type[] = {(PyObject*)Module_type, (PyObject*)Expression_type, |
| 6958 | (PyObject*)Interactive_type}; |
| 6959 | char *req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6960 | int isinstance; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 6961 | assert(0 <= mode && mode <= 2); |
| 6962 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6963 | init_types(); |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 6964 | |
Benjamin Peterson | fc43127 | 2009-12-13 01:29:00 +0000 | [diff] [blame] | 6965 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 6966 | if (isinstance == -1) |
| 6967 | return NULL; |
| 6968 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 6969 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
| 6970 | req_name[mode], Py_TYPE(ast)->tp_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6971 | return NULL; |
| 6972 | } |
| 6973 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 6974 | return NULL; |
| 6975 | else |
| 6976 | return res; |
| 6977 | } |
| 6978 | |
| 6979 | int PyAST_Check(PyObject* obj) |
| 6980 | { |
| 6981 | init_types(); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 6982 | return PyObject_IsInstance(obj, (PyObject*)&AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6983 | } |
| 6984 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 6985 | |