Thomas Wouters | cf297e4 | 2007-02-23 15:07:44 +0000 | [diff] [blame] | 1 | /* File automatically generated by Parser/asdl_c.py. */ |
| 2 | |
| 3 | |
| 4 | /* |
Alexander Belopolsky | 1b7046b | 2010-06-23 21:40:15 +0000 | [diff] [blame^] | 5 | __version__ 82163. |
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 | } |
Victor Stinner | 7eeb5b5 | 2010-06-07 19:57:46 +0000 | [diff] [blame] | 530 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(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; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1335 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1336 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1337 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1338 | p->kind = ImportFrom_kind; |
| 1339 | p->v.ImportFrom.module = module; |
| 1340 | p->v.ImportFrom.names = names; |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 1341 | p->v.ImportFrom.level = level; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1342 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1343 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1344 | return p; |
| 1345 | } |
| 1346 | |
| 1347 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1348 | Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1349 | { |
| 1350 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1351 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1352 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1353 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1354 | p->kind = Global_kind; |
| 1355 | p->v.Global.names = names; |
| 1356 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1357 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1358 | return p; |
| 1359 | } |
| 1360 | |
| 1361 | stmt_ty |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 1362 | Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
| 1363 | { |
| 1364 | stmt_ty p; |
| 1365 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1366 | if (!p) |
| 1367 | return NULL; |
| 1368 | p->kind = Nonlocal_kind; |
| 1369 | p->v.Nonlocal.names = names; |
| 1370 | p->lineno = lineno; |
| 1371 | p->col_offset = col_offset; |
| 1372 | return p; |
| 1373 | } |
| 1374 | |
| 1375 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1376 | Expr(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1377 | { |
| 1378 | stmt_ty p; |
| 1379 | if (!value) { |
| 1380 | PyErr_SetString(PyExc_ValueError, |
| 1381 | "field value is required for Expr"); |
| 1382 | return NULL; |
| 1383 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1384 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1385 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1386 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1387 | p->kind = Expr_kind; |
| 1388 | p->v.Expr.value = value; |
| 1389 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1390 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1391 | return p; |
| 1392 | } |
| 1393 | |
| 1394 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1395 | Pass(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1396 | { |
| 1397 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1398 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1399 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1400 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1401 | p->kind = Pass_kind; |
| 1402 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1403 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1404 | return p; |
| 1405 | } |
| 1406 | |
| 1407 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1408 | Break(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1409 | { |
| 1410 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1411 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1412 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1413 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1414 | p->kind = Break_kind; |
| 1415 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1416 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1417 | return p; |
| 1418 | } |
| 1419 | |
| 1420 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1421 | Continue(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1422 | { |
| 1423 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1424 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1425 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1426 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1427 | p->kind = Continue_kind; |
| 1428 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1429 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1430 | return p; |
| 1431 | } |
| 1432 | |
| 1433 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1434 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1435 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1436 | { |
| 1437 | expr_ty p; |
| 1438 | if (!op) { |
| 1439 | PyErr_SetString(PyExc_ValueError, |
| 1440 | "field op is required for BoolOp"); |
| 1441 | return NULL; |
| 1442 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1443 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1444 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1445 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1446 | p->kind = BoolOp_kind; |
| 1447 | p->v.BoolOp.op = op; |
| 1448 | p->v.BoolOp.values = values; |
| 1449 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1450 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1451 | return p; |
| 1452 | } |
| 1453 | |
| 1454 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1455 | BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset, |
| 1456 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1457 | { |
| 1458 | expr_ty p; |
| 1459 | if (!left) { |
| 1460 | PyErr_SetString(PyExc_ValueError, |
| 1461 | "field left is required for BinOp"); |
| 1462 | return NULL; |
| 1463 | } |
| 1464 | if (!op) { |
| 1465 | PyErr_SetString(PyExc_ValueError, |
| 1466 | "field op is required for BinOp"); |
| 1467 | return NULL; |
| 1468 | } |
| 1469 | if (!right) { |
| 1470 | PyErr_SetString(PyExc_ValueError, |
| 1471 | "field right is required for BinOp"); |
| 1472 | return NULL; |
| 1473 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1474 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1475 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1476 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1477 | p->kind = BinOp_kind; |
| 1478 | p->v.BinOp.left = left; |
| 1479 | p->v.BinOp.op = op; |
| 1480 | p->v.BinOp.right = right; |
| 1481 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1482 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1483 | return p; |
| 1484 | } |
| 1485 | |
| 1486 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1487 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena |
| 1488 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1489 | { |
| 1490 | expr_ty p; |
| 1491 | if (!op) { |
| 1492 | PyErr_SetString(PyExc_ValueError, |
| 1493 | "field op is required for UnaryOp"); |
| 1494 | return NULL; |
| 1495 | } |
| 1496 | if (!operand) { |
| 1497 | PyErr_SetString(PyExc_ValueError, |
| 1498 | "field operand is required for UnaryOp"); |
| 1499 | return NULL; |
| 1500 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1501 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1502 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1503 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1504 | p->kind = UnaryOp_kind; |
| 1505 | p->v.UnaryOp.op = op; |
| 1506 | p->v.UnaryOp.operand = operand; |
| 1507 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1508 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1509 | return p; |
| 1510 | } |
| 1511 | |
| 1512 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1513 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena |
| 1514 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1515 | { |
| 1516 | expr_ty p; |
| 1517 | if (!args) { |
| 1518 | PyErr_SetString(PyExc_ValueError, |
| 1519 | "field args is required for Lambda"); |
| 1520 | return NULL; |
| 1521 | } |
| 1522 | if (!body) { |
| 1523 | PyErr_SetString(PyExc_ValueError, |
| 1524 | "field body is required for Lambda"); |
| 1525 | return NULL; |
| 1526 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1527 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1528 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1529 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1530 | p->kind = Lambda_kind; |
| 1531 | p->v.Lambda.args = args; |
| 1532 | p->v.Lambda.body = body; |
| 1533 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1534 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1535 | return p; |
| 1536 | } |
| 1537 | |
| 1538 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1539 | IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset, |
| 1540 | PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1541 | { |
| 1542 | expr_ty p; |
| 1543 | if (!test) { |
| 1544 | PyErr_SetString(PyExc_ValueError, |
| 1545 | "field test is required for IfExp"); |
| 1546 | return NULL; |
| 1547 | } |
| 1548 | if (!body) { |
| 1549 | PyErr_SetString(PyExc_ValueError, |
| 1550 | "field body is required for IfExp"); |
| 1551 | return NULL; |
| 1552 | } |
| 1553 | if (!orelse) { |
| 1554 | PyErr_SetString(PyExc_ValueError, |
| 1555 | "field orelse is required for IfExp"); |
| 1556 | return NULL; |
| 1557 | } |
| 1558 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1559 | if (!p) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1560 | return NULL; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1561 | p->kind = IfExp_kind; |
| 1562 | p->v.IfExp.test = test; |
| 1563 | p->v.IfExp.body = body; |
| 1564 | p->v.IfExp.orelse = orelse; |
| 1565 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1566 | p->col_offset = col_offset; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1567 | return p; |
| 1568 | } |
| 1569 | |
| 1570 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1571 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1572 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1573 | { |
| 1574 | expr_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1575 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1576 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1577 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1578 | p->kind = Dict_kind; |
| 1579 | p->v.Dict.keys = keys; |
| 1580 | p->v.Dict.values = values; |
| 1581 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1582 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1583 | return p; |
| 1584 | } |
| 1585 | |
| 1586 | expr_ty |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1587 | Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena) |
| 1588 | { |
| 1589 | expr_ty p; |
| 1590 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1591 | if (!p) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1592 | return NULL; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1593 | p->kind = Set_kind; |
| 1594 | p->v.Set.elts = elts; |
| 1595 | p->lineno = lineno; |
| 1596 | p->col_offset = col_offset; |
| 1597 | return p; |
| 1598 | } |
| 1599 | |
| 1600 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1601 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1602 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1603 | { |
| 1604 | expr_ty p; |
| 1605 | if (!elt) { |
| 1606 | PyErr_SetString(PyExc_ValueError, |
| 1607 | "field elt is required for ListComp"); |
| 1608 | return NULL; |
| 1609 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1610 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1611 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1612 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1613 | p->kind = ListComp_kind; |
| 1614 | p->v.ListComp.elt = elt; |
| 1615 | p->v.ListComp.generators = generators; |
| 1616 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1617 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1618 | return p; |
| 1619 | } |
| 1620 | |
| 1621 | expr_ty |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 1622 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena |
| 1623 | *arena) |
| 1624 | { |
| 1625 | expr_ty p; |
| 1626 | if (!elt) { |
| 1627 | PyErr_SetString(PyExc_ValueError, |
| 1628 | "field elt is required for SetComp"); |
| 1629 | return NULL; |
| 1630 | } |
| 1631 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1632 | if (!p) |
| 1633 | return NULL; |
| 1634 | p->kind = SetComp_kind; |
| 1635 | p->v.SetComp.elt = elt; |
| 1636 | p->v.SetComp.generators = generators; |
| 1637 | p->lineno = lineno; |
| 1638 | p->col_offset = col_offset; |
| 1639 | return p; |
| 1640 | } |
| 1641 | |
| 1642 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 1643 | DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int |
| 1644 | col_offset, PyArena *arena) |
| 1645 | { |
| 1646 | expr_ty p; |
| 1647 | if (!key) { |
| 1648 | PyErr_SetString(PyExc_ValueError, |
| 1649 | "field key is required for DictComp"); |
| 1650 | return NULL; |
| 1651 | } |
| 1652 | if (!value) { |
| 1653 | PyErr_SetString(PyExc_ValueError, |
| 1654 | "field value is required for DictComp"); |
| 1655 | return NULL; |
| 1656 | } |
| 1657 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1658 | if (!p) |
| 1659 | return NULL; |
| 1660 | p->kind = DictComp_kind; |
| 1661 | p->v.DictComp.key = key; |
| 1662 | p->v.DictComp.value = value; |
| 1663 | p->v.DictComp.generators = generators; |
| 1664 | p->lineno = lineno; |
| 1665 | p->col_offset = col_offset; |
| 1666 | return p; |
| 1667 | } |
| 1668 | |
| 1669 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1670 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1671 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1672 | { |
| 1673 | expr_ty p; |
| 1674 | if (!elt) { |
| 1675 | PyErr_SetString(PyExc_ValueError, |
| 1676 | "field elt is required for GeneratorExp"); |
| 1677 | return NULL; |
| 1678 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1679 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1680 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1681 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1682 | p->kind = GeneratorExp_kind; |
| 1683 | p->v.GeneratorExp.elt = elt; |
| 1684 | p->v.GeneratorExp.generators = generators; |
| 1685 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1686 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1687 | return p; |
| 1688 | } |
| 1689 | |
| 1690 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1691 | Yield(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1692 | { |
| 1693 | expr_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1694 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1695 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1696 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1697 | p->kind = Yield_kind; |
| 1698 | p->v.Yield.value = value; |
| 1699 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1700 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1701 | return p; |
| 1702 | } |
| 1703 | |
| 1704 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1705 | Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno, |
| 1706 | int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1707 | { |
| 1708 | expr_ty p; |
| 1709 | if (!left) { |
| 1710 | PyErr_SetString(PyExc_ValueError, |
| 1711 | "field left is required for Compare"); |
| 1712 | return NULL; |
| 1713 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1714 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1715 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1716 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1717 | p->kind = Compare_kind; |
| 1718 | p->v.Compare.left = left; |
| 1719 | p->v.Compare.ops = ops; |
| 1720 | p->v.Compare.comparators = comparators; |
| 1721 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1722 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1723 | return p; |
| 1724 | } |
| 1725 | |
| 1726 | expr_ty |
| 1727 | 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] | 1728 | expr_ty kwargs, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1729 | { |
| 1730 | expr_ty p; |
| 1731 | if (!func) { |
| 1732 | PyErr_SetString(PyExc_ValueError, |
| 1733 | "field func is required for Call"); |
| 1734 | return NULL; |
| 1735 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1736 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1737 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1738 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1739 | p->kind = Call_kind; |
| 1740 | p->v.Call.func = func; |
| 1741 | p->v.Call.args = args; |
| 1742 | p->v.Call.keywords = keywords; |
| 1743 | p->v.Call.starargs = starargs; |
| 1744 | p->v.Call.kwargs = kwargs; |
| 1745 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1746 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1747 | return p; |
| 1748 | } |
| 1749 | |
| 1750 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1751 | Num(object n, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1752 | { |
| 1753 | expr_ty p; |
| 1754 | if (!n) { |
| 1755 | PyErr_SetString(PyExc_ValueError, |
| 1756 | "field n is required for Num"); |
| 1757 | return NULL; |
| 1758 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1759 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1760 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1761 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1762 | p->kind = Num_kind; |
| 1763 | p->v.Num.n = n; |
| 1764 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1765 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1766 | return p; |
| 1767 | } |
| 1768 | |
| 1769 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1770 | Str(string s, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1771 | { |
| 1772 | expr_ty p; |
| 1773 | if (!s) { |
| 1774 | PyErr_SetString(PyExc_ValueError, |
| 1775 | "field s is required for Str"); |
| 1776 | return NULL; |
| 1777 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1778 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1779 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1780 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1781 | p->kind = Str_kind; |
| 1782 | p->v.Str.s = s; |
| 1783 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1784 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1785 | return p; |
| 1786 | } |
| 1787 | |
| 1788 | expr_ty |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1789 | Bytes(string s, int lineno, int col_offset, PyArena *arena) |
| 1790 | { |
| 1791 | expr_ty p; |
| 1792 | if (!s) { |
| 1793 | PyErr_SetString(PyExc_ValueError, |
| 1794 | "field s is required for Bytes"); |
| 1795 | return NULL; |
| 1796 | } |
| 1797 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1798 | if (!p) |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1799 | return NULL; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1800 | p->kind = Bytes_kind; |
| 1801 | p->v.Bytes.s = s; |
| 1802 | p->lineno = lineno; |
| 1803 | p->col_offset = col_offset; |
| 1804 | return p; |
| 1805 | } |
| 1806 | |
| 1807 | expr_ty |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1808 | Ellipsis(int lineno, int col_offset, PyArena *arena) |
| 1809 | { |
| 1810 | expr_ty p; |
| 1811 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1812 | if (!p) |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1813 | return NULL; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1814 | p->kind = Ellipsis_kind; |
| 1815 | p->lineno = lineno; |
| 1816 | p->col_offset = col_offset; |
| 1817 | return p; |
| 1818 | } |
| 1819 | |
| 1820 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1821 | Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int |
| 1822 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1823 | { |
| 1824 | expr_ty p; |
| 1825 | if (!value) { |
| 1826 | PyErr_SetString(PyExc_ValueError, |
| 1827 | "field value is required for Attribute"); |
| 1828 | return NULL; |
| 1829 | } |
| 1830 | if (!attr) { |
| 1831 | PyErr_SetString(PyExc_ValueError, |
| 1832 | "field attr is required for Attribute"); |
| 1833 | return NULL; |
| 1834 | } |
| 1835 | if (!ctx) { |
| 1836 | PyErr_SetString(PyExc_ValueError, |
| 1837 | "field ctx is required for Attribute"); |
| 1838 | return NULL; |
| 1839 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1840 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1841 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1842 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1843 | p->kind = Attribute_kind; |
| 1844 | p->v.Attribute.value = value; |
| 1845 | p->v.Attribute.attr = attr; |
| 1846 | p->v.Attribute.ctx = ctx; |
| 1847 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1848 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1849 | return p; |
| 1850 | } |
| 1851 | |
| 1852 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1853 | Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int |
| 1854 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1855 | { |
| 1856 | expr_ty p; |
| 1857 | if (!value) { |
| 1858 | PyErr_SetString(PyExc_ValueError, |
| 1859 | "field value is required for Subscript"); |
| 1860 | return NULL; |
| 1861 | } |
| 1862 | if (!slice) { |
| 1863 | PyErr_SetString(PyExc_ValueError, |
| 1864 | "field slice is required for Subscript"); |
| 1865 | return NULL; |
| 1866 | } |
| 1867 | if (!ctx) { |
| 1868 | PyErr_SetString(PyExc_ValueError, |
| 1869 | "field ctx is required for Subscript"); |
| 1870 | return NULL; |
| 1871 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1872 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1873 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1874 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1875 | p->kind = Subscript_kind; |
| 1876 | p->v.Subscript.value = value; |
| 1877 | p->v.Subscript.slice = slice; |
| 1878 | p->v.Subscript.ctx = ctx; |
| 1879 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1880 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1881 | return p; |
| 1882 | } |
| 1883 | |
| 1884 | expr_ty |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 1885 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1886 | *arena) |
| 1887 | { |
| 1888 | expr_ty p; |
| 1889 | if (!value) { |
| 1890 | PyErr_SetString(PyExc_ValueError, |
| 1891 | "field value is required for Starred"); |
| 1892 | return NULL; |
| 1893 | } |
| 1894 | if (!ctx) { |
| 1895 | PyErr_SetString(PyExc_ValueError, |
| 1896 | "field ctx is required for Starred"); |
| 1897 | return NULL; |
| 1898 | } |
| 1899 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1900 | if (!p) |
| 1901 | return NULL; |
| 1902 | p->kind = Starred_kind; |
| 1903 | p->v.Starred.value = value; |
| 1904 | p->v.Starred.ctx = ctx; |
| 1905 | p->lineno = lineno; |
| 1906 | p->col_offset = col_offset; |
| 1907 | return p; |
| 1908 | } |
| 1909 | |
| 1910 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1911 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1912 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1913 | { |
| 1914 | expr_ty p; |
| 1915 | if (!id) { |
| 1916 | PyErr_SetString(PyExc_ValueError, |
| 1917 | "field id is required for Name"); |
| 1918 | return NULL; |
| 1919 | } |
| 1920 | if (!ctx) { |
| 1921 | PyErr_SetString(PyExc_ValueError, |
| 1922 | "field ctx is required for Name"); |
| 1923 | return NULL; |
| 1924 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1925 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1926 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1927 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1928 | p->kind = Name_kind; |
| 1929 | p->v.Name.id = id; |
| 1930 | p->v.Name.ctx = ctx; |
| 1931 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1932 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1933 | return p; |
| 1934 | } |
| 1935 | |
| 1936 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1937 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1938 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1939 | { |
| 1940 | expr_ty p; |
| 1941 | if (!ctx) { |
| 1942 | PyErr_SetString(PyExc_ValueError, |
| 1943 | "field ctx is required for List"); |
| 1944 | return NULL; |
| 1945 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1946 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1947 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1948 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1949 | p->kind = List_kind; |
| 1950 | p->v.List.elts = elts; |
| 1951 | p->v.List.ctx = ctx; |
| 1952 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1953 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1954 | return p; |
| 1955 | } |
| 1956 | |
| 1957 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1958 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1959 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1960 | { |
| 1961 | expr_ty p; |
| 1962 | if (!ctx) { |
| 1963 | PyErr_SetString(PyExc_ValueError, |
| 1964 | "field ctx is required for Tuple"); |
| 1965 | return NULL; |
| 1966 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1967 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1968 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1969 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1970 | p->kind = Tuple_kind; |
| 1971 | p->v.Tuple.elts = elts; |
| 1972 | p->v.Tuple.ctx = ctx; |
| 1973 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1974 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1975 | return p; |
| 1976 | } |
| 1977 | |
| 1978 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1979 | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1980 | { |
| 1981 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1982 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1983 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1984 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1985 | p->kind = Slice_kind; |
| 1986 | p->v.Slice.lower = lower; |
| 1987 | p->v.Slice.upper = upper; |
| 1988 | p->v.Slice.step = step; |
| 1989 | return p; |
| 1990 | } |
| 1991 | |
| 1992 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1993 | ExtSlice(asdl_seq * dims, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1994 | { |
| 1995 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1996 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1997 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1998 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1999 | p->kind = ExtSlice_kind; |
| 2000 | p->v.ExtSlice.dims = dims; |
| 2001 | return p; |
| 2002 | } |
| 2003 | |
| 2004 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2005 | Index(expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2006 | { |
| 2007 | slice_ty p; |
| 2008 | if (!value) { |
| 2009 | PyErr_SetString(PyExc_ValueError, |
| 2010 | "field value is required for Index"); |
| 2011 | return NULL; |
| 2012 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2013 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2014 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2015 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2016 | p->kind = Index_kind; |
| 2017 | p->v.Index.value = value; |
| 2018 | return p; |
| 2019 | } |
| 2020 | |
| 2021 | comprehension_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2022 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2023 | { |
| 2024 | comprehension_ty p; |
| 2025 | if (!target) { |
| 2026 | PyErr_SetString(PyExc_ValueError, |
| 2027 | "field target is required for comprehension"); |
| 2028 | return NULL; |
| 2029 | } |
| 2030 | if (!iter) { |
| 2031 | PyErr_SetString(PyExc_ValueError, |
| 2032 | "field iter is required for comprehension"); |
| 2033 | return NULL; |
| 2034 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2035 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2036 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2037 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2038 | p->target = target; |
| 2039 | p->iter = iter; |
| 2040 | p->ifs = ifs; |
| 2041 | return p; |
| 2042 | } |
| 2043 | |
| 2044 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 2045 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2046 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2047 | { |
| 2048 | excepthandler_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2049 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2050 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2051 | return NULL; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 2052 | p->kind = ExceptHandler_kind; |
| 2053 | p->v.ExceptHandler.type = type; |
| 2054 | p->v.ExceptHandler.name = name; |
| 2055 | p->v.ExceptHandler.body = body; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2056 | p->lineno = lineno; |
| 2057 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2058 | return p; |
| 2059 | } |
| 2060 | |
| 2061 | arguments_ty |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2062 | arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation, |
| 2063 | asdl_seq * kwonlyargs, identifier kwarg, expr_ty kwargannotation, |
| 2064 | asdl_seq * defaults, asdl_seq * kw_defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2065 | { |
| 2066 | arguments_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2067 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2068 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2069 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2070 | p->args = args; |
| 2071 | p->vararg = vararg; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2072 | p->varargannotation = varargannotation; |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 2073 | p->kwonlyargs = kwonlyargs; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2074 | p->kwarg = kwarg; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2075 | p->kwargannotation = kwargannotation; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2076 | p->defaults = defaults; |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 2077 | p->kw_defaults = kw_defaults; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2078 | return p; |
| 2079 | } |
| 2080 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2081 | arg_ty |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2082 | arg(identifier arg, expr_ty annotation, PyArena *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2083 | { |
| 2084 | arg_ty p; |
| 2085 | if (!arg) { |
| 2086 | PyErr_SetString(PyExc_ValueError, |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2087 | "field arg is required for arg"); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2088 | return NULL; |
| 2089 | } |
| 2090 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2091 | if (!p) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2092 | return NULL; |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2093 | p->arg = arg; |
| 2094 | p->annotation = annotation; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2095 | return p; |
| 2096 | } |
| 2097 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2098 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2099 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2100 | { |
| 2101 | keyword_ty p; |
| 2102 | if (!arg) { |
| 2103 | PyErr_SetString(PyExc_ValueError, |
| 2104 | "field arg is required for keyword"); |
| 2105 | return NULL; |
| 2106 | } |
| 2107 | if (!value) { |
| 2108 | PyErr_SetString(PyExc_ValueError, |
| 2109 | "field value is required for keyword"); |
| 2110 | return NULL; |
| 2111 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2112 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2113 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2114 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2115 | p->arg = arg; |
| 2116 | p->value = value; |
| 2117 | return p; |
| 2118 | } |
| 2119 | |
| 2120 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2121 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2122 | { |
| 2123 | alias_ty p; |
| 2124 | if (!name) { |
| 2125 | PyErr_SetString(PyExc_ValueError, |
| 2126 | "field name is required for alias"); |
| 2127 | return NULL; |
| 2128 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2129 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2130 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2131 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2132 | p->name = name; |
| 2133 | p->asname = asname; |
| 2134 | return p; |
| 2135 | } |
| 2136 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2137 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2138 | PyObject* |
| 2139 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2140 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2141 | mod_ty o = (mod_ty)_o; |
| 2142 | PyObject *result = NULL, *value = NULL; |
| 2143 | if (!o) { |
| 2144 | Py_INCREF(Py_None); |
| 2145 | return Py_None; |
| 2146 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2147 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2148 | switch (o->kind) { |
| 2149 | case Module_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2150 | result = PyType_GenericNew(Module_type, NULL, NULL); |
| 2151 | if (!result) goto failed; |
| 2152 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 2153 | if (!value) goto failed; |
| 2154 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2155 | goto failed; |
| 2156 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2157 | break; |
| 2158 | case Interactive_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2159 | result = PyType_GenericNew(Interactive_type, NULL, NULL); |
| 2160 | if (!result) goto failed; |
| 2161 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 2162 | if (!value) goto failed; |
| 2163 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2164 | goto failed; |
| 2165 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2166 | break; |
| 2167 | case Expression_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2168 | result = PyType_GenericNew(Expression_type, NULL, NULL); |
| 2169 | if (!result) goto failed; |
| 2170 | value = ast2obj_expr(o->v.Expression.body); |
| 2171 | if (!value) goto failed; |
| 2172 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2173 | goto failed; |
| 2174 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2175 | break; |
| 2176 | case Suite_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2177 | result = PyType_GenericNew(Suite_type, NULL, NULL); |
| 2178 | if (!result) goto failed; |
| 2179 | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
| 2180 | if (!value) goto failed; |
| 2181 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2182 | goto failed; |
| 2183 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2184 | break; |
| 2185 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2186 | return result; |
| 2187 | failed: |
| 2188 | Py_XDECREF(value); |
| 2189 | Py_XDECREF(result); |
| 2190 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2191 | } |
| 2192 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2193 | PyObject* |
| 2194 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2195 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2196 | stmt_ty o = (stmt_ty)_o; |
| 2197 | PyObject *result = NULL, *value = NULL; |
| 2198 | if (!o) { |
| 2199 | Py_INCREF(Py_None); |
| 2200 | return Py_None; |
| 2201 | } |
| 2202 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2203 | switch (o->kind) { |
| 2204 | case FunctionDef_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2205 | result = PyType_GenericNew(FunctionDef_type, NULL, NULL); |
| 2206 | if (!result) goto failed; |
| 2207 | value = ast2obj_identifier(o->v.FunctionDef.name); |
| 2208 | if (!value) goto failed; |
| 2209 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 2210 | goto failed; |
| 2211 | Py_DECREF(value); |
| 2212 | value = ast2obj_arguments(o->v.FunctionDef.args); |
| 2213 | if (!value) goto failed; |
| 2214 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 2215 | goto failed; |
| 2216 | Py_DECREF(value); |
| 2217 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 2218 | if (!value) goto failed; |
| 2219 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2220 | goto failed; |
| 2221 | Py_DECREF(value); |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2222 | value = ast2obj_list(o->v.FunctionDef.decorator_list, |
| 2223 | ast2obj_expr); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2224 | if (!value) goto failed; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2225 | if (PyObject_SetAttrString(result, "decorator_list", value) == |
| 2226 | -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2227 | goto failed; |
| 2228 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2229 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 2230 | if (!value) goto failed; |
| 2231 | if (PyObject_SetAttrString(result, "returns", value) == -1) |
| 2232 | goto failed; |
| 2233 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2234 | break; |
| 2235 | case ClassDef_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2236 | result = PyType_GenericNew(ClassDef_type, NULL, NULL); |
| 2237 | if (!result) goto failed; |
| 2238 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 2239 | if (!value) goto failed; |
| 2240 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 2241 | goto failed; |
| 2242 | Py_DECREF(value); |
| 2243 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 2244 | if (!value) goto failed; |
| 2245 | if (PyObject_SetAttrString(result, "bases", value) == -1) |
| 2246 | goto failed; |
| 2247 | Py_DECREF(value); |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 2248 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 2249 | if (!value) goto failed; |
| 2250 | if (PyObject_SetAttrString(result, "keywords", value) == -1) |
| 2251 | goto failed; |
| 2252 | Py_DECREF(value); |
| 2253 | value = ast2obj_expr(o->v.ClassDef.starargs); |
| 2254 | if (!value) goto failed; |
| 2255 | if (PyObject_SetAttrString(result, "starargs", value) == -1) |
| 2256 | goto failed; |
| 2257 | Py_DECREF(value); |
| 2258 | value = ast2obj_expr(o->v.ClassDef.kwargs); |
| 2259 | if (!value) goto failed; |
| 2260 | if (PyObject_SetAttrString(result, "kwargs", value) == -1) |
| 2261 | goto failed; |
| 2262 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2263 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 2264 | if (!value) goto failed; |
| 2265 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2266 | goto failed; |
| 2267 | Py_DECREF(value); |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2268 | value = ast2obj_list(o->v.ClassDef.decorator_list, |
| 2269 | ast2obj_expr); |
| 2270 | if (!value) goto failed; |
| 2271 | if (PyObject_SetAttrString(result, "decorator_list", value) == |
| 2272 | -1) |
| 2273 | goto failed; |
| 2274 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2275 | break; |
| 2276 | case Return_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2277 | result = PyType_GenericNew(Return_type, NULL, NULL); |
| 2278 | if (!result) goto failed; |
| 2279 | value = ast2obj_expr(o->v.Return.value); |
| 2280 | if (!value) goto failed; |
| 2281 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2282 | goto failed; |
| 2283 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2284 | break; |
| 2285 | case Delete_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2286 | result = PyType_GenericNew(Delete_type, NULL, NULL); |
| 2287 | if (!result) goto failed; |
| 2288 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 2289 | if (!value) goto failed; |
| 2290 | if (PyObject_SetAttrString(result, "targets", value) == -1) |
| 2291 | goto failed; |
| 2292 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2293 | break; |
| 2294 | case Assign_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2295 | result = PyType_GenericNew(Assign_type, NULL, NULL); |
| 2296 | if (!result) goto failed; |
| 2297 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 2298 | if (!value) goto failed; |
| 2299 | if (PyObject_SetAttrString(result, "targets", value) == -1) |
| 2300 | goto failed; |
| 2301 | Py_DECREF(value); |
| 2302 | value = ast2obj_expr(o->v.Assign.value); |
| 2303 | if (!value) goto failed; |
| 2304 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2305 | goto failed; |
| 2306 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2307 | break; |
| 2308 | case AugAssign_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2309 | result = PyType_GenericNew(AugAssign_type, NULL, NULL); |
| 2310 | if (!result) goto failed; |
| 2311 | value = ast2obj_expr(o->v.AugAssign.target); |
| 2312 | if (!value) goto failed; |
| 2313 | if (PyObject_SetAttrString(result, "target", value) == -1) |
| 2314 | goto failed; |
| 2315 | Py_DECREF(value); |
| 2316 | value = ast2obj_operator(o->v.AugAssign.op); |
| 2317 | if (!value) goto failed; |
| 2318 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2319 | goto failed; |
| 2320 | Py_DECREF(value); |
| 2321 | value = ast2obj_expr(o->v.AugAssign.value); |
| 2322 | if (!value) goto failed; |
| 2323 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2324 | goto failed; |
| 2325 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2326 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2327 | case For_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2328 | result = PyType_GenericNew(For_type, NULL, NULL); |
| 2329 | if (!result) goto failed; |
| 2330 | value = ast2obj_expr(o->v.For.target); |
| 2331 | if (!value) goto failed; |
| 2332 | if (PyObject_SetAttrString(result, "target", value) == -1) |
| 2333 | goto failed; |
| 2334 | Py_DECREF(value); |
| 2335 | value = ast2obj_expr(o->v.For.iter); |
| 2336 | if (!value) goto failed; |
| 2337 | if (PyObject_SetAttrString(result, "iter", value) == -1) |
| 2338 | goto failed; |
| 2339 | Py_DECREF(value); |
| 2340 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 2341 | if (!value) goto failed; |
| 2342 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2343 | goto failed; |
| 2344 | Py_DECREF(value); |
| 2345 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 2346 | if (!value) goto failed; |
| 2347 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2348 | goto failed; |
| 2349 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2350 | break; |
| 2351 | case While_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2352 | result = PyType_GenericNew(While_type, NULL, NULL); |
| 2353 | if (!result) goto failed; |
| 2354 | value = ast2obj_expr(o->v.While.test); |
| 2355 | if (!value) goto failed; |
| 2356 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2357 | goto failed; |
| 2358 | Py_DECREF(value); |
| 2359 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 2360 | if (!value) goto failed; |
| 2361 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2362 | goto failed; |
| 2363 | Py_DECREF(value); |
| 2364 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 2365 | if (!value) goto failed; |
| 2366 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2367 | goto failed; |
| 2368 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2369 | break; |
| 2370 | case If_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2371 | result = PyType_GenericNew(If_type, NULL, NULL); |
| 2372 | if (!result) goto failed; |
| 2373 | value = ast2obj_expr(o->v.If.test); |
| 2374 | if (!value) goto failed; |
| 2375 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2376 | goto failed; |
| 2377 | Py_DECREF(value); |
| 2378 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 2379 | if (!value) goto failed; |
| 2380 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2381 | goto failed; |
| 2382 | Py_DECREF(value); |
| 2383 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 2384 | if (!value) goto failed; |
| 2385 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2386 | goto failed; |
| 2387 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2388 | break; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2389 | case With_kind: |
| 2390 | result = PyType_GenericNew(With_type, NULL, NULL); |
| 2391 | if (!result) goto failed; |
| 2392 | value = ast2obj_expr(o->v.With.context_expr); |
| 2393 | if (!value) goto failed; |
| 2394 | if (PyObject_SetAttrString(result, "context_expr", value) == -1) |
| 2395 | goto failed; |
| 2396 | Py_DECREF(value); |
| 2397 | value = ast2obj_expr(o->v.With.optional_vars); |
| 2398 | if (!value) goto failed; |
| 2399 | if (PyObject_SetAttrString(result, "optional_vars", value) == |
| 2400 | -1) |
| 2401 | goto failed; |
| 2402 | Py_DECREF(value); |
| 2403 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 2404 | if (!value) goto failed; |
| 2405 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2406 | goto failed; |
| 2407 | Py_DECREF(value); |
| 2408 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2409 | case Raise_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2410 | result = PyType_GenericNew(Raise_type, NULL, NULL); |
| 2411 | if (!result) goto failed; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2412 | value = ast2obj_expr(o->v.Raise.exc); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2413 | if (!value) goto failed; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2414 | if (PyObject_SetAttrString(result, "exc", value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2415 | goto failed; |
| 2416 | Py_DECREF(value); |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2417 | value = ast2obj_expr(o->v.Raise.cause); |
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, "cause", value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2420 | goto failed; |
| 2421 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2422 | break; |
| 2423 | case TryExcept_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2424 | result = PyType_GenericNew(TryExcept_type, NULL, NULL); |
| 2425 | if (!result) goto failed; |
| 2426 | value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt); |
| 2427 | if (!value) goto failed; |
| 2428 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2429 | goto failed; |
| 2430 | Py_DECREF(value); |
| 2431 | value = ast2obj_list(o->v.TryExcept.handlers, |
| 2432 | ast2obj_excepthandler); |
| 2433 | if (!value) goto failed; |
| 2434 | if (PyObject_SetAttrString(result, "handlers", value) == -1) |
| 2435 | goto failed; |
| 2436 | Py_DECREF(value); |
| 2437 | value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt); |
| 2438 | if (!value) goto failed; |
| 2439 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2440 | goto failed; |
| 2441 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2442 | break; |
| 2443 | case TryFinally_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2444 | result = PyType_GenericNew(TryFinally_type, NULL, NULL); |
| 2445 | if (!result) goto failed; |
| 2446 | value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt); |
| 2447 | if (!value) goto failed; |
| 2448 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2449 | goto failed; |
| 2450 | Py_DECREF(value); |
| 2451 | value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt); |
| 2452 | if (!value) goto failed; |
| 2453 | if (PyObject_SetAttrString(result, "finalbody", value) == -1) |
| 2454 | goto failed; |
| 2455 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2456 | break; |
| 2457 | case Assert_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2458 | result = PyType_GenericNew(Assert_type, NULL, NULL); |
| 2459 | if (!result) goto failed; |
| 2460 | value = ast2obj_expr(o->v.Assert.test); |
| 2461 | if (!value) goto failed; |
| 2462 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2463 | goto failed; |
| 2464 | Py_DECREF(value); |
| 2465 | value = ast2obj_expr(o->v.Assert.msg); |
| 2466 | if (!value) goto failed; |
| 2467 | if (PyObject_SetAttrString(result, "msg", value) == -1) |
| 2468 | goto failed; |
| 2469 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2470 | break; |
| 2471 | case Import_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2472 | result = PyType_GenericNew(Import_type, NULL, NULL); |
| 2473 | if (!result) goto failed; |
| 2474 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 2475 | if (!value) goto failed; |
| 2476 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2477 | goto failed; |
| 2478 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2479 | break; |
| 2480 | case ImportFrom_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2481 | result = PyType_GenericNew(ImportFrom_type, NULL, NULL); |
| 2482 | if (!result) goto failed; |
| 2483 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 2484 | if (!value) goto failed; |
| 2485 | if (PyObject_SetAttrString(result, "module", value) == -1) |
| 2486 | goto failed; |
| 2487 | Py_DECREF(value); |
| 2488 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 2489 | if (!value) goto failed; |
| 2490 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2491 | goto failed; |
| 2492 | Py_DECREF(value); |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 2493 | value = ast2obj_int(o->v.ImportFrom.level); |
| 2494 | if (!value) goto failed; |
| 2495 | if (PyObject_SetAttrString(result, "level", value) == -1) |
| 2496 | goto failed; |
| 2497 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2498 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2499 | case Global_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2500 | result = PyType_GenericNew(Global_type, NULL, NULL); |
| 2501 | if (!result) goto failed; |
| 2502 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 2503 | if (!value) goto failed; |
| 2504 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2505 | goto failed; |
| 2506 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2507 | break; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2508 | case Nonlocal_kind: |
| 2509 | result = PyType_GenericNew(Nonlocal_type, NULL, NULL); |
| 2510 | if (!result) goto failed; |
| 2511 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 2512 | if (!value) goto failed; |
| 2513 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2514 | goto failed; |
| 2515 | Py_DECREF(value); |
| 2516 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2517 | case Expr_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2518 | result = PyType_GenericNew(Expr_type, NULL, NULL); |
| 2519 | if (!result) goto failed; |
| 2520 | value = ast2obj_expr(o->v.Expr.value); |
| 2521 | if (!value) goto failed; |
| 2522 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2523 | goto failed; |
| 2524 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2525 | break; |
| 2526 | case Pass_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2527 | result = PyType_GenericNew(Pass_type, NULL, NULL); |
| 2528 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2529 | break; |
| 2530 | case Break_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2531 | result = PyType_GenericNew(Break_type, NULL, NULL); |
| 2532 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2533 | break; |
| 2534 | case Continue_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2535 | result = PyType_GenericNew(Continue_type, NULL, NULL); |
| 2536 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2537 | break; |
| 2538 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2539 | value = ast2obj_int(o->lineno); |
| 2540 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2541 | if (PyObject_SetAttrString(result, "lineno", value) < 0) |
| 2542 | goto failed; |
| 2543 | Py_DECREF(value); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2544 | value = ast2obj_int(o->col_offset); |
| 2545 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2546 | if (PyObject_SetAttrString(result, "col_offset", value) < 0) |
| 2547 | goto failed; |
| 2548 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2549 | return result; |
| 2550 | failed: |
| 2551 | Py_XDECREF(value); |
| 2552 | Py_XDECREF(result); |
| 2553 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2554 | } |
| 2555 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2556 | PyObject* |
| 2557 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2558 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2559 | expr_ty o = (expr_ty)_o; |
| 2560 | PyObject *result = NULL, *value = NULL; |
| 2561 | if (!o) { |
| 2562 | Py_INCREF(Py_None); |
| 2563 | return Py_None; |
| 2564 | } |
| 2565 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2566 | switch (o->kind) { |
| 2567 | case BoolOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2568 | result = PyType_GenericNew(BoolOp_type, NULL, NULL); |
| 2569 | if (!result) goto failed; |
| 2570 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 2571 | if (!value) goto failed; |
| 2572 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2573 | goto failed; |
| 2574 | Py_DECREF(value); |
| 2575 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 2576 | if (!value) goto failed; |
| 2577 | if (PyObject_SetAttrString(result, "values", value) == -1) |
| 2578 | goto failed; |
| 2579 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2580 | break; |
| 2581 | case BinOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2582 | result = PyType_GenericNew(BinOp_type, NULL, NULL); |
| 2583 | if (!result) goto failed; |
| 2584 | value = ast2obj_expr(o->v.BinOp.left); |
| 2585 | if (!value) goto failed; |
| 2586 | if (PyObject_SetAttrString(result, "left", value) == -1) |
| 2587 | goto failed; |
| 2588 | Py_DECREF(value); |
| 2589 | value = ast2obj_operator(o->v.BinOp.op); |
| 2590 | if (!value) goto failed; |
| 2591 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2592 | goto failed; |
| 2593 | Py_DECREF(value); |
| 2594 | value = ast2obj_expr(o->v.BinOp.right); |
| 2595 | if (!value) goto failed; |
| 2596 | if (PyObject_SetAttrString(result, "right", value) == -1) |
| 2597 | goto failed; |
| 2598 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2599 | break; |
| 2600 | case UnaryOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2601 | result = PyType_GenericNew(UnaryOp_type, NULL, NULL); |
| 2602 | if (!result) goto failed; |
| 2603 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 2604 | if (!value) goto failed; |
| 2605 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2606 | goto failed; |
| 2607 | Py_DECREF(value); |
| 2608 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 2609 | if (!value) goto failed; |
| 2610 | if (PyObject_SetAttrString(result, "operand", value) == -1) |
| 2611 | goto failed; |
| 2612 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2613 | break; |
| 2614 | case Lambda_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2615 | result = PyType_GenericNew(Lambda_type, NULL, NULL); |
| 2616 | if (!result) goto failed; |
| 2617 | value = ast2obj_arguments(o->v.Lambda.args); |
| 2618 | if (!value) goto failed; |
| 2619 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 2620 | goto failed; |
| 2621 | Py_DECREF(value); |
| 2622 | value = ast2obj_expr(o->v.Lambda.body); |
| 2623 | if (!value) goto failed; |
| 2624 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2625 | goto failed; |
| 2626 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2627 | break; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2628 | case IfExp_kind: |
| 2629 | result = PyType_GenericNew(IfExp_type, NULL, NULL); |
| 2630 | if (!result) goto failed; |
| 2631 | value = ast2obj_expr(o->v.IfExp.test); |
| 2632 | if (!value) goto failed; |
| 2633 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2634 | goto failed; |
| 2635 | Py_DECREF(value); |
| 2636 | value = ast2obj_expr(o->v.IfExp.body); |
| 2637 | if (!value) goto failed; |
| 2638 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2639 | goto failed; |
| 2640 | Py_DECREF(value); |
| 2641 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 2642 | if (!value) goto failed; |
| 2643 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2644 | goto failed; |
| 2645 | Py_DECREF(value); |
| 2646 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2647 | case Dict_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2648 | result = PyType_GenericNew(Dict_type, NULL, NULL); |
| 2649 | if (!result) goto failed; |
| 2650 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 2651 | if (!value) goto failed; |
| 2652 | if (PyObject_SetAttrString(result, "keys", value) == -1) |
| 2653 | goto failed; |
| 2654 | Py_DECREF(value); |
| 2655 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 2656 | if (!value) goto failed; |
| 2657 | if (PyObject_SetAttrString(result, "values", value) == -1) |
| 2658 | goto failed; |
| 2659 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2660 | break; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2661 | case Set_kind: |
| 2662 | result = PyType_GenericNew(Set_type, NULL, NULL); |
| 2663 | if (!result) goto failed; |
| 2664 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 2665 | if (!value) goto failed; |
| 2666 | if (PyObject_SetAttrString(result, "elts", value) == -1) |
| 2667 | goto failed; |
| 2668 | Py_DECREF(value); |
| 2669 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2670 | case ListComp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2671 | result = PyType_GenericNew(ListComp_type, NULL, NULL); |
| 2672 | if (!result) goto failed; |
| 2673 | value = ast2obj_expr(o->v.ListComp.elt); |
| 2674 | if (!value) goto failed; |
| 2675 | if (PyObject_SetAttrString(result, "elt", value) == -1) |
| 2676 | goto failed; |
| 2677 | Py_DECREF(value); |
| 2678 | value = ast2obj_list(o->v.ListComp.generators, |
| 2679 | ast2obj_comprehension); |
| 2680 | if (!value) goto failed; |
| 2681 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2682 | goto failed; |
| 2683 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2684 | break; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2685 | case SetComp_kind: |
| 2686 | result = PyType_GenericNew(SetComp_type, NULL, NULL); |
| 2687 | if (!result) goto failed; |
| 2688 | value = ast2obj_expr(o->v.SetComp.elt); |
| 2689 | if (!value) goto failed; |
| 2690 | if (PyObject_SetAttrString(result, "elt", value) == -1) |
| 2691 | goto failed; |
| 2692 | Py_DECREF(value); |
| 2693 | value = ast2obj_list(o->v.SetComp.generators, |
| 2694 | ast2obj_comprehension); |
| 2695 | if (!value) goto failed; |
| 2696 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2697 | goto failed; |
| 2698 | Py_DECREF(value); |
| 2699 | break; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2700 | case DictComp_kind: |
| 2701 | result = PyType_GenericNew(DictComp_type, NULL, NULL); |
| 2702 | if (!result) goto failed; |
| 2703 | value = ast2obj_expr(o->v.DictComp.key); |
| 2704 | if (!value) goto failed; |
| 2705 | if (PyObject_SetAttrString(result, "key", value) == -1) |
| 2706 | goto failed; |
| 2707 | Py_DECREF(value); |
| 2708 | value = ast2obj_expr(o->v.DictComp.value); |
| 2709 | if (!value) goto failed; |
| 2710 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2711 | goto failed; |
| 2712 | Py_DECREF(value); |
| 2713 | value = ast2obj_list(o->v.DictComp.generators, |
| 2714 | ast2obj_comprehension); |
| 2715 | if (!value) goto failed; |
| 2716 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2717 | goto failed; |
| 2718 | Py_DECREF(value); |
| 2719 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2720 | case GeneratorExp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2721 | result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); |
| 2722 | if (!result) goto failed; |
| 2723 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 2724 | if (!value) goto failed; |
| 2725 | if (PyObject_SetAttrString(result, "elt", value) == -1) |
| 2726 | goto failed; |
| 2727 | Py_DECREF(value); |
| 2728 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 2729 | ast2obj_comprehension); |
| 2730 | if (!value) goto failed; |
| 2731 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2732 | goto failed; |
| 2733 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2734 | break; |
| 2735 | case Yield_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2736 | result = PyType_GenericNew(Yield_type, NULL, NULL); |
| 2737 | if (!result) goto failed; |
| 2738 | value = ast2obj_expr(o->v.Yield.value); |
| 2739 | if (!value) goto failed; |
| 2740 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2741 | goto failed; |
| 2742 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2743 | break; |
| 2744 | case Compare_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2745 | result = PyType_GenericNew(Compare_type, NULL, NULL); |
| 2746 | if (!result) goto failed; |
| 2747 | value = ast2obj_expr(o->v.Compare.left); |
| 2748 | if (!value) goto failed; |
| 2749 | if (PyObject_SetAttrString(result, "left", value) == -1) |
| 2750 | goto failed; |
| 2751 | Py_DECREF(value); |
Martin v. Löwis | ce1d5d2 | 2006-02-26 20:51:25 +0000 | [diff] [blame] | 2752 | { |
| 2753 | int i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 2754 | value = PyList_New(n); |
| 2755 | if (!value) goto failed; |
| 2756 | for(i = 0; i < n; i++) |
| 2757 | PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i))); |
| 2758 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2759 | if (!value) goto failed; |
| 2760 | if (PyObject_SetAttrString(result, "ops", value) == -1) |
| 2761 | goto failed; |
| 2762 | Py_DECREF(value); |
| 2763 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
| 2764 | if (!value) goto failed; |
| 2765 | if (PyObject_SetAttrString(result, "comparators", value) == -1) |
| 2766 | goto failed; |
| 2767 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2768 | break; |
| 2769 | case Call_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2770 | result = PyType_GenericNew(Call_type, NULL, NULL); |
| 2771 | if (!result) goto failed; |
| 2772 | value = ast2obj_expr(o->v.Call.func); |
| 2773 | if (!value) goto failed; |
| 2774 | if (PyObject_SetAttrString(result, "func", value) == -1) |
| 2775 | goto failed; |
| 2776 | Py_DECREF(value); |
| 2777 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 2778 | if (!value) goto failed; |
| 2779 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 2780 | goto failed; |
| 2781 | Py_DECREF(value); |
| 2782 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 2783 | if (!value) goto failed; |
| 2784 | if (PyObject_SetAttrString(result, "keywords", value) == -1) |
| 2785 | goto failed; |
| 2786 | Py_DECREF(value); |
| 2787 | value = ast2obj_expr(o->v.Call.starargs); |
| 2788 | if (!value) goto failed; |
| 2789 | if (PyObject_SetAttrString(result, "starargs", value) == -1) |
| 2790 | goto failed; |
| 2791 | Py_DECREF(value); |
| 2792 | value = ast2obj_expr(o->v.Call.kwargs); |
| 2793 | if (!value) goto failed; |
| 2794 | if (PyObject_SetAttrString(result, "kwargs", value) == -1) |
| 2795 | goto failed; |
| 2796 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2797 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2798 | case Num_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2799 | result = PyType_GenericNew(Num_type, NULL, NULL); |
| 2800 | if (!result) goto failed; |
| 2801 | value = ast2obj_object(o->v.Num.n); |
| 2802 | if (!value) goto failed; |
| 2803 | if (PyObject_SetAttrString(result, "n", value) == -1) |
| 2804 | goto failed; |
| 2805 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2806 | break; |
| 2807 | case Str_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2808 | result = PyType_GenericNew(Str_type, NULL, NULL); |
| 2809 | if (!result) goto failed; |
| 2810 | value = ast2obj_string(o->v.Str.s); |
| 2811 | if (!value) goto failed; |
| 2812 | if (PyObject_SetAttrString(result, "s", value) == -1) |
| 2813 | goto failed; |
| 2814 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2815 | break; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 2816 | case Bytes_kind: |
| 2817 | result = PyType_GenericNew(Bytes_type, NULL, NULL); |
| 2818 | if (!result) goto failed; |
| 2819 | value = ast2obj_string(o->v.Bytes.s); |
| 2820 | if (!value) goto failed; |
| 2821 | if (PyObject_SetAttrString(result, "s", value) == -1) |
| 2822 | goto failed; |
| 2823 | Py_DECREF(value); |
| 2824 | break; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 2825 | case Ellipsis_kind: |
| 2826 | result = PyType_GenericNew(Ellipsis_type, NULL, NULL); |
| 2827 | if (!result) goto failed; |
| 2828 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2829 | case Attribute_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2830 | result = PyType_GenericNew(Attribute_type, NULL, NULL); |
| 2831 | if (!result) goto failed; |
| 2832 | value = ast2obj_expr(o->v.Attribute.value); |
| 2833 | if (!value) goto failed; |
| 2834 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2835 | goto failed; |
| 2836 | Py_DECREF(value); |
| 2837 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 2838 | if (!value) goto failed; |
| 2839 | if (PyObject_SetAttrString(result, "attr", value) == -1) |
| 2840 | goto failed; |
| 2841 | Py_DECREF(value); |
| 2842 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 2843 | if (!value) goto failed; |
| 2844 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2845 | goto failed; |
| 2846 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2847 | break; |
| 2848 | case Subscript_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2849 | result = PyType_GenericNew(Subscript_type, NULL, NULL); |
| 2850 | if (!result) goto failed; |
| 2851 | value = ast2obj_expr(o->v.Subscript.value); |
| 2852 | if (!value) goto failed; |
| 2853 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2854 | goto failed; |
| 2855 | Py_DECREF(value); |
| 2856 | value = ast2obj_slice(o->v.Subscript.slice); |
| 2857 | if (!value) goto failed; |
| 2858 | if (PyObject_SetAttrString(result, "slice", value) == -1) |
| 2859 | goto failed; |
| 2860 | Py_DECREF(value); |
| 2861 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 2862 | if (!value) goto failed; |
| 2863 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2864 | goto failed; |
| 2865 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2866 | break; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2867 | case Starred_kind: |
| 2868 | result = PyType_GenericNew(Starred_type, NULL, NULL); |
| 2869 | if (!result) goto failed; |
| 2870 | value = ast2obj_expr(o->v.Starred.value); |
| 2871 | if (!value) goto failed; |
| 2872 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2873 | goto failed; |
| 2874 | Py_DECREF(value); |
| 2875 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 2876 | if (!value) goto failed; |
| 2877 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2878 | goto failed; |
| 2879 | Py_DECREF(value); |
| 2880 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2881 | case Name_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2882 | result = PyType_GenericNew(Name_type, NULL, NULL); |
| 2883 | if (!result) goto failed; |
| 2884 | value = ast2obj_identifier(o->v.Name.id); |
| 2885 | if (!value) goto failed; |
| 2886 | if (PyObject_SetAttrString(result, "id", value) == -1) |
| 2887 | goto failed; |
| 2888 | Py_DECREF(value); |
| 2889 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 2890 | if (!value) goto failed; |
| 2891 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2892 | goto failed; |
| 2893 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2894 | break; |
| 2895 | case List_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2896 | result = PyType_GenericNew(List_type, NULL, NULL); |
| 2897 | if (!result) goto failed; |
| 2898 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 2899 | if (!value) goto failed; |
| 2900 | if (PyObject_SetAttrString(result, "elts", value) == -1) |
| 2901 | goto failed; |
| 2902 | Py_DECREF(value); |
| 2903 | value = ast2obj_expr_context(o->v.List.ctx); |
| 2904 | if (!value) goto failed; |
| 2905 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2906 | goto failed; |
| 2907 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2908 | break; |
| 2909 | case Tuple_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2910 | result = PyType_GenericNew(Tuple_type, NULL, NULL); |
| 2911 | if (!result) goto failed; |
| 2912 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 2913 | if (!value) goto failed; |
| 2914 | if (PyObject_SetAttrString(result, "elts", value) == -1) |
| 2915 | goto failed; |
| 2916 | Py_DECREF(value); |
| 2917 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 2918 | if (!value) goto failed; |
| 2919 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2920 | goto failed; |
| 2921 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2922 | break; |
| 2923 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2924 | value = ast2obj_int(o->lineno); |
| 2925 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2926 | if (PyObject_SetAttrString(result, "lineno", value) < 0) |
| 2927 | goto failed; |
| 2928 | Py_DECREF(value); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2929 | value = ast2obj_int(o->col_offset); |
| 2930 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2931 | if (PyObject_SetAttrString(result, "col_offset", value) < 0) |
| 2932 | goto failed; |
| 2933 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2934 | return result; |
| 2935 | failed: |
| 2936 | Py_XDECREF(value); |
| 2937 | Py_XDECREF(result); |
| 2938 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2939 | } |
| 2940 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2941 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2942 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2943 | switch(o) { |
| 2944 | case Load: |
| 2945 | Py_INCREF(Load_singleton); |
| 2946 | return Load_singleton; |
| 2947 | case Store: |
| 2948 | Py_INCREF(Store_singleton); |
| 2949 | return Store_singleton; |
| 2950 | case Del: |
| 2951 | Py_INCREF(Del_singleton); |
| 2952 | return Del_singleton; |
| 2953 | case AugLoad: |
| 2954 | Py_INCREF(AugLoad_singleton); |
| 2955 | return AugLoad_singleton; |
| 2956 | case AugStore: |
| 2957 | Py_INCREF(AugStore_singleton); |
| 2958 | return AugStore_singleton; |
| 2959 | case Param: |
| 2960 | Py_INCREF(Param_singleton); |
| 2961 | return Param_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 2962 | default: |
| 2963 | /* should never happen, but just in case ... */ |
| 2964 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 2965 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2966 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2967 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2968 | PyObject* |
| 2969 | ast2obj_slice(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2970 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2971 | slice_ty o = (slice_ty)_o; |
| 2972 | PyObject *result = NULL, *value = NULL; |
| 2973 | if (!o) { |
| 2974 | Py_INCREF(Py_None); |
| 2975 | return Py_None; |
| 2976 | } |
| 2977 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2978 | switch (o->kind) { |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2979 | case Slice_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2980 | result = PyType_GenericNew(Slice_type, NULL, NULL); |
| 2981 | if (!result) goto failed; |
| 2982 | value = ast2obj_expr(o->v.Slice.lower); |
| 2983 | if (!value) goto failed; |
| 2984 | if (PyObject_SetAttrString(result, "lower", value) == -1) |
| 2985 | goto failed; |
| 2986 | Py_DECREF(value); |
| 2987 | value = ast2obj_expr(o->v.Slice.upper); |
| 2988 | if (!value) goto failed; |
| 2989 | if (PyObject_SetAttrString(result, "upper", value) == -1) |
| 2990 | goto failed; |
| 2991 | Py_DECREF(value); |
| 2992 | value = ast2obj_expr(o->v.Slice.step); |
| 2993 | if (!value) goto failed; |
| 2994 | if (PyObject_SetAttrString(result, "step", value) == -1) |
| 2995 | goto failed; |
| 2996 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2997 | break; |
| 2998 | case ExtSlice_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2999 | result = PyType_GenericNew(ExtSlice_type, NULL, NULL); |
| 3000 | if (!result) goto failed; |
| 3001 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 3002 | if (!value) goto failed; |
| 3003 | if (PyObject_SetAttrString(result, "dims", value) == -1) |
| 3004 | goto failed; |
| 3005 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3006 | break; |
| 3007 | case Index_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3008 | result = PyType_GenericNew(Index_type, NULL, NULL); |
| 3009 | if (!result) goto failed; |
| 3010 | value = ast2obj_expr(o->v.Index.value); |
| 3011 | if (!value) goto failed; |
| 3012 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 3013 | goto failed; |
| 3014 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3015 | break; |
| 3016 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3017 | return result; |
| 3018 | failed: |
| 3019 | Py_XDECREF(value); |
| 3020 | Py_XDECREF(result); |
| 3021 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3022 | } |
| 3023 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3024 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3025 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3026 | switch(o) { |
| 3027 | case And: |
| 3028 | Py_INCREF(And_singleton); |
| 3029 | return And_singleton; |
| 3030 | case Or: |
| 3031 | Py_INCREF(Or_singleton); |
| 3032 | return Or_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3033 | default: |
| 3034 | /* should never happen, but just in case ... */ |
| 3035 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 3036 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3037 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3038 | } |
| 3039 | PyObject* ast2obj_operator(operator_ty o) |
| 3040 | { |
| 3041 | switch(o) { |
| 3042 | case Add: |
| 3043 | Py_INCREF(Add_singleton); |
| 3044 | return Add_singleton; |
| 3045 | case Sub: |
| 3046 | Py_INCREF(Sub_singleton); |
| 3047 | return Sub_singleton; |
| 3048 | case Mult: |
| 3049 | Py_INCREF(Mult_singleton); |
| 3050 | return Mult_singleton; |
| 3051 | case Div: |
| 3052 | Py_INCREF(Div_singleton); |
| 3053 | return Div_singleton; |
| 3054 | case Mod: |
| 3055 | Py_INCREF(Mod_singleton); |
| 3056 | return Mod_singleton; |
| 3057 | case Pow: |
| 3058 | Py_INCREF(Pow_singleton); |
| 3059 | return Pow_singleton; |
| 3060 | case LShift: |
| 3061 | Py_INCREF(LShift_singleton); |
| 3062 | return LShift_singleton; |
| 3063 | case RShift: |
| 3064 | Py_INCREF(RShift_singleton); |
| 3065 | return RShift_singleton; |
| 3066 | case BitOr: |
| 3067 | Py_INCREF(BitOr_singleton); |
| 3068 | return BitOr_singleton; |
| 3069 | case BitXor: |
| 3070 | Py_INCREF(BitXor_singleton); |
| 3071 | return BitXor_singleton; |
| 3072 | case BitAnd: |
| 3073 | Py_INCREF(BitAnd_singleton); |
| 3074 | return BitAnd_singleton; |
| 3075 | case FloorDiv: |
| 3076 | Py_INCREF(FloorDiv_singleton); |
| 3077 | return FloorDiv_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3078 | default: |
| 3079 | /* should never happen, but just in case ... */ |
| 3080 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 3081 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3082 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3083 | } |
| 3084 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 3085 | { |
| 3086 | switch(o) { |
| 3087 | case Invert: |
| 3088 | Py_INCREF(Invert_singleton); |
| 3089 | return Invert_singleton; |
| 3090 | case Not: |
| 3091 | Py_INCREF(Not_singleton); |
| 3092 | return Not_singleton; |
| 3093 | case UAdd: |
| 3094 | Py_INCREF(UAdd_singleton); |
| 3095 | return UAdd_singleton; |
| 3096 | case USub: |
| 3097 | Py_INCREF(USub_singleton); |
| 3098 | return USub_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3099 | default: |
| 3100 | /* should never happen, but just in case ... */ |
| 3101 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 3102 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3103 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3104 | } |
| 3105 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 3106 | { |
| 3107 | switch(o) { |
| 3108 | case Eq: |
| 3109 | Py_INCREF(Eq_singleton); |
| 3110 | return Eq_singleton; |
| 3111 | case NotEq: |
| 3112 | Py_INCREF(NotEq_singleton); |
| 3113 | return NotEq_singleton; |
| 3114 | case Lt: |
| 3115 | Py_INCREF(Lt_singleton); |
| 3116 | return Lt_singleton; |
| 3117 | case LtE: |
| 3118 | Py_INCREF(LtE_singleton); |
| 3119 | return LtE_singleton; |
| 3120 | case Gt: |
| 3121 | Py_INCREF(Gt_singleton); |
| 3122 | return Gt_singleton; |
| 3123 | case GtE: |
| 3124 | Py_INCREF(GtE_singleton); |
| 3125 | return GtE_singleton; |
| 3126 | case Is: |
| 3127 | Py_INCREF(Is_singleton); |
| 3128 | return Is_singleton; |
| 3129 | case IsNot: |
| 3130 | Py_INCREF(IsNot_singleton); |
| 3131 | return IsNot_singleton; |
| 3132 | case In: |
| 3133 | Py_INCREF(In_singleton); |
| 3134 | return In_singleton; |
| 3135 | case NotIn: |
| 3136 | Py_INCREF(NotIn_singleton); |
| 3137 | return NotIn_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3138 | default: |
| 3139 | /* should never happen, but just in case ... */ |
| 3140 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 3141 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3142 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3143 | } |
| 3144 | PyObject* |
| 3145 | ast2obj_comprehension(void* _o) |
| 3146 | { |
| 3147 | comprehension_ty o = (comprehension_ty)_o; |
| 3148 | PyObject *result = NULL, *value = NULL; |
| 3149 | if (!o) { |
| 3150 | Py_INCREF(Py_None); |
| 3151 | return Py_None; |
| 3152 | } |
| 3153 | |
| 3154 | result = PyType_GenericNew(comprehension_type, NULL, NULL); |
| 3155 | if (!result) return NULL; |
| 3156 | value = ast2obj_expr(o->target); |
| 3157 | if (!value) goto failed; |
| 3158 | if (PyObject_SetAttrString(result, "target", value) == -1) |
| 3159 | goto failed; |
| 3160 | Py_DECREF(value); |
| 3161 | value = ast2obj_expr(o->iter); |
| 3162 | if (!value) goto failed; |
| 3163 | if (PyObject_SetAttrString(result, "iter", value) == -1) |
| 3164 | goto failed; |
| 3165 | Py_DECREF(value); |
| 3166 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 3167 | if (!value) goto failed; |
| 3168 | if (PyObject_SetAttrString(result, "ifs", value) == -1) |
| 3169 | goto failed; |
| 3170 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3171 | return result; |
| 3172 | failed: |
| 3173 | Py_XDECREF(value); |
| 3174 | Py_XDECREF(result); |
| 3175 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3176 | } |
| 3177 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3178 | PyObject* |
| 3179 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3180 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3181 | excepthandler_ty o = (excepthandler_ty)_o; |
| 3182 | PyObject *result = NULL, *value = NULL; |
| 3183 | if (!o) { |
| 3184 | Py_INCREF(Py_None); |
| 3185 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3186 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3187 | |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3188 | switch (o->kind) { |
| 3189 | case ExceptHandler_kind: |
| 3190 | result = PyType_GenericNew(ExceptHandler_type, NULL, NULL); |
| 3191 | if (!result) goto failed; |
| 3192 | value = ast2obj_expr(o->v.ExceptHandler.type); |
| 3193 | if (!value) goto failed; |
| 3194 | if (PyObject_SetAttrString(result, "type", value) == -1) |
| 3195 | goto failed; |
| 3196 | Py_DECREF(value); |
| 3197 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
| 3198 | if (!value) goto failed; |
| 3199 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 3200 | goto failed; |
| 3201 | Py_DECREF(value); |
| 3202 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 3203 | if (!value) goto failed; |
| 3204 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 3205 | goto failed; |
| 3206 | Py_DECREF(value); |
| 3207 | break; |
| 3208 | } |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3209 | value = ast2obj_int(o->lineno); |
| 3210 | if (!value) goto failed; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3211 | if (PyObject_SetAttrString(result, "lineno", value) < 0) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3212 | goto failed; |
| 3213 | Py_DECREF(value); |
| 3214 | value = ast2obj_int(o->col_offset); |
| 3215 | if (!value) goto failed; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3216 | if (PyObject_SetAttrString(result, "col_offset", value) < 0) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3217 | goto failed; |
| 3218 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3219 | return result; |
| 3220 | failed: |
| 3221 | Py_XDECREF(value); |
| 3222 | Py_XDECREF(result); |
| 3223 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3224 | } |
| 3225 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3226 | PyObject* |
| 3227 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3228 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3229 | arguments_ty o = (arguments_ty)_o; |
| 3230 | PyObject *result = NULL, *value = NULL; |
| 3231 | if (!o) { |
| 3232 | Py_INCREF(Py_None); |
| 3233 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3234 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3235 | |
| 3236 | result = PyType_GenericNew(arguments_type, NULL, NULL); |
| 3237 | if (!result) return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3238 | value = ast2obj_list(o->args, ast2obj_arg); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3239 | if (!value) goto failed; |
| 3240 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 3241 | goto failed; |
| 3242 | Py_DECREF(value); |
| 3243 | value = ast2obj_identifier(o->vararg); |
| 3244 | if (!value) goto failed; |
| 3245 | if (PyObject_SetAttrString(result, "vararg", value) == -1) |
| 3246 | goto failed; |
| 3247 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3248 | value = ast2obj_expr(o->varargannotation); |
| 3249 | if (!value) goto failed; |
| 3250 | if (PyObject_SetAttrString(result, "varargannotation", value) == -1) |
| 3251 | goto failed; |
| 3252 | Py_DECREF(value); |
| 3253 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 3254 | if (!value) goto failed; |
| 3255 | if (PyObject_SetAttrString(result, "kwonlyargs", value) == -1) |
| 3256 | goto failed; |
| 3257 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3258 | value = ast2obj_identifier(o->kwarg); |
| 3259 | if (!value) goto failed; |
| 3260 | if (PyObject_SetAttrString(result, "kwarg", value) == -1) |
| 3261 | goto failed; |
| 3262 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3263 | value = ast2obj_expr(o->kwargannotation); |
| 3264 | if (!value) goto failed; |
| 3265 | if (PyObject_SetAttrString(result, "kwargannotation", value) == -1) |
| 3266 | goto failed; |
| 3267 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3268 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 3269 | if (!value) goto failed; |
| 3270 | if (PyObject_SetAttrString(result, "defaults", value) == -1) |
| 3271 | goto failed; |
| 3272 | Py_DECREF(value); |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 3273 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
| 3274 | if (!value) goto failed; |
| 3275 | if (PyObject_SetAttrString(result, "kw_defaults", value) == -1) |
| 3276 | goto failed; |
| 3277 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3278 | return result; |
| 3279 | failed: |
| 3280 | Py_XDECREF(value); |
| 3281 | Py_XDECREF(result); |
| 3282 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3283 | } |
| 3284 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3285 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3286 | ast2obj_arg(void* _o) |
| 3287 | { |
| 3288 | arg_ty o = (arg_ty)_o; |
| 3289 | PyObject *result = NULL, *value = NULL; |
| 3290 | if (!o) { |
| 3291 | Py_INCREF(Py_None); |
| 3292 | return Py_None; |
| 3293 | } |
| 3294 | |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 3295 | result = PyType_GenericNew(arg_type, NULL, NULL); |
| 3296 | if (!result) return NULL; |
| 3297 | value = ast2obj_identifier(o->arg); |
| 3298 | if (!value) goto failed; |
| 3299 | if (PyObject_SetAttrString(result, "arg", value) == -1) |
| 3300 | goto failed; |
| 3301 | Py_DECREF(value); |
| 3302 | value = ast2obj_expr(o->annotation); |
| 3303 | if (!value) goto failed; |
| 3304 | if (PyObject_SetAttrString(result, "annotation", value) == -1) |
| 3305 | goto failed; |
| 3306 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3307 | return result; |
| 3308 | failed: |
| 3309 | Py_XDECREF(value); |
| 3310 | Py_XDECREF(result); |
| 3311 | return NULL; |
| 3312 | } |
| 3313 | |
| 3314 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3315 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3316 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3317 | keyword_ty o = (keyword_ty)_o; |
| 3318 | PyObject *result = NULL, *value = NULL; |
| 3319 | if (!o) { |
| 3320 | Py_INCREF(Py_None); |
| 3321 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3322 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3323 | |
| 3324 | result = PyType_GenericNew(keyword_type, NULL, NULL); |
| 3325 | if (!result) return NULL; |
| 3326 | value = ast2obj_identifier(o->arg); |
| 3327 | if (!value) goto failed; |
| 3328 | if (PyObject_SetAttrString(result, "arg", value) == -1) |
| 3329 | goto failed; |
| 3330 | Py_DECREF(value); |
| 3331 | value = ast2obj_expr(o->value); |
| 3332 | if (!value) goto failed; |
| 3333 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 3334 | goto failed; |
| 3335 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3336 | return result; |
| 3337 | failed: |
| 3338 | Py_XDECREF(value); |
| 3339 | Py_XDECREF(result); |
| 3340 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3341 | } |
| 3342 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3343 | PyObject* |
| 3344 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3345 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3346 | alias_ty o = (alias_ty)_o; |
| 3347 | PyObject *result = NULL, *value = NULL; |
| 3348 | if (!o) { |
| 3349 | Py_INCREF(Py_None); |
| 3350 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3351 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3352 | |
| 3353 | result = PyType_GenericNew(alias_type, NULL, NULL); |
| 3354 | if (!result) return NULL; |
| 3355 | value = ast2obj_identifier(o->name); |
| 3356 | if (!value) goto failed; |
| 3357 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 3358 | goto failed; |
| 3359 | Py_DECREF(value); |
| 3360 | value = ast2obj_identifier(o->asname); |
| 3361 | if (!value) goto failed; |
| 3362 | if (PyObject_SetAttrString(result, "asname", value) == -1) |
| 3363 | goto failed; |
| 3364 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3365 | return result; |
| 3366 | failed: |
| 3367 | Py_XDECREF(value); |
| 3368 | Py_XDECREF(result); |
| 3369 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3370 | } |
| 3371 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3372 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3373 | int |
| 3374 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 3375 | { |
| 3376 | PyObject* tmp = NULL; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3377 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3378 | |
| 3379 | |
| 3380 | if (obj == Py_None) { |
| 3381 | *out = NULL; |
| 3382 | return 0; |
| 3383 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3384 | isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type); |
| 3385 | if (isinstance == -1) { |
| 3386 | return 1; |
| 3387 | } |
| 3388 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3389 | asdl_seq* body; |
| 3390 | |
| 3391 | if (PyObject_HasAttrString(obj, "body")) { |
| 3392 | int res; |
| 3393 | Py_ssize_t len; |
| 3394 | Py_ssize_t i; |
| 3395 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3396 | if (tmp == NULL) goto failed; |
| 3397 | if (!PyList_Check(tmp)) { |
| 3398 | PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3399 | goto failed; |
| 3400 | } |
| 3401 | len = PyList_GET_SIZE(tmp); |
| 3402 | body = asdl_seq_new(len, arena); |
| 3403 | if (body == NULL) goto failed; |
| 3404 | for (i = 0; i < len; i++) { |
| 3405 | stmt_ty value; |
| 3406 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3407 | if (res != 0) goto failed; |
| 3408 | asdl_seq_SET(body, i, value); |
| 3409 | } |
| 3410 | Py_XDECREF(tmp); |
| 3411 | tmp = NULL; |
| 3412 | } else { |
| 3413 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 3414 | return 1; |
| 3415 | } |
| 3416 | *out = Module(body, arena); |
| 3417 | if (*out == NULL) goto failed; |
| 3418 | return 0; |
| 3419 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3420 | isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type); |
| 3421 | if (isinstance == -1) { |
| 3422 | return 1; |
| 3423 | } |
| 3424 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3425 | asdl_seq* body; |
| 3426 | |
| 3427 | if (PyObject_HasAttrString(obj, "body")) { |
| 3428 | int res; |
| 3429 | Py_ssize_t len; |
| 3430 | Py_ssize_t i; |
| 3431 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3432 | if (tmp == NULL) goto failed; |
| 3433 | if (!PyList_Check(tmp)) { |
| 3434 | PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3435 | goto failed; |
| 3436 | } |
| 3437 | len = PyList_GET_SIZE(tmp); |
| 3438 | body = asdl_seq_new(len, arena); |
| 3439 | if (body == NULL) goto failed; |
| 3440 | for (i = 0; i < len; i++) { |
| 3441 | stmt_ty value; |
| 3442 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3443 | if (res != 0) goto failed; |
| 3444 | asdl_seq_SET(body, i, value); |
| 3445 | } |
| 3446 | Py_XDECREF(tmp); |
| 3447 | tmp = NULL; |
| 3448 | } else { |
| 3449 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 3450 | return 1; |
| 3451 | } |
| 3452 | *out = Interactive(body, arena); |
| 3453 | if (*out == NULL) goto failed; |
| 3454 | return 0; |
| 3455 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3456 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type); |
| 3457 | if (isinstance == -1) { |
| 3458 | return 1; |
| 3459 | } |
| 3460 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3461 | expr_ty body; |
| 3462 | |
| 3463 | if (PyObject_HasAttrString(obj, "body")) { |
| 3464 | int res; |
| 3465 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3466 | if (tmp == NULL) goto failed; |
| 3467 | res = obj2ast_expr(tmp, &body, arena); |
| 3468 | if (res != 0) goto failed; |
| 3469 | Py_XDECREF(tmp); |
| 3470 | tmp = NULL; |
| 3471 | } else { |
| 3472 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 3473 | return 1; |
| 3474 | } |
| 3475 | *out = Expression(body, arena); |
| 3476 | if (*out == NULL) goto failed; |
| 3477 | return 0; |
| 3478 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3479 | isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type); |
| 3480 | if (isinstance == -1) { |
| 3481 | return 1; |
| 3482 | } |
| 3483 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3484 | asdl_seq* body; |
| 3485 | |
| 3486 | if (PyObject_HasAttrString(obj, "body")) { |
| 3487 | int res; |
| 3488 | Py_ssize_t len; |
| 3489 | Py_ssize_t i; |
| 3490 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3491 | if (tmp == NULL) goto failed; |
| 3492 | if (!PyList_Check(tmp)) { |
| 3493 | PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3494 | goto failed; |
| 3495 | } |
| 3496 | len = PyList_GET_SIZE(tmp); |
| 3497 | body = asdl_seq_new(len, arena); |
| 3498 | if (body == NULL) goto failed; |
| 3499 | for (i = 0; i < len; i++) { |
| 3500 | stmt_ty value; |
| 3501 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3502 | if (res != 0) goto failed; |
| 3503 | asdl_seq_SET(body, i, value); |
| 3504 | } |
| 3505 | Py_XDECREF(tmp); |
| 3506 | tmp = NULL; |
| 3507 | } else { |
| 3508 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite"); |
| 3509 | return 1; |
| 3510 | } |
| 3511 | *out = Suite(body, arena); |
| 3512 | if (*out == NULL) goto failed; |
| 3513 | return 0; |
| 3514 | } |
| 3515 | |
| 3516 | tmp = PyObject_Repr(obj); |
| 3517 | if (tmp == NULL) goto failed; |
Christian Heimes | 72b710a | 2008-05-26 13:28:38 +0000 | [diff] [blame] | 3518 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %.400s", PyBytes_AS_STRING(tmp)); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3519 | failed: |
| 3520 | Py_XDECREF(tmp); |
| 3521 | return 1; |
| 3522 | } |
| 3523 | |
| 3524 | int |
| 3525 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 3526 | { |
| 3527 | PyObject* tmp = NULL; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3528 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3529 | |
| 3530 | int lineno; |
| 3531 | int col_offset; |
| 3532 | |
| 3533 | if (obj == Py_None) { |
| 3534 | *out = NULL; |
| 3535 | return 0; |
| 3536 | } |
| 3537 | if (PyObject_HasAttrString(obj, "lineno")) { |
| 3538 | int res; |
| 3539 | tmp = PyObject_GetAttrString(obj, "lineno"); |
| 3540 | if (tmp == NULL) goto failed; |
| 3541 | res = obj2ast_int(tmp, &lineno, arena); |
| 3542 | if (res != 0) goto failed; |
| 3543 | Py_XDECREF(tmp); |
| 3544 | tmp = NULL; |
| 3545 | } else { |
| 3546 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 3547 | return 1; |
| 3548 | } |
| 3549 | if (PyObject_HasAttrString(obj, "col_offset")) { |
| 3550 | int res; |
| 3551 | tmp = PyObject_GetAttrString(obj, "col_offset"); |
| 3552 | if (tmp == NULL) goto failed; |
| 3553 | res = obj2ast_int(tmp, &col_offset, arena); |
| 3554 | if (res != 0) goto failed; |
| 3555 | Py_XDECREF(tmp); |
| 3556 | tmp = NULL; |
| 3557 | } else { |
| 3558 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 3559 | return 1; |
| 3560 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3561 | isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type); |
| 3562 | if (isinstance == -1) { |
| 3563 | return 1; |
| 3564 | } |
| 3565 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3566 | identifier name; |
| 3567 | arguments_ty args; |
| 3568 | asdl_seq* body; |
| 3569 | asdl_seq* decorator_list; |
| 3570 | expr_ty returns; |
| 3571 | |
| 3572 | if (PyObject_HasAttrString(obj, "name")) { |
| 3573 | int res; |
| 3574 | tmp = PyObject_GetAttrString(obj, "name"); |
| 3575 | if (tmp == NULL) goto failed; |
| 3576 | res = obj2ast_identifier(tmp, &name, arena); |
| 3577 | if (res != 0) goto failed; |
| 3578 | Py_XDECREF(tmp); |
| 3579 | tmp = NULL; |
| 3580 | } else { |
| 3581 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 3582 | return 1; |
| 3583 | } |
| 3584 | if (PyObject_HasAttrString(obj, "args")) { |
| 3585 | int res; |
| 3586 | tmp = PyObject_GetAttrString(obj, "args"); |
| 3587 | if (tmp == NULL) goto failed; |
| 3588 | res = obj2ast_arguments(tmp, &args, arena); |
| 3589 | if (res != 0) goto failed; |
| 3590 | Py_XDECREF(tmp); |
| 3591 | tmp = NULL; |
| 3592 | } else { |
| 3593 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 3594 | return 1; |
| 3595 | } |
| 3596 | if (PyObject_HasAttrString(obj, "body")) { |
| 3597 | int res; |
| 3598 | Py_ssize_t len; |
| 3599 | Py_ssize_t i; |
| 3600 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3601 | if (tmp == NULL) goto failed; |
| 3602 | if (!PyList_Check(tmp)) { |
| 3603 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3604 | goto failed; |
| 3605 | } |
| 3606 | len = PyList_GET_SIZE(tmp); |
| 3607 | body = asdl_seq_new(len, arena); |
| 3608 | if (body == NULL) goto failed; |
| 3609 | for (i = 0; i < len; i++) { |
| 3610 | stmt_ty value; |
| 3611 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3612 | if (res != 0) goto failed; |
| 3613 | asdl_seq_SET(body, i, value); |
| 3614 | } |
| 3615 | Py_XDECREF(tmp); |
| 3616 | tmp = NULL; |
| 3617 | } else { |
| 3618 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 3619 | return 1; |
| 3620 | } |
| 3621 | if (PyObject_HasAttrString(obj, "decorator_list")) { |
| 3622 | int res; |
| 3623 | Py_ssize_t len; |
| 3624 | Py_ssize_t i; |
| 3625 | tmp = PyObject_GetAttrString(obj, "decorator_list"); |
| 3626 | if (tmp == NULL) goto failed; |
| 3627 | if (!PyList_Check(tmp)) { |
| 3628 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3629 | goto failed; |
| 3630 | } |
| 3631 | len = PyList_GET_SIZE(tmp); |
| 3632 | decorator_list = asdl_seq_new(len, arena); |
| 3633 | if (decorator_list == NULL) goto failed; |
| 3634 | for (i = 0; i < len; i++) { |
| 3635 | expr_ty value; |
| 3636 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3637 | if (res != 0) goto failed; |
| 3638 | asdl_seq_SET(decorator_list, i, value); |
| 3639 | } |
| 3640 | Py_XDECREF(tmp); |
| 3641 | tmp = NULL; |
| 3642 | } else { |
| 3643 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 3644 | return 1; |
| 3645 | } |
| 3646 | if (PyObject_HasAttrString(obj, "returns")) { |
| 3647 | int res; |
| 3648 | tmp = PyObject_GetAttrString(obj, "returns"); |
| 3649 | if (tmp == NULL) goto failed; |
| 3650 | res = obj2ast_expr(tmp, &returns, arena); |
| 3651 | if (res != 0) goto failed; |
| 3652 | Py_XDECREF(tmp); |
| 3653 | tmp = NULL; |
| 3654 | } else { |
| 3655 | returns = NULL; |
| 3656 | } |
| 3657 | *out = FunctionDef(name, args, body, decorator_list, returns, |
| 3658 | lineno, col_offset, arena); |
| 3659 | if (*out == NULL) goto failed; |
| 3660 | return 0; |
| 3661 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3662 | isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type); |
| 3663 | if (isinstance == -1) { |
| 3664 | return 1; |
| 3665 | } |
| 3666 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3667 | identifier name; |
| 3668 | asdl_seq* bases; |
| 3669 | asdl_seq* keywords; |
| 3670 | expr_ty starargs; |
| 3671 | expr_ty kwargs; |
| 3672 | asdl_seq* body; |
| 3673 | asdl_seq* decorator_list; |
| 3674 | |
| 3675 | if (PyObject_HasAttrString(obj, "name")) { |
| 3676 | int res; |
| 3677 | tmp = PyObject_GetAttrString(obj, "name"); |
| 3678 | if (tmp == NULL) goto failed; |
| 3679 | res = obj2ast_identifier(tmp, &name, arena); |
| 3680 | if (res != 0) goto failed; |
| 3681 | Py_XDECREF(tmp); |
| 3682 | tmp = NULL; |
| 3683 | } else { |
| 3684 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 3685 | return 1; |
| 3686 | } |
| 3687 | if (PyObject_HasAttrString(obj, "bases")) { |
| 3688 | int res; |
| 3689 | Py_ssize_t len; |
| 3690 | Py_ssize_t i; |
| 3691 | tmp = PyObject_GetAttrString(obj, "bases"); |
| 3692 | if (tmp == NULL) goto failed; |
| 3693 | if (!PyList_Check(tmp)) { |
| 3694 | PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3695 | goto failed; |
| 3696 | } |
| 3697 | len = PyList_GET_SIZE(tmp); |
| 3698 | bases = asdl_seq_new(len, arena); |
| 3699 | if (bases == NULL) goto failed; |
| 3700 | for (i = 0; i < len; i++) { |
| 3701 | expr_ty value; |
| 3702 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3703 | if (res != 0) goto failed; |
| 3704 | asdl_seq_SET(bases, i, value); |
| 3705 | } |
| 3706 | Py_XDECREF(tmp); |
| 3707 | tmp = NULL; |
| 3708 | } else { |
| 3709 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 3710 | return 1; |
| 3711 | } |
| 3712 | if (PyObject_HasAttrString(obj, "keywords")) { |
| 3713 | int res; |
| 3714 | Py_ssize_t len; |
| 3715 | Py_ssize_t i; |
| 3716 | tmp = PyObject_GetAttrString(obj, "keywords"); |
| 3717 | if (tmp == NULL) goto failed; |
| 3718 | if (!PyList_Check(tmp)) { |
| 3719 | PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3720 | goto failed; |
| 3721 | } |
| 3722 | len = PyList_GET_SIZE(tmp); |
| 3723 | keywords = asdl_seq_new(len, arena); |
| 3724 | if (keywords == NULL) goto failed; |
| 3725 | for (i = 0; i < len; i++) { |
| 3726 | keyword_ty value; |
| 3727 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3728 | if (res != 0) goto failed; |
| 3729 | asdl_seq_SET(keywords, i, value); |
| 3730 | } |
| 3731 | Py_XDECREF(tmp); |
| 3732 | tmp = NULL; |
| 3733 | } else { |
| 3734 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 3735 | return 1; |
| 3736 | } |
| 3737 | if (PyObject_HasAttrString(obj, "starargs")) { |
| 3738 | int res; |
| 3739 | tmp = PyObject_GetAttrString(obj, "starargs"); |
| 3740 | if (tmp == NULL) goto failed; |
| 3741 | res = obj2ast_expr(tmp, &starargs, arena); |
| 3742 | if (res != 0) goto failed; |
| 3743 | Py_XDECREF(tmp); |
| 3744 | tmp = NULL; |
| 3745 | } else { |
| 3746 | starargs = NULL; |
| 3747 | } |
| 3748 | if (PyObject_HasAttrString(obj, "kwargs")) { |
| 3749 | int res; |
| 3750 | tmp = PyObject_GetAttrString(obj, "kwargs"); |
| 3751 | if (tmp == NULL) goto failed; |
| 3752 | res = obj2ast_expr(tmp, &kwargs, arena); |
| 3753 | if (res != 0) goto failed; |
| 3754 | Py_XDECREF(tmp); |
| 3755 | tmp = NULL; |
| 3756 | } else { |
| 3757 | kwargs = NULL; |
| 3758 | } |
| 3759 | if (PyObject_HasAttrString(obj, "body")) { |
| 3760 | int res; |
| 3761 | Py_ssize_t len; |
| 3762 | Py_ssize_t i; |
| 3763 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3764 | if (tmp == NULL) goto failed; |
| 3765 | if (!PyList_Check(tmp)) { |
| 3766 | PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3767 | goto failed; |
| 3768 | } |
| 3769 | len = PyList_GET_SIZE(tmp); |
| 3770 | body = asdl_seq_new(len, arena); |
| 3771 | if (body == NULL) goto failed; |
| 3772 | for (i = 0; i < len; i++) { |
| 3773 | stmt_ty value; |
| 3774 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3775 | if (res != 0) goto failed; |
| 3776 | asdl_seq_SET(body, i, value); |
| 3777 | } |
| 3778 | Py_XDECREF(tmp); |
| 3779 | tmp = NULL; |
| 3780 | } else { |
| 3781 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 3782 | return 1; |
| 3783 | } |
| 3784 | if (PyObject_HasAttrString(obj, "decorator_list")) { |
| 3785 | int res; |
| 3786 | Py_ssize_t len; |
| 3787 | Py_ssize_t i; |
| 3788 | tmp = PyObject_GetAttrString(obj, "decorator_list"); |
| 3789 | if (tmp == NULL) goto failed; |
| 3790 | if (!PyList_Check(tmp)) { |
| 3791 | PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3792 | goto failed; |
| 3793 | } |
| 3794 | len = PyList_GET_SIZE(tmp); |
| 3795 | decorator_list = asdl_seq_new(len, arena); |
| 3796 | if (decorator_list == NULL) goto failed; |
| 3797 | for (i = 0; i < len; i++) { |
| 3798 | expr_ty value; |
| 3799 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3800 | if (res != 0) goto failed; |
| 3801 | asdl_seq_SET(decorator_list, i, value); |
| 3802 | } |
| 3803 | Py_XDECREF(tmp); |
| 3804 | tmp = NULL; |
| 3805 | } else { |
| 3806 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 3807 | return 1; |
| 3808 | } |
| 3809 | *out = ClassDef(name, bases, keywords, starargs, kwargs, body, |
| 3810 | decorator_list, lineno, col_offset, arena); |
| 3811 | if (*out == NULL) goto failed; |
| 3812 | return 0; |
| 3813 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3814 | isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type); |
| 3815 | if (isinstance == -1) { |
| 3816 | return 1; |
| 3817 | } |
| 3818 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3819 | expr_ty value; |
| 3820 | |
| 3821 | if (PyObject_HasAttrString(obj, "value")) { |
| 3822 | int res; |
| 3823 | tmp = PyObject_GetAttrString(obj, "value"); |
| 3824 | if (tmp == NULL) goto failed; |
| 3825 | res = obj2ast_expr(tmp, &value, arena); |
| 3826 | if (res != 0) goto failed; |
| 3827 | Py_XDECREF(tmp); |
| 3828 | tmp = NULL; |
| 3829 | } else { |
| 3830 | value = NULL; |
| 3831 | } |
| 3832 | *out = Return(value, lineno, col_offset, arena); |
| 3833 | if (*out == NULL) goto failed; |
| 3834 | return 0; |
| 3835 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3836 | isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type); |
| 3837 | if (isinstance == -1) { |
| 3838 | return 1; |
| 3839 | } |
| 3840 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3841 | asdl_seq* targets; |
| 3842 | |
| 3843 | if (PyObject_HasAttrString(obj, "targets")) { |
| 3844 | int res; |
| 3845 | Py_ssize_t len; |
| 3846 | Py_ssize_t i; |
| 3847 | tmp = PyObject_GetAttrString(obj, "targets"); |
| 3848 | if (tmp == NULL) goto failed; |
| 3849 | if (!PyList_Check(tmp)) { |
| 3850 | PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3851 | goto failed; |
| 3852 | } |
| 3853 | len = PyList_GET_SIZE(tmp); |
| 3854 | targets = asdl_seq_new(len, arena); |
| 3855 | if (targets == NULL) goto failed; |
| 3856 | for (i = 0; i < len; i++) { |
| 3857 | expr_ty value; |
| 3858 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3859 | if (res != 0) goto failed; |
| 3860 | asdl_seq_SET(targets, i, value); |
| 3861 | } |
| 3862 | Py_XDECREF(tmp); |
| 3863 | tmp = NULL; |
| 3864 | } else { |
| 3865 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 3866 | return 1; |
| 3867 | } |
| 3868 | *out = Delete(targets, lineno, col_offset, arena); |
| 3869 | if (*out == NULL) goto failed; |
| 3870 | return 0; |
| 3871 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3872 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type); |
| 3873 | if (isinstance == -1) { |
| 3874 | return 1; |
| 3875 | } |
| 3876 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3877 | asdl_seq* targets; |
| 3878 | expr_ty value; |
| 3879 | |
| 3880 | if (PyObject_HasAttrString(obj, "targets")) { |
| 3881 | int res; |
| 3882 | Py_ssize_t len; |
| 3883 | Py_ssize_t i; |
| 3884 | tmp = PyObject_GetAttrString(obj, "targets"); |
| 3885 | if (tmp == NULL) goto failed; |
| 3886 | if (!PyList_Check(tmp)) { |
| 3887 | PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3888 | goto failed; |
| 3889 | } |
| 3890 | len = PyList_GET_SIZE(tmp); |
| 3891 | targets = asdl_seq_new(len, arena); |
| 3892 | if (targets == NULL) goto failed; |
| 3893 | for (i = 0; i < len; i++) { |
| 3894 | expr_ty value; |
| 3895 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3896 | if (res != 0) goto failed; |
| 3897 | asdl_seq_SET(targets, i, value); |
| 3898 | } |
| 3899 | Py_XDECREF(tmp); |
| 3900 | tmp = NULL; |
| 3901 | } else { |
| 3902 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 3903 | return 1; |
| 3904 | } |
| 3905 | if (PyObject_HasAttrString(obj, "value")) { |
| 3906 | int res; |
| 3907 | tmp = PyObject_GetAttrString(obj, "value"); |
| 3908 | if (tmp == NULL) goto failed; |
| 3909 | res = obj2ast_expr(tmp, &value, arena); |
| 3910 | if (res != 0) goto failed; |
| 3911 | Py_XDECREF(tmp); |
| 3912 | tmp = NULL; |
| 3913 | } else { |
| 3914 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 3915 | return 1; |
| 3916 | } |
| 3917 | *out = Assign(targets, value, lineno, col_offset, arena); |
| 3918 | if (*out == NULL) goto failed; |
| 3919 | return 0; |
| 3920 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3921 | isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type); |
| 3922 | if (isinstance == -1) { |
| 3923 | return 1; |
| 3924 | } |
| 3925 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3926 | expr_ty target; |
| 3927 | operator_ty op; |
| 3928 | expr_ty value; |
| 3929 | |
| 3930 | if (PyObject_HasAttrString(obj, "target")) { |
| 3931 | int res; |
| 3932 | tmp = PyObject_GetAttrString(obj, "target"); |
| 3933 | if (tmp == NULL) goto failed; |
| 3934 | res = obj2ast_expr(tmp, &target, arena); |
| 3935 | if (res != 0) goto failed; |
| 3936 | Py_XDECREF(tmp); |
| 3937 | tmp = NULL; |
| 3938 | } else { |
| 3939 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 3940 | return 1; |
| 3941 | } |
| 3942 | if (PyObject_HasAttrString(obj, "op")) { |
| 3943 | int res; |
| 3944 | tmp = PyObject_GetAttrString(obj, "op"); |
| 3945 | if (tmp == NULL) goto failed; |
| 3946 | res = obj2ast_operator(tmp, &op, arena); |
| 3947 | if (res != 0) goto failed; |
| 3948 | Py_XDECREF(tmp); |
| 3949 | tmp = NULL; |
| 3950 | } else { |
| 3951 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 3952 | return 1; |
| 3953 | } |
| 3954 | if (PyObject_HasAttrString(obj, "value")) { |
| 3955 | int res; |
| 3956 | tmp = PyObject_GetAttrString(obj, "value"); |
| 3957 | if (tmp == NULL) goto failed; |
| 3958 | res = obj2ast_expr(tmp, &value, arena); |
| 3959 | if (res != 0) goto failed; |
| 3960 | Py_XDECREF(tmp); |
| 3961 | tmp = NULL; |
| 3962 | } else { |
| 3963 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 3964 | return 1; |
| 3965 | } |
| 3966 | *out = AugAssign(target, op, value, lineno, col_offset, arena); |
| 3967 | if (*out == NULL) goto failed; |
| 3968 | return 0; |
| 3969 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3970 | isinstance = PyObject_IsInstance(obj, (PyObject*)For_type); |
| 3971 | if (isinstance == -1) { |
| 3972 | return 1; |
| 3973 | } |
| 3974 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3975 | expr_ty target; |
| 3976 | expr_ty iter; |
| 3977 | asdl_seq* body; |
| 3978 | asdl_seq* orelse; |
| 3979 | |
| 3980 | if (PyObject_HasAttrString(obj, "target")) { |
| 3981 | int res; |
| 3982 | tmp = PyObject_GetAttrString(obj, "target"); |
| 3983 | if (tmp == NULL) goto failed; |
| 3984 | res = obj2ast_expr(tmp, &target, arena); |
| 3985 | if (res != 0) goto failed; |
| 3986 | Py_XDECREF(tmp); |
| 3987 | tmp = NULL; |
| 3988 | } else { |
| 3989 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 3990 | return 1; |
| 3991 | } |
| 3992 | if (PyObject_HasAttrString(obj, "iter")) { |
| 3993 | int res; |
| 3994 | tmp = PyObject_GetAttrString(obj, "iter"); |
| 3995 | if (tmp == NULL) goto failed; |
| 3996 | res = obj2ast_expr(tmp, &iter, arena); |
| 3997 | if (res != 0) goto failed; |
| 3998 | Py_XDECREF(tmp); |
| 3999 | tmp = NULL; |
| 4000 | } else { |
| 4001 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 4002 | return 1; |
| 4003 | } |
| 4004 | if (PyObject_HasAttrString(obj, "body")) { |
| 4005 | int res; |
| 4006 | Py_ssize_t len; |
| 4007 | Py_ssize_t i; |
| 4008 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4009 | if (tmp == NULL) goto failed; |
| 4010 | if (!PyList_Check(tmp)) { |
| 4011 | PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4012 | goto failed; |
| 4013 | } |
| 4014 | len = PyList_GET_SIZE(tmp); |
| 4015 | body = asdl_seq_new(len, arena); |
| 4016 | if (body == NULL) goto failed; |
| 4017 | for (i = 0; i < len; i++) { |
| 4018 | stmt_ty value; |
| 4019 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4020 | if (res != 0) goto failed; |
| 4021 | asdl_seq_SET(body, i, value); |
| 4022 | } |
| 4023 | Py_XDECREF(tmp); |
| 4024 | tmp = NULL; |
| 4025 | } else { |
| 4026 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 4027 | return 1; |
| 4028 | } |
| 4029 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4030 | int res; |
| 4031 | Py_ssize_t len; |
| 4032 | Py_ssize_t i; |
| 4033 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4034 | if (tmp == NULL) goto failed; |
| 4035 | if (!PyList_Check(tmp)) { |
| 4036 | PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4037 | goto failed; |
| 4038 | } |
| 4039 | len = PyList_GET_SIZE(tmp); |
| 4040 | orelse = asdl_seq_new(len, arena); |
| 4041 | if (orelse == NULL) goto failed; |
| 4042 | for (i = 0; i < len; i++) { |
| 4043 | stmt_ty value; |
| 4044 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4045 | if (res != 0) goto failed; |
| 4046 | asdl_seq_SET(orelse, i, value); |
| 4047 | } |
| 4048 | Py_XDECREF(tmp); |
| 4049 | tmp = NULL; |
| 4050 | } else { |
| 4051 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 4052 | return 1; |
| 4053 | } |
| 4054 | *out = For(target, iter, body, orelse, lineno, col_offset, |
| 4055 | arena); |
| 4056 | if (*out == NULL) goto failed; |
| 4057 | return 0; |
| 4058 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4059 | isinstance = PyObject_IsInstance(obj, (PyObject*)While_type); |
| 4060 | if (isinstance == -1) { |
| 4061 | return 1; |
| 4062 | } |
| 4063 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4064 | expr_ty test; |
| 4065 | asdl_seq* body; |
| 4066 | asdl_seq* orelse; |
| 4067 | |
| 4068 | if (PyObject_HasAttrString(obj, "test")) { |
| 4069 | int res; |
| 4070 | tmp = PyObject_GetAttrString(obj, "test"); |
| 4071 | if (tmp == NULL) goto failed; |
| 4072 | res = obj2ast_expr(tmp, &test, arena); |
| 4073 | if (res != 0) goto failed; |
| 4074 | Py_XDECREF(tmp); |
| 4075 | tmp = NULL; |
| 4076 | } else { |
| 4077 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 4078 | return 1; |
| 4079 | } |
| 4080 | if (PyObject_HasAttrString(obj, "body")) { |
| 4081 | int res; |
| 4082 | Py_ssize_t len; |
| 4083 | Py_ssize_t i; |
| 4084 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4085 | if (tmp == NULL) goto failed; |
| 4086 | if (!PyList_Check(tmp)) { |
| 4087 | PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4088 | goto failed; |
| 4089 | } |
| 4090 | len = PyList_GET_SIZE(tmp); |
| 4091 | body = asdl_seq_new(len, arena); |
| 4092 | if (body == NULL) goto failed; |
| 4093 | for (i = 0; i < len; i++) { |
| 4094 | stmt_ty value; |
| 4095 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4096 | if (res != 0) goto failed; |
| 4097 | asdl_seq_SET(body, i, value); |
| 4098 | } |
| 4099 | Py_XDECREF(tmp); |
| 4100 | tmp = NULL; |
| 4101 | } else { |
| 4102 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 4103 | return 1; |
| 4104 | } |
| 4105 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4106 | int res; |
| 4107 | Py_ssize_t len; |
| 4108 | Py_ssize_t i; |
| 4109 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4110 | if (tmp == NULL) goto failed; |
| 4111 | if (!PyList_Check(tmp)) { |
| 4112 | PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4113 | goto failed; |
| 4114 | } |
| 4115 | len = PyList_GET_SIZE(tmp); |
| 4116 | orelse = asdl_seq_new(len, arena); |
| 4117 | if (orelse == NULL) goto failed; |
| 4118 | for (i = 0; i < len; i++) { |
| 4119 | stmt_ty value; |
| 4120 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4121 | if (res != 0) goto failed; |
| 4122 | asdl_seq_SET(orelse, i, value); |
| 4123 | } |
| 4124 | Py_XDECREF(tmp); |
| 4125 | tmp = NULL; |
| 4126 | } else { |
| 4127 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 4128 | return 1; |
| 4129 | } |
| 4130 | *out = While(test, body, orelse, lineno, col_offset, arena); |
| 4131 | if (*out == NULL) goto failed; |
| 4132 | return 0; |
| 4133 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4134 | isinstance = PyObject_IsInstance(obj, (PyObject*)If_type); |
| 4135 | if (isinstance == -1) { |
| 4136 | return 1; |
| 4137 | } |
| 4138 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4139 | expr_ty test; |
| 4140 | asdl_seq* body; |
| 4141 | asdl_seq* orelse; |
| 4142 | |
| 4143 | if (PyObject_HasAttrString(obj, "test")) { |
| 4144 | int res; |
| 4145 | tmp = PyObject_GetAttrString(obj, "test"); |
| 4146 | if (tmp == NULL) goto failed; |
| 4147 | res = obj2ast_expr(tmp, &test, arena); |
| 4148 | if (res != 0) goto failed; |
| 4149 | Py_XDECREF(tmp); |
| 4150 | tmp = NULL; |
| 4151 | } else { |
| 4152 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 4153 | return 1; |
| 4154 | } |
| 4155 | if (PyObject_HasAttrString(obj, "body")) { |
| 4156 | int res; |
| 4157 | Py_ssize_t len; |
| 4158 | Py_ssize_t i; |
| 4159 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4160 | if (tmp == NULL) goto failed; |
| 4161 | if (!PyList_Check(tmp)) { |
| 4162 | PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4163 | goto failed; |
| 4164 | } |
| 4165 | len = PyList_GET_SIZE(tmp); |
| 4166 | body = asdl_seq_new(len, arena); |
| 4167 | if (body == NULL) goto failed; |
| 4168 | for (i = 0; i < len; i++) { |
| 4169 | stmt_ty value; |
| 4170 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4171 | if (res != 0) goto failed; |
| 4172 | asdl_seq_SET(body, i, value); |
| 4173 | } |
| 4174 | Py_XDECREF(tmp); |
| 4175 | tmp = NULL; |
| 4176 | } else { |
| 4177 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 4178 | return 1; |
| 4179 | } |
| 4180 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4181 | int res; |
| 4182 | Py_ssize_t len; |
| 4183 | Py_ssize_t i; |
| 4184 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4185 | if (tmp == NULL) goto failed; |
| 4186 | if (!PyList_Check(tmp)) { |
| 4187 | PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4188 | goto failed; |
| 4189 | } |
| 4190 | len = PyList_GET_SIZE(tmp); |
| 4191 | orelse = asdl_seq_new(len, arena); |
| 4192 | if (orelse == NULL) goto failed; |
| 4193 | for (i = 0; i < len; i++) { |
| 4194 | stmt_ty value; |
| 4195 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4196 | if (res != 0) goto failed; |
| 4197 | asdl_seq_SET(orelse, i, value); |
| 4198 | } |
| 4199 | Py_XDECREF(tmp); |
| 4200 | tmp = NULL; |
| 4201 | } else { |
| 4202 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 4203 | return 1; |
| 4204 | } |
| 4205 | *out = If(test, body, orelse, lineno, col_offset, arena); |
| 4206 | if (*out == NULL) goto failed; |
| 4207 | return 0; |
| 4208 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4209 | isinstance = PyObject_IsInstance(obj, (PyObject*)With_type); |
| 4210 | if (isinstance == -1) { |
| 4211 | return 1; |
| 4212 | } |
| 4213 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4214 | expr_ty context_expr; |
| 4215 | expr_ty optional_vars; |
| 4216 | asdl_seq* body; |
| 4217 | |
| 4218 | if (PyObject_HasAttrString(obj, "context_expr")) { |
| 4219 | int res; |
| 4220 | tmp = PyObject_GetAttrString(obj, "context_expr"); |
| 4221 | if (tmp == NULL) goto failed; |
| 4222 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 4223 | if (res != 0) goto failed; |
| 4224 | Py_XDECREF(tmp); |
| 4225 | tmp = NULL; |
| 4226 | } else { |
| 4227 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from With"); |
| 4228 | return 1; |
| 4229 | } |
| 4230 | if (PyObject_HasAttrString(obj, "optional_vars")) { |
| 4231 | int res; |
| 4232 | tmp = PyObject_GetAttrString(obj, "optional_vars"); |
| 4233 | if (tmp == NULL) goto failed; |
| 4234 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 4235 | if (res != 0) goto failed; |
| 4236 | Py_XDECREF(tmp); |
| 4237 | tmp = NULL; |
| 4238 | } else { |
| 4239 | optional_vars = NULL; |
| 4240 | } |
| 4241 | if (PyObject_HasAttrString(obj, "body")) { |
| 4242 | int res; |
| 4243 | Py_ssize_t len; |
| 4244 | Py_ssize_t i; |
| 4245 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4246 | if (tmp == NULL) goto failed; |
| 4247 | if (!PyList_Check(tmp)) { |
| 4248 | PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4249 | goto failed; |
| 4250 | } |
| 4251 | len = PyList_GET_SIZE(tmp); |
| 4252 | body = asdl_seq_new(len, arena); |
| 4253 | if (body == NULL) goto failed; |
| 4254 | for (i = 0; i < len; i++) { |
| 4255 | stmt_ty value; |
| 4256 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4257 | if (res != 0) goto failed; |
| 4258 | asdl_seq_SET(body, i, value); |
| 4259 | } |
| 4260 | Py_XDECREF(tmp); |
| 4261 | tmp = NULL; |
| 4262 | } else { |
| 4263 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 4264 | return 1; |
| 4265 | } |
| 4266 | *out = With(context_expr, optional_vars, body, lineno, |
| 4267 | col_offset, arena); |
| 4268 | if (*out == NULL) goto failed; |
| 4269 | return 0; |
| 4270 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4271 | isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type); |
| 4272 | if (isinstance == -1) { |
| 4273 | return 1; |
| 4274 | } |
| 4275 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4276 | expr_ty exc; |
| 4277 | expr_ty cause; |
| 4278 | |
| 4279 | if (PyObject_HasAttrString(obj, "exc")) { |
| 4280 | int res; |
| 4281 | tmp = PyObject_GetAttrString(obj, "exc"); |
| 4282 | if (tmp == NULL) goto failed; |
| 4283 | res = obj2ast_expr(tmp, &exc, arena); |
| 4284 | if (res != 0) goto failed; |
| 4285 | Py_XDECREF(tmp); |
| 4286 | tmp = NULL; |
| 4287 | } else { |
| 4288 | exc = NULL; |
| 4289 | } |
| 4290 | if (PyObject_HasAttrString(obj, "cause")) { |
| 4291 | int res; |
| 4292 | tmp = PyObject_GetAttrString(obj, "cause"); |
| 4293 | if (tmp == NULL) goto failed; |
| 4294 | res = obj2ast_expr(tmp, &cause, arena); |
| 4295 | if (res != 0) goto failed; |
| 4296 | Py_XDECREF(tmp); |
| 4297 | tmp = NULL; |
| 4298 | } else { |
| 4299 | cause = NULL; |
| 4300 | } |
| 4301 | *out = Raise(exc, cause, lineno, col_offset, arena); |
| 4302 | if (*out == NULL) goto failed; |
| 4303 | return 0; |
| 4304 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4305 | isinstance = PyObject_IsInstance(obj, (PyObject*)TryExcept_type); |
| 4306 | if (isinstance == -1) { |
| 4307 | return 1; |
| 4308 | } |
| 4309 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4310 | asdl_seq* body; |
| 4311 | asdl_seq* handlers; |
| 4312 | asdl_seq* orelse; |
| 4313 | |
| 4314 | if (PyObject_HasAttrString(obj, "body")) { |
| 4315 | int res; |
| 4316 | Py_ssize_t len; |
| 4317 | Py_ssize_t i; |
| 4318 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4319 | if (tmp == NULL) goto failed; |
| 4320 | if (!PyList_Check(tmp)) { |
| 4321 | PyErr_Format(PyExc_TypeError, "TryExcept field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4322 | goto failed; |
| 4323 | } |
| 4324 | len = PyList_GET_SIZE(tmp); |
| 4325 | body = asdl_seq_new(len, arena); |
| 4326 | if (body == NULL) goto failed; |
| 4327 | for (i = 0; i < len; i++) { |
| 4328 | stmt_ty value; |
| 4329 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4330 | if (res != 0) goto failed; |
| 4331 | asdl_seq_SET(body, i, value); |
| 4332 | } |
| 4333 | Py_XDECREF(tmp); |
| 4334 | tmp = NULL; |
| 4335 | } else { |
| 4336 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryExcept"); |
| 4337 | return 1; |
| 4338 | } |
| 4339 | if (PyObject_HasAttrString(obj, "handlers")) { |
| 4340 | int res; |
| 4341 | Py_ssize_t len; |
| 4342 | Py_ssize_t i; |
| 4343 | tmp = PyObject_GetAttrString(obj, "handlers"); |
| 4344 | if (tmp == NULL) goto failed; |
| 4345 | if (!PyList_Check(tmp)) { |
| 4346 | PyErr_Format(PyExc_TypeError, "TryExcept field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4347 | goto failed; |
| 4348 | } |
| 4349 | len = PyList_GET_SIZE(tmp); |
| 4350 | handlers = asdl_seq_new(len, arena); |
| 4351 | if (handlers == NULL) goto failed; |
| 4352 | for (i = 0; i < len; i++) { |
| 4353 | excepthandler_ty value; |
| 4354 | res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4355 | if (res != 0) goto failed; |
| 4356 | asdl_seq_SET(handlers, i, value); |
| 4357 | } |
| 4358 | Py_XDECREF(tmp); |
| 4359 | tmp = NULL; |
| 4360 | } else { |
| 4361 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from TryExcept"); |
| 4362 | return 1; |
| 4363 | } |
| 4364 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4365 | int res; |
| 4366 | Py_ssize_t len; |
| 4367 | Py_ssize_t i; |
| 4368 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4369 | if (tmp == NULL) goto failed; |
| 4370 | if (!PyList_Check(tmp)) { |
| 4371 | PyErr_Format(PyExc_TypeError, "TryExcept field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4372 | goto failed; |
| 4373 | } |
| 4374 | len = PyList_GET_SIZE(tmp); |
| 4375 | orelse = asdl_seq_new(len, arena); |
| 4376 | if (orelse == NULL) goto failed; |
| 4377 | for (i = 0; i < len; i++) { |
| 4378 | stmt_ty value; |
| 4379 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4380 | if (res != 0) goto failed; |
| 4381 | asdl_seq_SET(orelse, i, value); |
| 4382 | } |
| 4383 | Py_XDECREF(tmp); |
| 4384 | tmp = NULL; |
| 4385 | } else { |
| 4386 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from TryExcept"); |
| 4387 | return 1; |
| 4388 | } |
| 4389 | *out = TryExcept(body, handlers, orelse, lineno, col_offset, |
| 4390 | arena); |
| 4391 | if (*out == NULL) goto failed; |
| 4392 | return 0; |
| 4393 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4394 | isinstance = PyObject_IsInstance(obj, (PyObject*)TryFinally_type); |
| 4395 | if (isinstance == -1) { |
| 4396 | return 1; |
| 4397 | } |
| 4398 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4399 | asdl_seq* body; |
| 4400 | asdl_seq* finalbody; |
| 4401 | |
| 4402 | if (PyObject_HasAttrString(obj, "body")) { |
| 4403 | int res; |
| 4404 | Py_ssize_t len; |
| 4405 | Py_ssize_t i; |
| 4406 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4407 | if (tmp == NULL) goto failed; |
| 4408 | if (!PyList_Check(tmp)) { |
| 4409 | PyErr_Format(PyExc_TypeError, "TryFinally field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4410 | goto failed; |
| 4411 | } |
| 4412 | len = PyList_GET_SIZE(tmp); |
| 4413 | body = asdl_seq_new(len, arena); |
| 4414 | if (body == NULL) goto failed; |
| 4415 | for (i = 0; i < len; i++) { |
| 4416 | stmt_ty value; |
| 4417 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4418 | if (res != 0) goto failed; |
| 4419 | asdl_seq_SET(body, i, value); |
| 4420 | } |
| 4421 | Py_XDECREF(tmp); |
| 4422 | tmp = NULL; |
| 4423 | } else { |
| 4424 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryFinally"); |
| 4425 | return 1; |
| 4426 | } |
| 4427 | if (PyObject_HasAttrString(obj, "finalbody")) { |
| 4428 | int res; |
| 4429 | Py_ssize_t len; |
| 4430 | Py_ssize_t i; |
| 4431 | tmp = PyObject_GetAttrString(obj, "finalbody"); |
| 4432 | if (tmp == NULL) goto failed; |
| 4433 | if (!PyList_Check(tmp)) { |
| 4434 | PyErr_Format(PyExc_TypeError, "TryFinally field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4435 | goto failed; |
| 4436 | } |
| 4437 | len = PyList_GET_SIZE(tmp); |
| 4438 | finalbody = asdl_seq_new(len, arena); |
| 4439 | if (finalbody == NULL) goto failed; |
| 4440 | for (i = 0; i < len; i++) { |
| 4441 | stmt_ty value; |
| 4442 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4443 | if (res != 0) goto failed; |
| 4444 | asdl_seq_SET(finalbody, i, value); |
| 4445 | } |
| 4446 | Py_XDECREF(tmp); |
| 4447 | tmp = NULL; |
| 4448 | } else { |
| 4449 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from TryFinally"); |
| 4450 | return 1; |
| 4451 | } |
| 4452 | *out = TryFinally(body, finalbody, lineno, col_offset, arena); |
| 4453 | if (*out == NULL) goto failed; |
| 4454 | return 0; |
| 4455 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4456 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type); |
| 4457 | if (isinstance == -1) { |
| 4458 | return 1; |
| 4459 | } |
| 4460 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4461 | expr_ty test; |
| 4462 | expr_ty msg; |
| 4463 | |
| 4464 | if (PyObject_HasAttrString(obj, "test")) { |
| 4465 | int res; |
| 4466 | tmp = PyObject_GetAttrString(obj, "test"); |
| 4467 | if (tmp == NULL) goto failed; |
| 4468 | res = obj2ast_expr(tmp, &test, arena); |
| 4469 | if (res != 0) goto failed; |
| 4470 | Py_XDECREF(tmp); |
| 4471 | tmp = NULL; |
| 4472 | } else { |
| 4473 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 4474 | return 1; |
| 4475 | } |
| 4476 | if (PyObject_HasAttrString(obj, "msg")) { |
| 4477 | int res; |
| 4478 | tmp = PyObject_GetAttrString(obj, "msg"); |
| 4479 | if (tmp == NULL) goto failed; |
| 4480 | res = obj2ast_expr(tmp, &msg, arena); |
| 4481 | if (res != 0) goto failed; |
| 4482 | Py_XDECREF(tmp); |
| 4483 | tmp = NULL; |
| 4484 | } else { |
| 4485 | msg = NULL; |
| 4486 | } |
| 4487 | *out = Assert(test, msg, lineno, col_offset, arena); |
| 4488 | if (*out == NULL) goto failed; |
| 4489 | return 0; |
| 4490 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4491 | isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type); |
| 4492 | if (isinstance == -1) { |
| 4493 | return 1; |
| 4494 | } |
| 4495 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4496 | asdl_seq* names; |
| 4497 | |
| 4498 | if (PyObject_HasAttrString(obj, "names")) { |
| 4499 | int res; |
| 4500 | Py_ssize_t len; |
| 4501 | Py_ssize_t i; |
| 4502 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4503 | if (tmp == NULL) goto failed; |
| 4504 | if (!PyList_Check(tmp)) { |
| 4505 | PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4506 | goto failed; |
| 4507 | } |
| 4508 | len = PyList_GET_SIZE(tmp); |
| 4509 | names = asdl_seq_new(len, arena); |
| 4510 | if (names == NULL) goto failed; |
| 4511 | for (i = 0; i < len; i++) { |
| 4512 | alias_ty value; |
| 4513 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4514 | if (res != 0) goto failed; |
| 4515 | asdl_seq_SET(names, i, value); |
| 4516 | } |
| 4517 | Py_XDECREF(tmp); |
| 4518 | tmp = NULL; |
| 4519 | } else { |
| 4520 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 4521 | return 1; |
| 4522 | } |
| 4523 | *out = Import(names, lineno, col_offset, arena); |
| 4524 | if (*out == NULL) goto failed; |
| 4525 | return 0; |
| 4526 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4527 | isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type); |
| 4528 | if (isinstance == -1) { |
| 4529 | return 1; |
| 4530 | } |
| 4531 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4532 | identifier module; |
| 4533 | asdl_seq* names; |
| 4534 | int level; |
| 4535 | |
| 4536 | if (PyObject_HasAttrString(obj, "module")) { |
| 4537 | int res; |
| 4538 | tmp = PyObject_GetAttrString(obj, "module"); |
| 4539 | if (tmp == NULL) goto failed; |
| 4540 | res = obj2ast_identifier(tmp, &module, arena); |
| 4541 | if (res != 0) goto failed; |
| 4542 | Py_XDECREF(tmp); |
| 4543 | tmp = NULL; |
| 4544 | } else { |
Benjamin Peterson | 78565b2 | 2009-06-28 19:19:51 +0000 | [diff] [blame] | 4545 | module = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4546 | } |
| 4547 | if (PyObject_HasAttrString(obj, "names")) { |
| 4548 | int res; |
| 4549 | Py_ssize_t len; |
| 4550 | Py_ssize_t i; |
| 4551 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4552 | if (tmp == NULL) goto failed; |
| 4553 | if (!PyList_Check(tmp)) { |
| 4554 | PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4555 | goto failed; |
| 4556 | } |
| 4557 | len = PyList_GET_SIZE(tmp); |
| 4558 | names = asdl_seq_new(len, arena); |
| 4559 | if (names == NULL) goto failed; |
| 4560 | for (i = 0; i < len; i++) { |
| 4561 | alias_ty value; |
| 4562 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4563 | if (res != 0) goto failed; |
| 4564 | asdl_seq_SET(names, i, value); |
| 4565 | } |
| 4566 | Py_XDECREF(tmp); |
| 4567 | tmp = NULL; |
| 4568 | } else { |
| 4569 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 4570 | return 1; |
| 4571 | } |
| 4572 | if (PyObject_HasAttrString(obj, "level")) { |
| 4573 | int res; |
| 4574 | tmp = PyObject_GetAttrString(obj, "level"); |
| 4575 | if (tmp == NULL) goto failed; |
| 4576 | res = obj2ast_int(tmp, &level, arena); |
| 4577 | if (res != 0) goto failed; |
| 4578 | Py_XDECREF(tmp); |
| 4579 | tmp = NULL; |
| 4580 | } else { |
| 4581 | level = 0; |
| 4582 | } |
| 4583 | *out = ImportFrom(module, names, level, lineno, col_offset, |
| 4584 | arena); |
| 4585 | if (*out == NULL) goto failed; |
| 4586 | return 0; |
| 4587 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4588 | isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type); |
| 4589 | if (isinstance == -1) { |
| 4590 | return 1; |
| 4591 | } |
| 4592 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4593 | asdl_seq* names; |
| 4594 | |
| 4595 | if (PyObject_HasAttrString(obj, "names")) { |
| 4596 | int res; |
| 4597 | Py_ssize_t len; |
| 4598 | Py_ssize_t i; |
| 4599 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4600 | if (tmp == NULL) goto failed; |
| 4601 | if (!PyList_Check(tmp)) { |
| 4602 | PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4603 | goto failed; |
| 4604 | } |
| 4605 | len = PyList_GET_SIZE(tmp); |
| 4606 | names = asdl_seq_new(len, arena); |
| 4607 | if (names == NULL) goto failed; |
| 4608 | for (i = 0; i < len; i++) { |
| 4609 | identifier value; |
| 4610 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4611 | if (res != 0) goto failed; |
| 4612 | asdl_seq_SET(names, i, value); |
| 4613 | } |
| 4614 | Py_XDECREF(tmp); |
| 4615 | tmp = NULL; |
| 4616 | } else { |
| 4617 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 4618 | return 1; |
| 4619 | } |
| 4620 | *out = Global(names, lineno, col_offset, arena); |
| 4621 | if (*out == NULL) goto failed; |
| 4622 | return 0; |
| 4623 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4624 | isinstance = PyObject_IsInstance(obj, (PyObject*)Nonlocal_type); |
| 4625 | if (isinstance == -1) { |
| 4626 | return 1; |
| 4627 | } |
| 4628 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4629 | asdl_seq* names; |
| 4630 | |
| 4631 | if (PyObject_HasAttrString(obj, "names")) { |
| 4632 | int res; |
| 4633 | Py_ssize_t len; |
| 4634 | Py_ssize_t i; |
| 4635 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4636 | if (tmp == NULL) goto failed; |
| 4637 | if (!PyList_Check(tmp)) { |
| 4638 | PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4639 | goto failed; |
| 4640 | } |
| 4641 | len = PyList_GET_SIZE(tmp); |
| 4642 | names = asdl_seq_new(len, arena); |
| 4643 | if (names == NULL) goto failed; |
| 4644 | for (i = 0; i < len; i++) { |
| 4645 | identifier value; |
| 4646 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4647 | if (res != 0) goto failed; |
| 4648 | asdl_seq_SET(names, i, value); |
| 4649 | } |
| 4650 | Py_XDECREF(tmp); |
| 4651 | tmp = NULL; |
| 4652 | } else { |
| 4653 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 4654 | return 1; |
| 4655 | } |
| 4656 | *out = Nonlocal(names, lineno, col_offset, arena); |
| 4657 | if (*out == NULL) goto failed; |
| 4658 | return 0; |
| 4659 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4660 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type); |
| 4661 | if (isinstance == -1) { |
| 4662 | return 1; |
| 4663 | } |
| 4664 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4665 | expr_ty value; |
| 4666 | |
| 4667 | if (PyObject_HasAttrString(obj, "value")) { |
| 4668 | int res; |
| 4669 | tmp = PyObject_GetAttrString(obj, "value"); |
| 4670 | if (tmp == NULL) goto failed; |
| 4671 | res = obj2ast_expr(tmp, &value, arena); |
| 4672 | if (res != 0) goto failed; |
| 4673 | Py_XDECREF(tmp); |
| 4674 | tmp = NULL; |
| 4675 | } else { |
| 4676 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 4677 | return 1; |
| 4678 | } |
| 4679 | *out = Expr(value, lineno, col_offset, arena); |
| 4680 | if (*out == NULL) goto failed; |
| 4681 | return 0; |
| 4682 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4683 | isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type); |
| 4684 | if (isinstance == -1) { |
| 4685 | return 1; |
| 4686 | } |
| 4687 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4688 | |
| 4689 | *out = Pass(lineno, col_offset, arena); |
| 4690 | if (*out == NULL) goto failed; |
| 4691 | return 0; |
| 4692 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4693 | isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type); |
| 4694 | if (isinstance == -1) { |
| 4695 | return 1; |
| 4696 | } |
| 4697 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4698 | |
| 4699 | *out = Break(lineno, col_offset, arena); |
| 4700 | if (*out == NULL) goto failed; |
| 4701 | return 0; |
| 4702 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4703 | isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type); |
| 4704 | if (isinstance == -1) { |
| 4705 | return 1; |
| 4706 | } |
| 4707 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4708 | |
| 4709 | *out = Continue(lineno, col_offset, arena); |
| 4710 | if (*out == NULL) goto failed; |
| 4711 | return 0; |
| 4712 | } |
| 4713 | |
| 4714 | tmp = PyObject_Repr(obj); |
| 4715 | if (tmp == NULL) goto failed; |
Christian Heimes | 72b710a | 2008-05-26 13:28:38 +0000 | [diff] [blame] | 4716 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %.400s", PyBytes_AS_STRING(tmp)); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4717 | failed: |
| 4718 | Py_XDECREF(tmp); |
| 4719 | return 1; |
| 4720 | } |
| 4721 | |
| 4722 | int |
| 4723 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 4724 | { |
| 4725 | PyObject* tmp = NULL; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4726 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4727 | |
| 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 | 0496c9e | 2009-12-13 01:24:58 +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 | 0496c9e | 2009-12-13 01:24:58 +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 | 0496c9e | 2009-12-13 01:24:58 +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 | 0496c9e | 2009-12-13 01:24:58 +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 | 0496c9e | 2009-12-13 01:24:58 +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 | 0496c9e | 2009-12-13 01:24:58 +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 | 0496c9e | 2009-12-13 01:24:58 +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 | 0496c9e | 2009-12-13 01:24:58 +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 | 0496c9e | 2009-12-13 01:24:58 +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 | 0496c9e | 2009-12-13 01:24:58 +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 | 0496c9e | 2009-12-13 01:24:58 +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 | 0496c9e | 2009-12-13 01:24:58 +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 | 0496c9e | 2009-12-13 01:24:58 +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 | 0496c9e | 2009-12-13 01:24:58 +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 | 0496c9e | 2009-12-13 01:24:58 +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 | 0496c9e | 2009-12-13 01:24:58 +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 | 0496c9e | 2009-12-13 01:24:58 +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 | 0496c9e | 2009-12-13 01:24:58 +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 | 0496c9e | 2009-12-13 01:24:58 +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 | 0496c9e | 2009-12-13 01:24:58 +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 | 0496c9e | 2009-12-13 01:24:58 +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 | 0496c9e | 2009-12-13 01:24:58 +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 | 0496c9e | 2009-12-13 01:24:58 +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 | 0496c9e | 2009-12-13 01:24:58 +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 | |
| 5832 | tmp = PyObject_Repr(obj); |
| 5833 | if (tmp == NULL) goto failed; |
Christian Heimes | 72b710a | 2008-05-26 13:28:38 +0000 | [diff] [blame] | 5834 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %.400s", PyBytes_AS_STRING(tmp)); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5835 | failed: |
| 5836 | Py_XDECREF(tmp); |
| 5837 | return 1; |
| 5838 | } |
| 5839 | |
| 5840 | int |
| 5841 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 5842 | { |
| 5843 | PyObject* tmp = NULL; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5844 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5845 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5846 | isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); |
| 5847 | if (isinstance == -1) { |
| 5848 | return 1; |
| 5849 | } |
| 5850 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5851 | *out = Load; |
| 5852 | return 0; |
| 5853 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5854 | isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type); |
| 5855 | if (isinstance == -1) { |
| 5856 | return 1; |
| 5857 | } |
| 5858 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5859 | *out = Store; |
| 5860 | return 0; |
| 5861 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5862 | isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type); |
| 5863 | if (isinstance == -1) { |
| 5864 | return 1; |
| 5865 | } |
| 5866 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5867 | *out = Del; |
| 5868 | return 0; |
| 5869 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5870 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type); |
| 5871 | if (isinstance == -1) { |
| 5872 | return 1; |
| 5873 | } |
| 5874 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5875 | *out = AugLoad; |
| 5876 | return 0; |
| 5877 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5878 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type); |
| 5879 | if (isinstance == -1) { |
| 5880 | return 1; |
| 5881 | } |
| 5882 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5883 | *out = AugStore; |
| 5884 | return 0; |
| 5885 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5886 | isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type); |
| 5887 | if (isinstance == -1) { |
| 5888 | return 1; |
| 5889 | } |
| 5890 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5891 | *out = Param; |
| 5892 | return 0; |
| 5893 | } |
| 5894 | |
| 5895 | tmp = PyObject_Repr(obj); |
| 5896 | if (tmp == NULL) goto failed; |
Christian Heimes | 72b710a | 2008-05-26 13:28:38 +0000 | [diff] [blame] | 5897 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %.400s", PyBytes_AS_STRING(tmp)); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5898 | failed: |
| 5899 | Py_XDECREF(tmp); |
| 5900 | return 1; |
| 5901 | } |
| 5902 | |
| 5903 | int |
| 5904 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
| 5905 | { |
| 5906 | PyObject* tmp = NULL; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5907 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5908 | |
| 5909 | |
| 5910 | if (obj == Py_None) { |
| 5911 | *out = NULL; |
| 5912 | return 0; |
| 5913 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5914 | isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type); |
| 5915 | if (isinstance == -1) { |
| 5916 | return 1; |
| 5917 | } |
| 5918 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5919 | expr_ty lower; |
| 5920 | expr_ty upper; |
| 5921 | expr_ty step; |
| 5922 | |
| 5923 | if (PyObject_HasAttrString(obj, "lower")) { |
| 5924 | int res; |
| 5925 | tmp = PyObject_GetAttrString(obj, "lower"); |
| 5926 | if (tmp == NULL) goto failed; |
| 5927 | res = obj2ast_expr(tmp, &lower, arena); |
| 5928 | if (res != 0) goto failed; |
| 5929 | Py_XDECREF(tmp); |
| 5930 | tmp = NULL; |
| 5931 | } else { |
| 5932 | lower = NULL; |
| 5933 | } |
| 5934 | if (PyObject_HasAttrString(obj, "upper")) { |
| 5935 | int res; |
| 5936 | tmp = PyObject_GetAttrString(obj, "upper"); |
| 5937 | if (tmp == NULL) goto failed; |
| 5938 | res = obj2ast_expr(tmp, &upper, arena); |
| 5939 | if (res != 0) goto failed; |
| 5940 | Py_XDECREF(tmp); |
| 5941 | tmp = NULL; |
| 5942 | } else { |
| 5943 | upper = NULL; |
| 5944 | } |
| 5945 | if (PyObject_HasAttrString(obj, "step")) { |
| 5946 | int res; |
| 5947 | tmp = PyObject_GetAttrString(obj, "step"); |
| 5948 | if (tmp == NULL) goto failed; |
| 5949 | res = obj2ast_expr(tmp, &step, arena); |
| 5950 | if (res != 0) goto failed; |
| 5951 | Py_XDECREF(tmp); |
| 5952 | tmp = NULL; |
| 5953 | } else { |
| 5954 | step = NULL; |
| 5955 | } |
| 5956 | *out = Slice(lower, upper, step, arena); |
| 5957 | if (*out == NULL) goto failed; |
| 5958 | return 0; |
| 5959 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5960 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type); |
| 5961 | if (isinstance == -1) { |
| 5962 | return 1; |
| 5963 | } |
| 5964 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5965 | asdl_seq* dims; |
| 5966 | |
| 5967 | if (PyObject_HasAttrString(obj, "dims")) { |
| 5968 | int res; |
| 5969 | Py_ssize_t len; |
| 5970 | Py_ssize_t i; |
| 5971 | tmp = PyObject_GetAttrString(obj, "dims"); |
| 5972 | if (tmp == NULL) goto failed; |
| 5973 | if (!PyList_Check(tmp)) { |
| 5974 | PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5975 | goto failed; |
| 5976 | } |
| 5977 | len = PyList_GET_SIZE(tmp); |
| 5978 | dims = asdl_seq_new(len, arena); |
| 5979 | if (dims == NULL) goto failed; |
| 5980 | for (i = 0; i < len; i++) { |
| 5981 | slice_ty value; |
| 5982 | res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5983 | if (res != 0) goto failed; |
| 5984 | asdl_seq_SET(dims, i, value); |
| 5985 | } |
| 5986 | Py_XDECREF(tmp); |
| 5987 | tmp = NULL; |
| 5988 | } else { |
| 5989 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
| 5990 | return 1; |
| 5991 | } |
| 5992 | *out = ExtSlice(dims, arena); |
| 5993 | if (*out == NULL) goto failed; |
| 5994 | return 0; |
| 5995 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5996 | isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type); |
| 5997 | if (isinstance == -1) { |
| 5998 | return 1; |
| 5999 | } |
| 6000 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6001 | expr_ty value; |
| 6002 | |
| 6003 | if (PyObject_HasAttrString(obj, "value")) { |
| 6004 | int res; |
| 6005 | tmp = PyObject_GetAttrString(obj, "value"); |
| 6006 | if (tmp == NULL) goto failed; |
| 6007 | res = obj2ast_expr(tmp, &value, arena); |
| 6008 | if (res != 0) goto failed; |
| 6009 | Py_XDECREF(tmp); |
| 6010 | tmp = NULL; |
| 6011 | } else { |
| 6012 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
| 6013 | return 1; |
| 6014 | } |
| 6015 | *out = Index(value, arena); |
| 6016 | if (*out == NULL) goto failed; |
| 6017 | return 0; |
| 6018 | } |
| 6019 | |
| 6020 | tmp = PyObject_Repr(obj); |
| 6021 | if (tmp == NULL) goto failed; |
Christian Heimes | 72b710a | 2008-05-26 13:28:38 +0000 | [diff] [blame] | 6022 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %.400s", PyBytes_AS_STRING(tmp)); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6023 | failed: |
| 6024 | Py_XDECREF(tmp); |
| 6025 | return 1; |
| 6026 | } |
| 6027 | |
| 6028 | int |
| 6029 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 6030 | { |
| 6031 | PyObject* tmp = NULL; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6032 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6033 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6034 | isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); |
| 6035 | if (isinstance == -1) { |
| 6036 | return 1; |
| 6037 | } |
| 6038 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6039 | *out = And; |
| 6040 | return 0; |
| 6041 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6042 | isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type); |
| 6043 | if (isinstance == -1) { |
| 6044 | return 1; |
| 6045 | } |
| 6046 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6047 | *out = Or; |
| 6048 | return 0; |
| 6049 | } |
| 6050 | |
| 6051 | tmp = PyObject_Repr(obj); |
| 6052 | if (tmp == NULL) goto failed; |
Christian Heimes | 72b710a | 2008-05-26 13:28:38 +0000 | [diff] [blame] | 6053 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %.400s", PyBytes_AS_STRING(tmp)); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6054 | failed: |
| 6055 | Py_XDECREF(tmp); |
| 6056 | return 1; |
| 6057 | } |
| 6058 | |
| 6059 | int |
| 6060 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 6061 | { |
| 6062 | PyObject* tmp = NULL; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6063 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6064 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6065 | isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); |
| 6066 | if (isinstance == -1) { |
| 6067 | return 1; |
| 6068 | } |
| 6069 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6070 | *out = Add; |
| 6071 | return 0; |
| 6072 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6073 | isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type); |
| 6074 | if (isinstance == -1) { |
| 6075 | return 1; |
| 6076 | } |
| 6077 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6078 | *out = Sub; |
| 6079 | return 0; |
| 6080 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6081 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type); |
| 6082 | if (isinstance == -1) { |
| 6083 | return 1; |
| 6084 | } |
| 6085 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6086 | *out = Mult; |
| 6087 | return 0; |
| 6088 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6089 | isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type); |
| 6090 | if (isinstance == -1) { |
| 6091 | return 1; |
| 6092 | } |
| 6093 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6094 | *out = Div; |
| 6095 | return 0; |
| 6096 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6097 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type); |
| 6098 | if (isinstance == -1) { |
| 6099 | return 1; |
| 6100 | } |
| 6101 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6102 | *out = Mod; |
| 6103 | return 0; |
| 6104 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6105 | isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type); |
| 6106 | if (isinstance == -1) { |
| 6107 | return 1; |
| 6108 | } |
| 6109 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6110 | *out = Pow; |
| 6111 | return 0; |
| 6112 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6113 | isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type); |
| 6114 | if (isinstance == -1) { |
| 6115 | return 1; |
| 6116 | } |
| 6117 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6118 | *out = LShift; |
| 6119 | return 0; |
| 6120 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6121 | isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type); |
| 6122 | if (isinstance == -1) { |
| 6123 | return 1; |
| 6124 | } |
| 6125 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6126 | *out = RShift; |
| 6127 | return 0; |
| 6128 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6129 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type); |
| 6130 | if (isinstance == -1) { |
| 6131 | return 1; |
| 6132 | } |
| 6133 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6134 | *out = BitOr; |
| 6135 | return 0; |
| 6136 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6137 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type); |
| 6138 | if (isinstance == -1) { |
| 6139 | return 1; |
| 6140 | } |
| 6141 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6142 | *out = BitXor; |
| 6143 | return 0; |
| 6144 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6145 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type); |
| 6146 | if (isinstance == -1) { |
| 6147 | return 1; |
| 6148 | } |
| 6149 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6150 | *out = BitAnd; |
| 6151 | return 0; |
| 6152 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6153 | isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type); |
| 6154 | if (isinstance == -1) { |
| 6155 | return 1; |
| 6156 | } |
| 6157 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6158 | *out = FloorDiv; |
| 6159 | return 0; |
| 6160 | } |
| 6161 | |
| 6162 | tmp = PyObject_Repr(obj); |
| 6163 | if (tmp == NULL) goto failed; |
Christian Heimes | 72b710a | 2008-05-26 13:28:38 +0000 | [diff] [blame] | 6164 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %.400s", PyBytes_AS_STRING(tmp)); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6165 | failed: |
| 6166 | Py_XDECREF(tmp); |
| 6167 | return 1; |
| 6168 | } |
| 6169 | |
| 6170 | int |
| 6171 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 6172 | { |
| 6173 | PyObject* tmp = NULL; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6174 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6175 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6176 | isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); |
| 6177 | if (isinstance == -1) { |
| 6178 | return 1; |
| 6179 | } |
| 6180 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6181 | *out = Invert; |
| 6182 | return 0; |
| 6183 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6184 | isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type); |
| 6185 | if (isinstance == -1) { |
| 6186 | return 1; |
| 6187 | } |
| 6188 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6189 | *out = Not; |
| 6190 | return 0; |
| 6191 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6192 | isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type); |
| 6193 | if (isinstance == -1) { |
| 6194 | return 1; |
| 6195 | } |
| 6196 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6197 | *out = UAdd; |
| 6198 | return 0; |
| 6199 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6200 | isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type); |
| 6201 | if (isinstance == -1) { |
| 6202 | return 1; |
| 6203 | } |
| 6204 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6205 | *out = USub; |
| 6206 | return 0; |
| 6207 | } |
| 6208 | |
| 6209 | tmp = PyObject_Repr(obj); |
| 6210 | if (tmp == NULL) goto failed; |
Christian Heimes | 72b710a | 2008-05-26 13:28:38 +0000 | [diff] [blame] | 6211 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %.400s", PyBytes_AS_STRING(tmp)); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6212 | failed: |
| 6213 | Py_XDECREF(tmp); |
| 6214 | return 1; |
| 6215 | } |
| 6216 | |
| 6217 | int |
| 6218 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 6219 | { |
| 6220 | PyObject* tmp = NULL; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6221 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6222 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6223 | isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); |
| 6224 | if (isinstance == -1) { |
| 6225 | return 1; |
| 6226 | } |
| 6227 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6228 | *out = Eq; |
| 6229 | return 0; |
| 6230 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6231 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type); |
| 6232 | if (isinstance == -1) { |
| 6233 | return 1; |
| 6234 | } |
| 6235 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6236 | *out = NotEq; |
| 6237 | return 0; |
| 6238 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6239 | isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type); |
| 6240 | if (isinstance == -1) { |
| 6241 | return 1; |
| 6242 | } |
| 6243 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6244 | *out = Lt; |
| 6245 | return 0; |
| 6246 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6247 | isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type); |
| 6248 | if (isinstance == -1) { |
| 6249 | return 1; |
| 6250 | } |
| 6251 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6252 | *out = LtE; |
| 6253 | return 0; |
| 6254 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6255 | isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type); |
| 6256 | if (isinstance == -1) { |
| 6257 | return 1; |
| 6258 | } |
| 6259 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6260 | *out = Gt; |
| 6261 | return 0; |
| 6262 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6263 | isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type); |
| 6264 | if (isinstance == -1) { |
| 6265 | return 1; |
| 6266 | } |
| 6267 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6268 | *out = GtE; |
| 6269 | return 0; |
| 6270 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6271 | isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type); |
| 6272 | if (isinstance == -1) { |
| 6273 | return 1; |
| 6274 | } |
| 6275 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6276 | *out = Is; |
| 6277 | return 0; |
| 6278 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6279 | isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type); |
| 6280 | if (isinstance == -1) { |
| 6281 | return 1; |
| 6282 | } |
| 6283 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6284 | *out = IsNot; |
| 6285 | return 0; |
| 6286 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6287 | isinstance = PyObject_IsInstance(obj, (PyObject *)In_type); |
| 6288 | if (isinstance == -1) { |
| 6289 | return 1; |
| 6290 | } |
| 6291 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6292 | *out = In; |
| 6293 | return 0; |
| 6294 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6295 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type); |
| 6296 | if (isinstance == -1) { |
| 6297 | return 1; |
| 6298 | } |
| 6299 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6300 | *out = NotIn; |
| 6301 | return 0; |
| 6302 | } |
| 6303 | |
| 6304 | tmp = PyObject_Repr(obj); |
| 6305 | if (tmp == NULL) goto failed; |
Christian Heimes | 72b710a | 2008-05-26 13:28:38 +0000 | [diff] [blame] | 6306 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %.400s", PyBytes_AS_STRING(tmp)); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6307 | failed: |
| 6308 | Py_XDECREF(tmp); |
| 6309 | return 1; |
| 6310 | } |
| 6311 | |
| 6312 | int |
| 6313 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 6314 | { |
| 6315 | PyObject* tmp = NULL; |
| 6316 | expr_ty target; |
| 6317 | expr_ty iter; |
| 6318 | asdl_seq* ifs; |
| 6319 | |
| 6320 | if (PyObject_HasAttrString(obj, "target")) { |
| 6321 | int res; |
| 6322 | tmp = PyObject_GetAttrString(obj, "target"); |
| 6323 | if (tmp == NULL) goto failed; |
| 6324 | res = obj2ast_expr(tmp, &target, arena); |
| 6325 | if (res != 0) goto failed; |
| 6326 | Py_XDECREF(tmp); |
| 6327 | tmp = NULL; |
| 6328 | } else { |
| 6329 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 6330 | return 1; |
| 6331 | } |
| 6332 | if (PyObject_HasAttrString(obj, "iter")) { |
| 6333 | int res; |
| 6334 | tmp = PyObject_GetAttrString(obj, "iter"); |
| 6335 | if (tmp == NULL) goto failed; |
| 6336 | res = obj2ast_expr(tmp, &iter, arena); |
| 6337 | if (res != 0) goto failed; |
| 6338 | Py_XDECREF(tmp); |
| 6339 | tmp = NULL; |
| 6340 | } else { |
| 6341 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 6342 | return 1; |
| 6343 | } |
| 6344 | if (PyObject_HasAttrString(obj, "ifs")) { |
| 6345 | int res; |
| 6346 | Py_ssize_t len; |
| 6347 | Py_ssize_t i; |
| 6348 | tmp = PyObject_GetAttrString(obj, "ifs"); |
| 6349 | if (tmp == NULL) goto failed; |
| 6350 | if (!PyList_Check(tmp)) { |
| 6351 | PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6352 | goto failed; |
| 6353 | } |
| 6354 | len = PyList_GET_SIZE(tmp); |
| 6355 | ifs = asdl_seq_new(len, arena); |
| 6356 | if (ifs == NULL) goto failed; |
| 6357 | for (i = 0; i < len; i++) { |
| 6358 | expr_ty value; |
| 6359 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6360 | if (res != 0) goto failed; |
| 6361 | asdl_seq_SET(ifs, i, value); |
| 6362 | } |
| 6363 | Py_XDECREF(tmp); |
| 6364 | tmp = NULL; |
| 6365 | } else { |
| 6366 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 6367 | return 1; |
| 6368 | } |
| 6369 | *out = comprehension(target, iter, ifs, arena); |
| 6370 | return 0; |
| 6371 | failed: |
| 6372 | Py_XDECREF(tmp); |
| 6373 | return 1; |
| 6374 | } |
| 6375 | |
| 6376 | int |
| 6377 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 6378 | { |
| 6379 | PyObject* tmp = NULL; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6380 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6381 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6382 | int lineno; |
| 6383 | int col_offset; |
| 6384 | |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6385 | if (obj == Py_None) { |
| 6386 | *out = NULL; |
| 6387 | return 0; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6388 | } |
| 6389 | if (PyObject_HasAttrString(obj, "lineno")) { |
| 6390 | int res; |
| 6391 | tmp = PyObject_GetAttrString(obj, "lineno"); |
| 6392 | if (tmp == NULL) goto failed; |
| 6393 | res = obj2ast_int(tmp, &lineno, arena); |
| 6394 | if (res != 0) goto failed; |
| 6395 | Py_XDECREF(tmp); |
| 6396 | tmp = NULL; |
| 6397 | } else { |
| 6398 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 6399 | return 1; |
| 6400 | } |
| 6401 | if (PyObject_HasAttrString(obj, "col_offset")) { |
| 6402 | int res; |
| 6403 | tmp = PyObject_GetAttrString(obj, "col_offset"); |
| 6404 | if (tmp == NULL) goto failed; |
| 6405 | res = obj2ast_int(tmp, &col_offset, arena); |
| 6406 | if (res != 0) goto failed; |
| 6407 | Py_XDECREF(tmp); |
| 6408 | tmp = NULL; |
| 6409 | } else { |
| 6410 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 6411 | return 1; |
| 6412 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6413 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type); |
| 6414 | if (isinstance == -1) { |
| 6415 | return 1; |
| 6416 | } |
| 6417 | if (isinstance) { |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6418 | expr_ty type; |
| 6419 | identifier name; |
| 6420 | asdl_seq* body; |
| 6421 | |
| 6422 | if (PyObject_HasAttrString(obj, "type")) { |
| 6423 | int res; |
| 6424 | tmp = PyObject_GetAttrString(obj, "type"); |
| 6425 | if (tmp == NULL) goto failed; |
| 6426 | res = obj2ast_expr(tmp, &type, arena); |
| 6427 | if (res != 0) goto failed; |
| 6428 | Py_XDECREF(tmp); |
| 6429 | tmp = NULL; |
| 6430 | } else { |
| 6431 | type = NULL; |
| 6432 | } |
| 6433 | if (PyObject_HasAttrString(obj, "name")) { |
| 6434 | int res; |
| 6435 | tmp = PyObject_GetAttrString(obj, "name"); |
| 6436 | if (tmp == NULL) goto failed; |
| 6437 | res = obj2ast_identifier(tmp, &name, arena); |
| 6438 | if (res != 0) goto failed; |
| 6439 | Py_XDECREF(tmp); |
| 6440 | tmp = NULL; |
| 6441 | } else { |
| 6442 | name = NULL; |
| 6443 | } |
| 6444 | if (PyObject_HasAttrString(obj, "body")) { |
| 6445 | int res; |
| 6446 | Py_ssize_t len; |
| 6447 | Py_ssize_t i; |
| 6448 | tmp = PyObject_GetAttrString(obj, "body"); |
| 6449 | if (tmp == NULL) goto failed; |
| 6450 | if (!PyList_Check(tmp)) { |
| 6451 | PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6452 | goto failed; |
| 6453 | } |
| 6454 | len = PyList_GET_SIZE(tmp); |
| 6455 | body = asdl_seq_new(len, arena); |
| 6456 | if (body == NULL) goto failed; |
| 6457 | for (i = 0; i < len; i++) { |
| 6458 | stmt_ty value; |
| 6459 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6460 | if (res != 0) goto failed; |
| 6461 | asdl_seq_SET(body, i, value); |
| 6462 | } |
| 6463 | Py_XDECREF(tmp); |
| 6464 | tmp = NULL; |
| 6465 | } else { |
| 6466 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 6467 | return 1; |
| 6468 | } |
| 6469 | *out = ExceptHandler(type, name, body, lineno, col_offset, |
| 6470 | arena); |
| 6471 | if (*out == NULL) goto failed; |
| 6472 | return 0; |
| 6473 | } |
| 6474 | |
| 6475 | tmp = PyObject_Repr(obj); |
| 6476 | if (tmp == NULL) goto failed; |
Christian Heimes | 72b710a | 2008-05-26 13:28:38 +0000 | [diff] [blame] | 6477 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %.400s", PyBytes_AS_STRING(tmp)); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6478 | failed: |
| 6479 | Py_XDECREF(tmp); |
| 6480 | return 1; |
| 6481 | } |
| 6482 | |
| 6483 | int |
| 6484 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 6485 | { |
| 6486 | PyObject* tmp = NULL; |
| 6487 | asdl_seq* args; |
| 6488 | identifier vararg; |
| 6489 | expr_ty varargannotation; |
| 6490 | asdl_seq* kwonlyargs; |
| 6491 | identifier kwarg; |
| 6492 | expr_ty kwargannotation; |
| 6493 | asdl_seq* defaults; |
| 6494 | asdl_seq* kw_defaults; |
| 6495 | |
| 6496 | if (PyObject_HasAttrString(obj, "args")) { |
| 6497 | int res; |
| 6498 | Py_ssize_t len; |
| 6499 | Py_ssize_t i; |
| 6500 | tmp = PyObject_GetAttrString(obj, "args"); |
| 6501 | if (tmp == NULL) goto failed; |
| 6502 | if (!PyList_Check(tmp)) { |
| 6503 | PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6504 | goto failed; |
| 6505 | } |
| 6506 | len = PyList_GET_SIZE(tmp); |
| 6507 | args = asdl_seq_new(len, arena); |
| 6508 | if (args == NULL) goto failed; |
| 6509 | for (i = 0; i < len; i++) { |
| 6510 | arg_ty value; |
| 6511 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6512 | if (res != 0) goto failed; |
| 6513 | asdl_seq_SET(args, i, value); |
| 6514 | } |
| 6515 | Py_XDECREF(tmp); |
| 6516 | tmp = NULL; |
| 6517 | } else { |
| 6518 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 6519 | return 1; |
| 6520 | } |
| 6521 | if (PyObject_HasAttrString(obj, "vararg")) { |
| 6522 | int res; |
| 6523 | tmp = PyObject_GetAttrString(obj, "vararg"); |
| 6524 | if (tmp == NULL) goto failed; |
| 6525 | res = obj2ast_identifier(tmp, &vararg, arena); |
| 6526 | if (res != 0) goto failed; |
| 6527 | Py_XDECREF(tmp); |
| 6528 | tmp = NULL; |
| 6529 | } else { |
| 6530 | vararg = NULL; |
| 6531 | } |
| 6532 | if (PyObject_HasAttrString(obj, "varargannotation")) { |
| 6533 | int res; |
| 6534 | tmp = PyObject_GetAttrString(obj, "varargannotation"); |
| 6535 | if (tmp == NULL) goto failed; |
| 6536 | res = obj2ast_expr(tmp, &varargannotation, arena); |
| 6537 | if (res != 0) goto failed; |
| 6538 | Py_XDECREF(tmp); |
| 6539 | tmp = NULL; |
| 6540 | } else { |
| 6541 | varargannotation = NULL; |
| 6542 | } |
| 6543 | if (PyObject_HasAttrString(obj, "kwonlyargs")) { |
| 6544 | int res; |
| 6545 | Py_ssize_t len; |
| 6546 | Py_ssize_t i; |
| 6547 | tmp = PyObject_GetAttrString(obj, "kwonlyargs"); |
| 6548 | if (tmp == NULL) goto failed; |
| 6549 | if (!PyList_Check(tmp)) { |
| 6550 | PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6551 | goto failed; |
| 6552 | } |
| 6553 | len = PyList_GET_SIZE(tmp); |
| 6554 | kwonlyargs = asdl_seq_new(len, arena); |
| 6555 | if (kwonlyargs == NULL) goto failed; |
| 6556 | for (i = 0; i < len; i++) { |
| 6557 | arg_ty value; |
| 6558 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6559 | if (res != 0) goto failed; |
| 6560 | asdl_seq_SET(kwonlyargs, i, value); |
| 6561 | } |
| 6562 | Py_XDECREF(tmp); |
| 6563 | tmp = NULL; |
| 6564 | } else { |
| 6565 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 6566 | return 1; |
| 6567 | } |
| 6568 | if (PyObject_HasAttrString(obj, "kwarg")) { |
| 6569 | int res; |
| 6570 | tmp = PyObject_GetAttrString(obj, "kwarg"); |
| 6571 | if (tmp == NULL) goto failed; |
| 6572 | res = obj2ast_identifier(tmp, &kwarg, arena); |
| 6573 | if (res != 0) goto failed; |
| 6574 | Py_XDECREF(tmp); |
| 6575 | tmp = NULL; |
| 6576 | } else { |
| 6577 | kwarg = NULL; |
| 6578 | } |
| 6579 | if (PyObject_HasAttrString(obj, "kwargannotation")) { |
| 6580 | int res; |
| 6581 | tmp = PyObject_GetAttrString(obj, "kwargannotation"); |
| 6582 | if (tmp == NULL) goto failed; |
| 6583 | res = obj2ast_expr(tmp, &kwargannotation, arena); |
| 6584 | if (res != 0) goto failed; |
| 6585 | Py_XDECREF(tmp); |
| 6586 | tmp = NULL; |
| 6587 | } else { |
| 6588 | kwargannotation = NULL; |
| 6589 | } |
| 6590 | if (PyObject_HasAttrString(obj, "defaults")) { |
| 6591 | int res; |
| 6592 | Py_ssize_t len; |
| 6593 | Py_ssize_t i; |
| 6594 | tmp = PyObject_GetAttrString(obj, "defaults"); |
| 6595 | if (tmp == NULL) goto failed; |
| 6596 | if (!PyList_Check(tmp)) { |
| 6597 | PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6598 | goto failed; |
| 6599 | } |
| 6600 | len = PyList_GET_SIZE(tmp); |
| 6601 | defaults = asdl_seq_new(len, arena); |
| 6602 | if (defaults == NULL) goto failed; |
| 6603 | for (i = 0; i < len; i++) { |
| 6604 | expr_ty value; |
| 6605 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6606 | if (res != 0) goto failed; |
| 6607 | asdl_seq_SET(defaults, i, value); |
| 6608 | } |
| 6609 | Py_XDECREF(tmp); |
| 6610 | tmp = NULL; |
| 6611 | } else { |
| 6612 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 6613 | return 1; |
| 6614 | } |
| 6615 | if (PyObject_HasAttrString(obj, "kw_defaults")) { |
| 6616 | int res; |
| 6617 | Py_ssize_t len; |
| 6618 | Py_ssize_t i; |
| 6619 | tmp = PyObject_GetAttrString(obj, "kw_defaults"); |
| 6620 | if (tmp == NULL) goto failed; |
| 6621 | if (!PyList_Check(tmp)) { |
| 6622 | PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6623 | goto failed; |
| 6624 | } |
| 6625 | len = PyList_GET_SIZE(tmp); |
| 6626 | kw_defaults = asdl_seq_new(len, arena); |
| 6627 | if (kw_defaults == NULL) goto failed; |
| 6628 | for (i = 0; i < len; i++) { |
| 6629 | expr_ty value; |
| 6630 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6631 | if (res != 0) goto failed; |
| 6632 | asdl_seq_SET(kw_defaults, i, value); |
| 6633 | } |
| 6634 | Py_XDECREF(tmp); |
| 6635 | tmp = NULL; |
| 6636 | } else { |
| 6637 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 6638 | return 1; |
| 6639 | } |
| 6640 | *out = arguments(args, vararg, varargannotation, kwonlyargs, kwarg, |
| 6641 | kwargannotation, defaults, kw_defaults, arena); |
| 6642 | return 0; |
| 6643 | failed: |
| 6644 | Py_XDECREF(tmp); |
| 6645 | return 1; |
| 6646 | } |
| 6647 | |
| 6648 | int |
| 6649 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 6650 | { |
| 6651 | PyObject* tmp = NULL; |
| 6652 | identifier arg; |
| 6653 | expr_ty annotation; |
| 6654 | |
| 6655 | if (PyObject_HasAttrString(obj, "arg")) { |
| 6656 | int res; |
| 6657 | tmp = PyObject_GetAttrString(obj, "arg"); |
| 6658 | if (tmp == NULL) goto failed; |
| 6659 | res = obj2ast_identifier(tmp, &arg, arena); |
| 6660 | if (res != 0) goto failed; |
| 6661 | Py_XDECREF(tmp); |
| 6662 | tmp = NULL; |
| 6663 | } else { |
| 6664 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
| 6665 | return 1; |
| 6666 | } |
| 6667 | if (PyObject_HasAttrString(obj, "annotation")) { |
| 6668 | int res; |
| 6669 | tmp = PyObject_GetAttrString(obj, "annotation"); |
| 6670 | if (tmp == NULL) goto failed; |
| 6671 | res = obj2ast_expr(tmp, &annotation, arena); |
| 6672 | if (res != 0) goto failed; |
| 6673 | Py_XDECREF(tmp); |
| 6674 | tmp = NULL; |
| 6675 | } else { |
| 6676 | annotation = NULL; |
| 6677 | } |
| 6678 | *out = arg(arg, annotation, arena); |
| 6679 | return 0; |
| 6680 | failed: |
| 6681 | Py_XDECREF(tmp); |
| 6682 | return 1; |
| 6683 | } |
| 6684 | |
| 6685 | int |
| 6686 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 6687 | { |
| 6688 | PyObject* tmp = NULL; |
| 6689 | identifier arg; |
| 6690 | expr_ty value; |
| 6691 | |
| 6692 | if (PyObject_HasAttrString(obj, "arg")) { |
| 6693 | int res; |
| 6694 | tmp = PyObject_GetAttrString(obj, "arg"); |
| 6695 | if (tmp == NULL) goto failed; |
| 6696 | res = obj2ast_identifier(tmp, &arg, arena); |
| 6697 | if (res != 0) goto failed; |
| 6698 | Py_XDECREF(tmp); |
| 6699 | tmp = NULL; |
| 6700 | } else { |
| 6701 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from keyword"); |
| 6702 | return 1; |
| 6703 | } |
| 6704 | if (PyObject_HasAttrString(obj, "value")) { |
| 6705 | int res; |
| 6706 | tmp = PyObject_GetAttrString(obj, "value"); |
| 6707 | if (tmp == NULL) goto failed; |
| 6708 | res = obj2ast_expr(tmp, &value, arena); |
| 6709 | if (res != 0) goto failed; |
| 6710 | Py_XDECREF(tmp); |
| 6711 | tmp = NULL; |
| 6712 | } else { |
| 6713 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 6714 | return 1; |
| 6715 | } |
| 6716 | *out = keyword(arg, value, arena); |
| 6717 | return 0; |
| 6718 | failed: |
| 6719 | Py_XDECREF(tmp); |
| 6720 | return 1; |
| 6721 | } |
| 6722 | |
| 6723 | int |
| 6724 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 6725 | { |
| 6726 | PyObject* tmp = NULL; |
| 6727 | identifier name; |
| 6728 | identifier asname; |
| 6729 | |
| 6730 | if (PyObject_HasAttrString(obj, "name")) { |
| 6731 | int res; |
| 6732 | tmp = PyObject_GetAttrString(obj, "name"); |
| 6733 | if (tmp == NULL) goto failed; |
| 6734 | res = obj2ast_identifier(tmp, &name, arena); |
| 6735 | if (res != 0) goto failed; |
| 6736 | Py_XDECREF(tmp); |
| 6737 | tmp = NULL; |
| 6738 | } else { |
| 6739 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 6740 | return 1; |
| 6741 | } |
| 6742 | if (PyObject_HasAttrString(obj, "asname")) { |
| 6743 | int res; |
| 6744 | tmp = PyObject_GetAttrString(obj, "asname"); |
| 6745 | if (tmp == NULL) goto failed; |
| 6746 | res = obj2ast_identifier(tmp, &asname, arena); |
| 6747 | if (res != 0) goto failed; |
| 6748 | Py_XDECREF(tmp); |
| 6749 | tmp = NULL; |
| 6750 | } else { |
| 6751 | asname = NULL; |
| 6752 | } |
| 6753 | *out = alias(name, asname, arena); |
| 6754 | return 0; |
| 6755 | failed: |
| 6756 | Py_XDECREF(tmp); |
| 6757 | return 1; |
| 6758 | } |
| 6759 | |
| 6760 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6761 | static struct PyModuleDef _astmodule = { |
| 6762 | PyModuleDef_HEAD_INIT, "_ast" |
| 6763 | }; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6764 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6765 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6766 | { |
| 6767 | PyObject *m, *d; |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6768 | if (!init_types()) return NULL; |
| 6769 | m = PyModule_Create(&_astmodule); |
| 6770 | if (!m) return NULL; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6771 | d = PyModule_GetDict(m); |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6772 | if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return |
| 6773 | NULL; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6774 | 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] | 6775 | return NULL; |
Alexander Belopolsky | 1b7046b | 2010-06-23 21:40:15 +0000 | [diff] [blame^] | 6776 | if (PyModule_AddStringConstant(m, "__version__", "82163") < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6777 | return NULL; |
| 6778 | if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return |
| 6779 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6780 | if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6781 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6782 | if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6783 | < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6784 | if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6785 | 0) return NULL; |
| 6786 | if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return |
| 6787 | NULL; |
| 6788 | if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return |
| 6789 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6790 | if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6791 | < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6792 | if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6793 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6794 | if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6795 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6796 | if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6797 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6798 | if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6799 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6800 | if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6801 | 0) return NULL; |
| 6802 | if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return |
| 6803 | NULL; |
| 6804 | if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return |
| 6805 | NULL; |
| 6806 | if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return NULL; |
| 6807 | if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return |
| 6808 | NULL; |
| 6809 | if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return |
| 6810 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6811 | if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6812 | 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6813 | if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6814 | 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6815 | if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6816 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6817 | if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6818 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6819 | if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6820 | 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6821 | if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6822 | return NULL; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 6823 | if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6824 | return NULL; |
| 6825 | if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return |
| 6826 | NULL; |
| 6827 | if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return |
| 6828 | NULL; |
| 6829 | if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return |
| 6830 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6831 | if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6832 | return NULL; |
| 6833 | if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return |
| 6834 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6835 | if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6836 | return NULL; |
| 6837 | if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return |
| 6838 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6839 | if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6840 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6841 | if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6842 | return NULL; |
| 6843 | if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return |
| 6844 | NULL; |
| 6845 | if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return |
| 6846 | NULL; |
| 6847 | if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return |
| 6848 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6849 | if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6850 | return NULL; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 6851 | if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6852 | return NULL; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 6853 | if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6854 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6855 | if (PyDict_SetItemString(d, "GeneratorExp", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6856 | (PyObject*)GeneratorExp_type) < 0) return NULL; |
| 6857 | if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return |
| 6858 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6859 | if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6860 | return NULL; |
| 6861 | if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return |
| 6862 | NULL; |
| 6863 | if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return |
| 6864 | NULL; |
| 6865 | if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return |
| 6866 | NULL; |
| 6867 | if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return |
| 6868 | NULL; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 6869 | if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6870 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6871 | if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6872 | 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6873 | if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6874 | 0) return NULL; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 6875 | if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6876 | return NULL; |
| 6877 | if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return |
| 6878 | NULL; |
| 6879 | if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return |
| 6880 | NULL; |
| 6881 | if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return |
| 6882 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6883 | if (PyDict_SetItemString(d, "expr_context", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6884 | (PyObject*)expr_context_type) < 0) return NULL; |
| 6885 | if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return |
| 6886 | NULL; |
| 6887 | if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return |
| 6888 | NULL; |
| 6889 | if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return |
| 6890 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6891 | if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6892 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6893 | if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6894 | return NULL; |
| 6895 | if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return |
| 6896 | NULL; |
| 6897 | if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return |
| 6898 | NULL; |
| 6899 | if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return |
| 6900 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6901 | if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6902 | return NULL; |
| 6903 | if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return |
| 6904 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6905 | if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6906 | return NULL; |
| 6907 | if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return |
| 6908 | NULL; |
| 6909 | if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6910 | if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6911 | return NULL; |
| 6912 | if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return |
| 6913 | NULL; |
| 6914 | if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return |
| 6915 | NULL; |
| 6916 | if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return |
| 6917 | NULL; |
| 6918 | if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return |
| 6919 | NULL; |
| 6920 | if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return |
| 6921 | NULL; |
| 6922 | if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return |
| 6923 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6924 | if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6925 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6926 | if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6927 | return NULL; |
| 6928 | if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return |
| 6929 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6930 | if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6931 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6932 | if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6933 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6934 | if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6935 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6936 | if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6937 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6938 | if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6939 | return NULL; |
| 6940 | if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return |
| 6941 | NULL; |
| 6942 | if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return |
| 6943 | NULL; |
| 6944 | if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return |
| 6945 | NULL; |
| 6946 | if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return |
| 6947 | NULL; |
| 6948 | if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return NULL; |
| 6949 | if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return |
| 6950 | NULL; |
| 6951 | if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return NULL; |
| 6952 | if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return |
| 6953 | NULL; |
| 6954 | if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return NULL; |
| 6955 | if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return |
| 6956 | NULL; |
| 6957 | if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return NULL; |
| 6958 | if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return |
| 6959 | NULL; |
| 6960 | if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return NULL; |
| 6961 | if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return |
| 6962 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6963 | if (PyDict_SetItemString(d, "comprehension", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6964 | (PyObject*)comprehension_type) < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6965 | if (PyDict_SetItemString(d, "excepthandler", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6966 | (PyObject*)excepthandler_type) < 0) return NULL; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6967 | if (PyDict_SetItemString(d, "ExceptHandler", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6968 | (PyObject*)ExceptHandler_type) < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6969 | if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6970 | 0) return NULL; |
| 6971 | if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return |
| 6972 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6973 | if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6974 | return NULL; |
| 6975 | if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return |
| 6976 | NULL; |
| 6977 | return m; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6978 | } |
| 6979 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 6980 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 6981 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 6982 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 6983 | init_types(); |
| 6984 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 6985 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 6986 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 6987 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 6988 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6989 | { |
| 6990 | mod_ty res; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 6991 | PyObject *req_type[] = {(PyObject*)Module_type, (PyObject*)Expression_type, |
| 6992 | (PyObject*)Interactive_type}; |
| 6993 | char *req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6994 | int isinstance; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 6995 | assert(0 <= mode && mode <= 2); |
| 6996 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6997 | init_types(); |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 6998 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6999 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 7000 | if (isinstance == -1) |
| 7001 | return NULL; |
| 7002 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7003 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
| 7004 | req_name[mode], Py_TYPE(ast)->tp_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7005 | return NULL; |
| 7006 | } |
| 7007 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 7008 | return NULL; |
| 7009 | else |
| 7010 | return res; |
| 7011 | } |
| 7012 | |
| 7013 | int PyAST_Check(PyObject* obj) |
| 7014 | { |
| 7015 | init_types(); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 7016 | return PyObject_IsInstance(obj, (PyObject*)&AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7017 | } |
| 7018 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 7019 | |