Brett Cannon | 0db62aa | 2007-02-12 03:51:02 +0000 | [diff] [blame] | 1 | /* File automatically generated by Parser/asdl_c.py. */ |
| 2 | |
| 3 | |
| 4 | /* |
Barry Warsaw | cf0d8ab | 2011-05-23 15:22:56 -0400 | [diff] [blame^] | 5 | __version__ . |
Brett Cannon | 0db62aa | 2007-02-12 03:51:02 +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 | |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +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", |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 45 | "decorator_list", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 46 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 47 | static PyTypeObject *ClassDef_type; |
| 48 | static char *ClassDef_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 49 | "name", |
| 50 | "bases", |
| 51 | "body", |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 52 | "decorator_list", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 53 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 54 | static PyTypeObject *Return_type; |
| 55 | static char *Return_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 56 | "value", |
| 57 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 58 | static PyTypeObject *Delete_type; |
| 59 | static char *Delete_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 60 | "targets", |
| 61 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 62 | static PyTypeObject *Assign_type; |
| 63 | static char *Assign_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 64 | "targets", |
| 65 | "value", |
| 66 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 67 | static PyTypeObject *AugAssign_type; |
| 68 | static char *AugAssign_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 69 | "target", |
| 70 | "op", |
| 71 | "value", |
| 72 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 73 | static PyTypeObject *Print_type; |
| 74 | static char *Print_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 75 | "dest", |
| 76 | "values", |
| 77 | "nl", |
| 78 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 79 | static PyTypeObject *For_type; |
| 80 | static char *For_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 81 | "target", |
| 82 | "iter", |
| 83 | "body", |
| 84 | "orelse", |
| 85 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 86 | static PyTypeObject *While_type; |
| 87 | static char *While_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 88 | "test", |
| 89 | "body", |
| 90 | "orelse", |
| 91 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 92 | static PyTypeObject *If_type; |
| 93 | static char *If_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 94 | "test", |
| 95 | "body", |
| 96 | "orelse", |
| 97 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 98 | static PyTypeObject *With_type; |
| 99 | static char *With_fields[]={ |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 100 | "context_expr", |
| 101 | "optional_vars", |
| 102 | "body", |
| 103 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 104 | static PyTypeObject *Raise_type; |
| 105 | static char *Raise_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 106 | "type", |
| 107 | "inst", |
| 108 | "tback", |
| 109 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 110 | static PyTypeObject *TryExcept_type; |
| 111 | static char *TryExcept_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 112 | "body", |
| 113 | "handlers", |
| 114 | "orelse", |
| 115 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 116 | static PyTypeObject *TryFinally_type; |
| 117 | static char *TryFinally_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 118 | "body", |
| 119 | "finalbody", |
| 120 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 121 | static PyTypeObject *Assert_type; |
| 122 | static char *Assert_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 123 | "test", |
| 124 | "msg", |
| 125 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 126 | static PyTypeObject *Import_type; |
| 127 | static char *Import_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 128 | "names", |
| 129 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 130 | static PyTypeObject *ImportFrom_type; |
| 131 | static char *ImportFrom_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 132 | "module", |
| 133 | "names", |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 134 | "level", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 135 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 136 | static PyTypeObject *Exec_type; |
| 137 | static char *Exec_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 138 | "body", |
| 139 | "globals", |
| 140 | "locals", |
| 141 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 142 | static PyTypeObject *Global_type; |
| 143 | static char *Global_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 144 | "names", |
| 145 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 146 | static PyTypeObject *Expr_type; |
| 147 | static char *Expr_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 148 | "value", |
| 149 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 150 | static PyTypeObject *Pass_type; |
| 151 | static PyTypeObject *Break_type; |
| 152 | static PyTypeObject *Continue_type; |
| 153 | static PyTypeObject *expr_type; |
| 154 | static char *expr_attributes[] = { |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 155 | "lineno", |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 156 | "col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 157 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 158 | static PyObject* ast2obj_expr(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 159 | static PyTypeObject *BoolOp_type; |
| 160 | static char *BoolOp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 161 | "op", |
| 162 | "values", |
| 163 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 164 | static PyTypeObject *BinOp_type; |
| 165 | static char *BinOp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 166 | "left", |
| 167 | "op", |
| 168 | "right", |
| 169 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 170 | static PyTypeObject *UnaryOp_type; |
| 171 | static char *UnaryOp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 172 | "op", |
| 173 | "operand", |
| 174 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 175 | static PyTypeObject *Lambda_type; |
| 176 | static char *Lambda_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 177 | "args", |
| 178 | "body", |
| 179 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 180 | static PyTypeObject *IfExp_type; |
| 181 | static char *IfExp_fields[]={ |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 182 | "test", |
| 183 | "body", |
| 184 | "orelse", |
| 185 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 186 | static PyTypeObject *Dict_type; |
| 187 | static char *Dict_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 188 | "keys", |
| 189 | "values", |
| 190 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 191 | static PyTypeObject *ListComp_type; |
| 192 | static char *ListComp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 193 | "elt", |
| 194 | "generators", |
| 195 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 196 | static PyTypeObject *GeneratorExp_type; |
| 197 | static char *GeneratorExp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 198 | "elt", |
| 199 | "generators", |
| 200 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 201 | static PyTypeObject *Yield_type; |
| 202 | static char *Yield_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 203 | "value", |
| 204 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 205 | static PyTypeObject *Compare_type; |
| 206 | static char *Compare_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 207 | "left", |
| 208 | "ops", |
| 209 | "comparators", |
| 210 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 211 | static PyTypeObject *Call_type; |
| 212 | static char *Call_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 213 | "func", |
| 214 | "args", |
| 215 | "keywords", |
| 216 | "starargs", |
| 217 | "kwargs", |
| 218 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 219 | static PyTypeObject *Repr_type; |
| 220 | static char *Repr_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 221 | "value", |
| 222 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 223 | static PyTypeObject *Num_type; |
| 224 | static char *Num_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 225 | "n", |
| 226 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 227 | static PyTypeObject *Str_type; |
| 228 | static char *Str_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 229 | "s", |
| 230 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 231 | static PyTypeObject *Attribute_type; |
| 232 | static char *Attribute_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 233 | "value", |
| 234 | "attr", |
| 235 | "ctx", |
| 236 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 237 | static PyTypeObject *Subscript_type; |
| 238 | static char *Subscript_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 239 | "value", |
| 240 | "slice", |
| 241 | "ctx", |
| 242 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 243 | static PyTypeObject *Name_type; |
| 244 | static char *Name_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 245 | "id", |
| 246 | "ctx", |
| 247 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 248 | static PyTypeObject *List_type; |
| 249 | static char *List_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 250 | "elts", |
| 251 | "ctx", |
| 252 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 253 | static PyTypeObject *Tuple_type; |
| 254 | static char *Tuple_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 255 | "elts", |
| 256 | "ctx", |
| 257 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 258 | static PyTypeObject *expr_context_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 259 | static PyObject *Load_singleton, *Store_singleton, *Del_singleton, |
| 260 | *AugLoad_singleton, *AugStore_singleton, *Param_singleton; |
| 261 | static PyObject* ast2obj_expr_context(expr_context_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 262 | static PyTypeObject *Load_type; |
| 263 | static PyTypeObject *Store_type; |
| 264 | static PyTypeObject *Del_type; |
| 265 | static PyTypeObject *AugLoad_type; |
| 266 | static PyTypeObject *AugStore_type; |
| 267 | static PyTypeObject *Param_type; |
| 268 | static PyTypeObject *slice_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 269 | static PyObject* ast2obj_slice(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 270 | static PyTypeObject *Ellipsis_type; |
| 271 | static PyTypeObject *Slice_type; |
| 272 | static char *Slice_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 273 | "lower", |
| 274 | "upper", |
| 275 | "step", |
| 276 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 277 | static PyTypeObject *ExtSlice_type; |
| 278 | static char *ExtSlice_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 279 | "dims", |
| 280 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 281 | static PyTypeObject *Index_type; |
| 282 | static char *Index_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 283 | "value", |
| 284 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 285 | static PyTypeObject *boolop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 286 | static PyObject *And_singleton, *Or_singleton; |
| 287 | static PyObject* ast2obj_boolop(boolop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 288 | static PyTypeObject *And_type; |
| 289 | static PyTypeObject *Or_type; |
| 290 | static PyTypeObject *operator_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 291 | static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton, |
| 292 | *Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton, |
| 293 | *RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton, |
| 294 | *FloorDiv_singleton; |
| 295 | static PyObject* ast2obj_operator(operator_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 296 | static PyTypeObject *Add_type; |
| 297 | static PyTypeObject *Sub_type; |
| 298 | static PyTypeObject *Mult_type; |
| 299 | static PyTypeObject *Div_type; |
| 300 | static PyTypeObject *Mod_type; |
| 301 | static PyTypeObject *Pow_type; |
| 302 | static PyTypeObject *LShift_type; |
| 303 | static PyTypeObject *RShift_type; |
| 304 | static PyTypeObject *BitOr_type; |
| 305 | static PyTypeObject *BitXor_type; |
| 306 | static PyTypeObject *BitAnd_type; |
| 307 | static PyTypeObject *FloorDiv_type; |
| 308 | static PyTypeObject *unaryop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 309 | static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton, |
| 310 | *USub_singleton; |
| 311 | static PyObject* ast2obj_unaryop(unaryop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 312 | static PyTypeObject *Invert_type; |
| 313 | static PyTypeObject *Not_type; |
| 314 | static PyTypeObject *UAdd_type; |
| 315 | static PyTypeObject *USub_type; |
| 316 | static PyTypeObject *cmpop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 317 | static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton, |
| 318 | *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton, |
| 319 | *NotIn_singleton; |
| 320 | static PyObject* ast2obj_cmpop(cmpop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 321 | static PyTypeObject *Eq_type; |
| 322 | static PyTypeObject *NotEq_type; |
| 323 | static PyTypeObject *Lt_type; |
| 324 | static PyTypeObject *LtE_type; |
| 325 | static PyTypeObject *Gt_type; |
| 326 | static PyTypeObject *GtE_type; |
| 327 | static PyTypeObject *Is_type; |
| 328 | static PyTypeObject *IsNot_type; |
| 329 | static PyTypeObject *In_type; |
| 330 | static PyTypeObject *NotIn_type; |
| 331 | static PyTypeObject *comprehension_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 332 | static PyObject* ast2obj_comprehension(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 333 | static char *comprehension_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 334 | "target", |
| 335 | "iter", |
| 336 | "ifs", |
| 337 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 338 | static PyTypeObject *excepthandler_type; |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame] | 339 | static char *excepthandler_attributes[] = { |
| 340 | "lineno", |
| 341 | "col_offset", |
| 342 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 343 | static PyObject* ast2obj_excepthandler(void*); |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame] | 344 | static PyTypeObject *ExceptHandler_type; |
| 345 | static char *ExceptHandler_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 346 | "type", |
| 347 | "name", |
| 348 | "body", |
| 349 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 350 | static PyTypeObject *arguments_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 351 | static PyObject* ast2obj_arguments(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 352 | static char *arguments_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 353 | "args", |
| 354 | "vararg", |
| 355 | "kwarg", |
| 356 | "defaults", |
| 357 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 358 | static PyTypeObject *keyword_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 359 | static PyObject* ast2obj_keyword(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 360 | static char *keyword_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 361 | "arg", |
| 362 | "value", |
| 363 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 364 | static PyTypeObject *alias_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 365 | static PyObject* ast2obj_alias(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 366 | static char *alias_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 367 | "name", |
| 368 | "asname", |
| 369 | }; |
| 370 | |
| 371 | |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 372 | static int |
| 373 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 374 | { |
| 375 | Py_ssize_t i, numfields = 0; |
| 376 | int res = -1; |
| 377 | PyObject *key, *value, *fields; |
| 378 | fields = PyObject_GetAttrString((PyObject*)Py_TYPE(self), "_fields"); |
| 379 | if (!fields) |
| 380 | PyErr_Clear(); |
| 381 | if (fields) { |
| 382 | numfields = PySequence_Size(fields); |
| 383 | if (numfields == -1) |
| 384 | goto cleanup; |
| 385 | } |
| 386 | res = 0; /* if no error occurs, this stays 0 to the end */ |
| 387 | if (PyTuple_GET_SIZE(args) > 0) { |
| 388 | if (numfields != PyTuple_GET_SIZE(args)) { |
Georg Brandl | 1721e75 | 2008-03-30 19:43:27 +0000 | [diff] [blame] | 389 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes %s" |
Amaury Forgeot d'Arc | 05e3449 | 2008-09-10 22:04:45 +0000 | [diff] [blame] | 390 | "%zd positional argument%s", |
Georg Brandl | 1721e75 | 2008-03-30 19:43:27 +0000 | [diff] [blame] | 391 | Py_TYPE(self)->tp_name, |
| 392 | numfields == 0 ? "" : "either 0 or ", |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 393 | numfields, numfields == 1 ? "" : "s"); |
| 394 | res = -1; |
| 395 | goto cleanup; |
| 396 | } |
| 397 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
| 398 | /* cannot be reached when fields is NULL */ |
| 399 | PyObject *name = PySequence_GetItem(fields, i); |
| 400 | if (!name) { |
| 401 | res = -1; |
| 402 | goto cleanup; |
| 403 | } |
| 404 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
| 405 | Py_DECREF(name); |
| 406 | if (res < 0) |
| 407 | goto cleanup; |
| 408 | } |
| 409 | } |
| 410 | if (kw) { |
| 411 | i = 0; /* needed by PyDict_Next */ |
| 412 | while (PyDict_Next(kw, &i, &key, &value)) { |
| 413 | res = PyObject_SetAttr(self, key, value); |
| 414 | if (res < 0) |
| 415 | goto cleanup; |
| 416 | } |
| 417 | } |
| 418 | cleanup: |
| 419 | Py_XDECREF(fields); |
| 420 | return res; |
| 421 | } |
| 422 | |
Georg Brandl | e34c21c | 2008-03-30 20:20:39 +0000 | [diff] [blame] | 423 | /* Pickling support */ |
| 424 | static PyObject * |
| 425 | ast_type_reduce(PyObject *self, PyObject *unused) |
| 426 | { |
| 427 | PyObject *res; |
| 428 | PyObject *dict = PyObject_GetAttrString(self, "__dict__"); |
| 429 | if (dict == NULL) { |
| 430 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) |
| 431 | PyErr_Clear(); |
| 432 | else |
| 433 | return NULL; |
| 434 | } |
| 435 | if (dict) { |
| 436 | res = Py_BuildValue("O()O", Py_TYPE(self), dict); |
| 437 | Py_DECREF(dict); |
| 438 | return res; |
| 439 | } |
| 440 | return Py_BuildValue("O()", Py_TYPE(self)); |
| 441 | } |
| 442 | |
| 443 | static PyMethodDef ast_type_methods[] = { |
| 444 | {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, |
| 445 | {NULL} |
| 446 | }; |
| 447 | |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 448 | static PyTypeObject AST_type = { |
| 449 | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
Georg Brandl | e34c21c | 2008-03-30 20:20:39 +0000 | [diff] [blame] | 450 | "_ast.AST", |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 451 | sizeof(PyObject), |
| 452 | 0, |
| 453 | 0, /* tp_dealloc */ |
| 454 | 0, /* tp_print */ |
| 455 | 0, /* tp_getattr */ |
| 456 | 0, /* tp_setattr */ |
| 457 | 0, /* tp_compare */ |
| 458 | 0, /* tp_repr */ |
| 459 | 0, /* tp_as_number */ |
| 460 | 0, /* tp_as_sequence */ |
| 461 | 0, /* tp_as_mapping */ |
| 462 | 0, /* tp_hash */ |
| 463 | 0, /* tp_call */ |
| 464 | 0, /* tp_str */ |
| 465 | PyObject_GenericGetAttr, /* tp_getattro */ |
| 466 | PyObject_GenericSetAttr, /* tp_setattro */ |
| 467 | 0, /* tp_as_buffer */ |
| 468 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
| 469 | 0, /* tp_doc */ |
| 470 | 0, /* tp_traverse */ |
| 471 | 0, /* tp_clear */ |
| 472 | 0, /* tp_richcompare */ |
| 473 | 0, /* tp_weaklistoffset */ |
| 474 | 0, /* tp_iter */ |
| 475 | 0, /* tp_iternext */ |
Georg Brandl | e34c21c | 2008-03-30 20:20:39 +0000 | [diff] [blame] | 476 | ast_type_methods, /* tp_methods */ |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 477 | 0, /* tp_members */ |
| 478 | 0, /* tp_getset */ |
| 479 | 0, /* tp_base */ |
| 480 | 0, /* tp_dict */ |
| 481 | 0, /* tp_descr_get */ |
| 482 | 0, /* tp_descr_set */ |
| 483 | 0, /* tp_dictoffset */ |
| 484 | (initproc)ast_type_init, /* tp_init */ |
| 485 | PyType_GenericAlloc, /* tp_alloc */ |
| 486 | PyType_GenericNew, /* tp_new */ |
| 487 | PyObject_Del, /* tp_free */ |
| 488 | }; |
| 489 | |
| 490 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 491 | static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields) |
| 492 | { |
| 493 | PyObject *fnames, *result; |
| 494 | int i; |
Georg Brandl | 2c55c59 | 2008-03-30 19:00:49 +0000 | [diff] [blame] | 495 | fnames = PyTuple_New(num_fields); |
| 496 | if (!fnames) return NULL; |
| 497 | for (i = 0; i < num_fields; i++) { |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 498 | PyObject *field = PyString_FromString(fields[i]); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 499 | if (!field) { |
| 500 | Py_DECREF(fnames); |
| 501 | return NULL; |
| 502 | } |
| 503 | PyTuple_SET_ITEM(fnames, i, field); |
| 504 | } |
Thomas Wouters | 34aa7ba | 2006-02-28 19:02:24 +0000 | [diff] [blame] | 505 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 506 | type, base, "_fields", fnames, "__module__", "_ast"); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 507 | Py_DECREF(fnames); |
| 508 | return (PyTypeObject*)result; |
| 509 | } |
| 510 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 511 | static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) |
| 512 | { |
Neal Norwitz | 19379f1 | 2006-04-03 04:50:58 +0000 | [diff] [blame] | 513 | int i, result; |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 514 | PyObject *s, *l = PyTuple_New(num_fields); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 515 | if (!l) return 0; |
Neal Norwitz | 19379f1 | 2006-04-03 04:50:58 +0000 | [diff] [blame] | 516 | for(i = 0; i < num_fields; i++) { |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 517 | s = PyString_FromString(attrs[i]); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 518 | if (!s) { |
| 519 | Py_DECREF(l); |
| 520 | return 0; |
| 521 | } |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 522 | PyTuple_SET_ITEM(l, i, s); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 523 | } |
Neal Norwitz | 19379f1 | 2006-04-03 04:50:58 +0000 | [diff] [blame] | 524 | result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0; |
| 525 | Py_DECREF(l); |
| 526 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 527 | } |
| 528 | |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 529 | /* Conversion AST -> Python */ |
| 530 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 531 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 532 | { |
| 533 | int i, n = asdl_seq_LEN(seq); |
| 534 | PyObject *result = PyList_New(n); |
| 535 | PyObject *value; |
| 536 | if (!result) |
| 537 | return NULL; |
| 538 | for (i = 0; i < n; i++) { |
| 539 | value = func(asdl_seq_GET(seq, i)); |
| 540 | if (!value) { |
| 541 | Py_DECREF(result); |
| 542 | return NULL; |
| 543 | } |
| 544 | PyList_SET_ITEM(result, i, value); |
| 545 | } |
| 546 | return result; |
| 547 | } |
| 548 | |
| 549 | static PyObject* ast2obj_object(void *o) |
| 550 | { |
| 551 | if (!o) |
| 552 | o = Py_None; |
| 553 | Py_INCREF((PyObject*)o); |
| 554 | return (PyObject*)o; |
| 555 | } |
| 556 | #define ast2obj_identifier ast2obj_object |
| 557 | #define ast2obj_string ast2obj_object |
| 558 | static PyObject* ast2obj_bool(bool b) |
| 559 | { |
| 560 | return PyBool_FromLong(b); |
| 561 | } |
| 562 | |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 563 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 564 | { |
| 565 | return PyInt_FromLong(b); |
| 566 | } |
| 567 | |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 568 | /* Conversion Python -> AST */ |
| 569 | |
| 570 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 571 | { |
| 572 | if (obj == Py_None) |
| 573 | obj = NULL; |
| 574 | if (obj) |
| 575 | PyArena_AddPyObject(arena, obj); |
| 576 | Py_XINCREF(obj); |
| 577 | *out = obj; |
| 578 | return 0; |
| 579 | } |
| 580 | |
| 581 | #define obj2ast_identifier obj2ast_object |
| 582 | #define obj2ast_string obj2ast_object |
| 583 | |
| 584 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 585 | { |
| 586 | int i; |
| 587 | if (!PyInt_Check(obj) && !PyLong_Check(obj)) { |
| 588 | PyObject *s = PyObject_Repr(obj); |
| 589 | if (s == NULL) return 1; |
| 590 | PyErr_Format(PyExc_ValueError, "invalid integer value: %.400s", |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 591 | PyString_AS_STRING(s)); |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 592 | Py_DECREF(s); |
| 593 | return 1; |
| 594 | } |
| 595 | |
| 596 | i = (int)PyLong_AsLong(obj); |
| 597 | if (i == -1 && PyErr_Occurred()) |
| 598 | return 1; |
| 599 | *out = i; |
| 600 | return 0; |
| 601 | } |
| 602 | |
| 603 | static int obj2ast_bool(PyObject* obj, bool* out, PyArena* arena) |
| 604 | { |
| 605 | if (!PyBool_Check(obj)) { |
| 606 | PyObject *s = PyObject_Repr(obj); |
| 607 | if (s == NULL) return 1; |
| 608 | PyErr_Format(PyExc_ValueError, "invalid boolean value: %.400s", |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 609 | PyString_AS_STRING(s)); |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 610 | Py_DECREF(s); |
| 611 | return 1; |
| 612 | } |
| 613 | |
| 614 | *out = (obj == Py_True); |
| 615 | return 0; |
| 616 | } |
| 617 | |
Georg Brandl | 4aef703 | 2008-11-07 08:56:27 +0000 | [diff] [blame] | 618 | static int add_ast_fields(void) |
| 619 | { |
| 620 | PyObject *empty_tuple, *d; |
| 621 | if (PyType_Ready(&AST_type) < 0) |
| 622 | return -1; |
| 623 | d = AST_type.tp_dict; |
| 624 | empty_tuple = PyTuple_New(0); |
| 625 | if (!empty_tuple || |
| 626 | PyDict_SetItemString(d, "_fields", empty_tuple) < 0 || |
| 627 | PyDict_SetItemString(d, "_attributes", empty_tuple) < 0) { |
| 628 | Py_XDECREF(empty_tuple); |
| 629 | return -1; |
| 630 | } |
| 631 | Py_DECREF(empty_tuple); |
| 632 | return 0; |
| 633 | } |
| 634 | |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 635 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 636 | static int init_types(void) |
| 637 | { |
Neal Norwitz | 19379f1 | 2006-04-03 04:50:58 +0000 | [diff] [blame] | 638 | static int initialized; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 639 | if (initialized) return 1; |
Georg Brandl | 4aef703 | 2008-11-07 08:56:27 +0000 | [diff] [blame] | 640 | if (add_ast_fields() < 0) return 0; |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 641 | mod_type = make_type("mod", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 642 | if (!mod_type) return 0; |
| 643 | if (!add_attributes(mod_type, NULL, 0)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 644 | Module_type = make_type("Module", mod_type, Module_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 645 | if (!Module_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 646 | Interactive_type = make_type("Interactive", mod_type, |
| 647 | Interactive_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 648 | if (!Interactive_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 649 | Expression_type = make_type("Expression", mod_type, Expression_fields, |
| 650 | 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 651 | if (!Expression_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 652 | Suite_type = make_type("Suite", mod_type, Suite_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 653 | if (!Suite_type) return 0; |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 654 | stmt_type = make_type("stmt", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 655 | if (!stmt_type) return 0; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 656 | if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 657 | FunctionDef_type = make_type("FunctionDef", stmt_type, |
| 658 | FunctionDef_fields, 4); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 659 | if (!FunctionDef_type) return 0; |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 660 | ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 4); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 661 | if (!ClassDef_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 662 | Return_type = make_type("Return", stmt_type, Return_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 663 | if (!Return_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 664 | Delete_type = make_type("Delete", stmt_type, Delete_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 665 | if (!Delete_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 666 | Assign_type = make_type("Assign", stmt_type, Assign_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 667 | if (!Assign_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 668 | AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 669 | if (!AugAssign_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 670 | Print_type = make_type("Print", stmt_type, Print_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 671 | if (!Print_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 672 | For_type = make_type("For", stmt_type, For_fields, 4); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 673 | if (!For_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 674 | While_type = make_type("While", stmt_type, While_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 675 | if (!While_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 676 | If_type = make_type("If", stmt_type, If_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 677 | if (!If_type) return 0; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 678 | With_type = make_type("With", stmt_type, With_fields, 3); |
| 679 | if (!With_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 680 | Raise_type = make_type("Raise", stmt_type, Raise_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 681 | if (!Raise_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 682 | TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 683 | if (!TryExcept_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 684 | TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields, |
| 685 | 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 686 | if (!TryFinally_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 687 | Assert_type = make_type("Assert", stmt_type, Assert_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 688 | if (!Assert_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 689 | Import_type = make_type("Import", stmt_type, Import_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 690 | if (!Import_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 691 | ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 692 | 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 693 | if (!ImportFrom_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 694 | Exec_type = make_type("Exec", stmt_type, Exec_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 695 | if (!Exec_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 696 | Global_type = make_type("Global", stmt_type, Global_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 697 | if (!Global_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 698 | Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 699 | if (!Expr_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 700 | Pass_type = make_type("Pass", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 701 | if (!Pass_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 702 | Break_type = make_type("Break", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 703 | if (!Break_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 704 | Continue_type = make_type("Continue", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 705 | if (!Continue_type) return 0; |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 706 | expr_type = make_type("expr", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 707 | if (!expr_type) return 0; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 708 | if (!add_attributes(expr_type, expr_attributes, 2)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 709 | BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 710 | if (!BoolOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 711 | BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 712 | if (!BinOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 713 | UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 714 | if (!UnaryOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 715 | Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 716 | if (!Lambda_type) return 0; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 717 | IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 718 | if (!IfExp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 719 | Dict_type = make_type("Dict", expr_type, Dict_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 720 | if (!Dict_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 721 | ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 722 | if (!ListComp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 723 | GeneratorExp_type = make_type("GeneratorExp", expr_type, |
| 724 | GeneratorExp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 725 | if (!GeneratorExp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 726 | Yield_type = make_type("Yield", expr_type, Yield_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 727 | if (!Yield_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 728 | Compare_type = make_type("Compare", expr_type, Compare_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 729 | if (!Compare_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 730 | Call_type = make_type("Call", expr_type, Call_fields, 5); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 731 | if (!Call_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 732 | Repr_type = make_type("Repr", expr_type, Repr_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 733 | if (!Repr_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 734 | Num_type = make_type("Num", expr_type, Num_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 735 | if (!Num_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 736 | Str_type = make_type("Str", expr_type, Str_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 737 | if (!Str_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 738 | Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 739 | if (!Attribute_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 740 | Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 741 | if (!Subscript_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 742 | Name_type = make_type("Name", expr_type, Name_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 743 | if (!Name_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 744 | List_type = make_type("List", expr_type, List_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 745 | if (!List_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 746 | Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 747 | if (!Tuple_type) return 0; |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 748 | 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] | 749 | if (!expr_context_type) return 0; |
| 750 | if (!add_attributes(expr_context_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 751 | Load_type = make_type("Load", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 752 | if (!Load_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 753 | Load_singleton = PyType_GenericNew(Load_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 754 | if (!Load_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 755 | Store_type = make_type("Store", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 756 | if (!Store_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 757 | Store_singleton = PyType_GenericNew(Store_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 758 | if (!Store_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 759 | Del_type = make_type("Del", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 760 | if (!Del_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 761 | Del_singleton = PyType_GenericNew(Del_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 762 | if (!Del_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 763 | AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 764 | if (!AugLoad_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 765 | AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 766 | if (!AugLoad_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 767 | AugStore_type = make_type("AugStore", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 768 | if (!AugStore_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 769 | AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 770 | if (!AugStore_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 771 | Param_type = make_type("Param", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 772 | if (!Param_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 773 | Param_singleton = PyType_GenericNew(Param_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 774 | if (!Param_singleton) return 0; |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 775 | slice_type = make_type("slice", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 776 | if (!slice_type) return 0; |
| 777 | if (!add_attributes(slice_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 778 | Ellipsis_type = make_type("Ellipsis", slice_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 779 | if (!Ellipsis_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 780 | Slice_type = make_type("Slice", slice_type, Slice_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 781 | if (!Slice_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 782 | ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 783 | if (!ExtSlice_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 784 | Index_type = make_type("Index", slice_type, Index_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 785 | if (!Index_type) return 0; |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 786 | boolop_type = make_type("boolop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 787 | if (!boolop_type) return 0; |
| 788 | if (!add_attributes(boolop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 789 | And_type = make_type("And", boolop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 790 | if (!And_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 791 | And_singleton = PyType_GenericNew(And_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 792 | if (!And_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 793 | Or_type = make_type("Or", boolop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 794 | if (!Or_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 795 | Or_singleton = PyType_GenericNew(Or_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 796 | if (!Or_singleton) return 0; |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 797 | operator_type = make_type("operator", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 798 | if (!operator_type) return 0; |
| 799 | if (!add_attributes(operator_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 800 | Add_type = make_type("Add", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 801 | if (!Add_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 802 | Add_singleton = PyType_GenericNew(Add_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 803 | if (!Add_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 804 | Sub_type = make_type("Sub", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 805 | if (!Sub_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 806 | Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 807 | if (!Sub_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 808 | Mult_type = make_type("Mult", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 809 | if (!Mult_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 810 | Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 811 | if (!Mult_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 812 | Div_type = make_type("Div", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 813 | if (!Div_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 814 | Div_singleton = PyType_GenericNew(Div_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 815 | if (!Div_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 816 | Mod_type = make_type("Mod", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 817 | if (!Mod_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 818 | Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 819 | if (!Mod_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 820 | Pow_type = make_type("Pow", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 821 | if (!Pow_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 822 | Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 823 | if (!Pow_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 824 | LShift_type = make_type("LShift", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 825 | if (!LShift_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 826 | LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 827 | if (!LShift_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 828 | RShift_type = make_type("RShift", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 829 | if (!RShift_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 830 | RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 831 | if (!RShift_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 832 | BitOr_type = make_type("BitOr", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 833 | if (!BitOr_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 834 | BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 835 | if (!BitOr_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 836 | BitXor_type = make_type("BitXor", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 837 | if (!BitXor_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 838 | BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 839 | if (!BitXor_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 840 | BitAnd_type = make_type("BitAnd", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 841 | if (!BitAnd_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 842 | BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 843 | if (!BitAnd_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 844 | FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 845 | if (!FloorDiv_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 846 | FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 847 | if (!FloorDiv_singleton) return 0; |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 848 | unaryop_type = make_type("unaryop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 849 | if (!unaryop_type) return 0; |
| 850 | if (!add_attributes(unaryop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 851 | Invert_type = make_type("Invert", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 852 | if (!Invert_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 853 | Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 854 | if (!Invert_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 855 | Not_type = make_type("Not", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 856 | if (!Not_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 857 | Not_singleton = PyType_GenericNew(Not_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 858 | if (!Not_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 859 | UAdd_type = make_type("UAdd", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 860 | if (!UAdd_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 861 | UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 862 | if (!UAdd_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 863 | USub_type = make_type("USub", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 864 | if (!USub_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 865 | USub_singleton = PyType_GenericNew(USub_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 866 | if (!USub_singleton) return 0; |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 867 | cmpop_type = make_type("cmpop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 868 | if (!cmpop_type) return 0; |
| 869 | if (!add_attributes(cmpop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 870 | Eq_type = make_type("Eq", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 871 | if (!Eq_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 872 | Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 873 | if (!Eq_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 874 | NotEq_type = make_type("NotEq", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 875 | if (!NotEq_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 876 | NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 877 | if (!NotEq_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 878 | Lt_type = make_type("Lt", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 879 | if (!Lt_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 880 | Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 881 | if (!Lt_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 882 | LtE_type = make_type("LtE", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 883 | if (!LtE_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 884 | LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 885 | if (!LtE_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 886 | Gt_type = make_type("Gt", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 887 | if (!Gt_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 888 | Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 889 | if (!Gt_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 890 | GtE_type = make_type("GtE", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 891 | if (!GtE_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 892 | GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 893 | if (!GtE_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 894 | Is_type = make_type("Is", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 895 | if (!Is_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 896 | Is_singleton = PyType_GenericNew(Is_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 897 | if (!Is_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 898 | IsNot_type = make_type("IsNot", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 899 | if (!IsNot_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 900 | IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 901 | if (!IsNot_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 902 | In_type = make_type("In", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 903 | if (!In_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 904 | In_singleton = PyType_GenericNew(In_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 905 | if (!In_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 906 | NotIn_type = make_type("NotIn", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 907 | if (!NotIn_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 908 | NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 909 | if (!NotIn_singleton) return 0; |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 910 | comprehension_type = make_type("comprehension", &AST_type, |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 911 | comprehension_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 912 | if (!comprehension_type) return 0; |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 913 | excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 914 | if (!excepthandler_type) return 0; |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame] | 915 | if (!add_attributes(excepthandler_type, excepthandler_attributes, 2)) |
| 916 | return 0; |
| 917 | ExceptHandler_type = make_type("ExceptHandler", excepthandler_type, |
| 918 | ExceptHandler_fields, 3); |
| 919 | if (!ExceptHandler_type) return 0; |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 920 | arguments_type = make_type("arguments", &AST_type, arguments_fields, 4); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 921 | if (!arguments_type) return 0; |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 922 | keyword_type = make_type("keyword", &AST_type, keyword_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 923 | if (!keyword_type) return 0; |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 924 | alias_type = make_type("alias", &AST_type, alias_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 925 | if (!alias_type) return 0; |
| 926 | initialized = 1; |
| 927 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 928 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 929 | |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 930 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 931 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 932 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 933 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 934 | arena); |
| 935 | static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena); |
| 936 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 937 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 938 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 939 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 940 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 941 | arena); |
| 942 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 943 | arena); |
| 944 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 945 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 946 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
| 947 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 948 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 949 | Module(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 950 | { |
| 951 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 952 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 953 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 954 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 955 | p->kind = Module_kind; |
| 956 | p->v.Module.body = body; |
| 957 | return p; |
| 958 | } |
| 959 | |
| 960 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 961 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 962 | { |
| 963 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 964 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 965 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 966 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 967 | p->kind = Interactive_kind; |
| 968 | p->v.Interactive.body = body; |
| 969 | return p; |
| 970 | } |
| 971 | |
| 972 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 973 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 974 | { |
| 975 | mod_ty p; |
| 976 | if (!body) { |
| 977 | PyErr_SetString(PyExc_ValueError, |
| 978 | "field body is required for Expression"); |
| 979 | return NULL; |
| 980 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 981 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 982 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 983 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 984 | p->kind = Expression_kind; |
| 985 | p->v.Expression.body = body; |
| 986 | return p; |
| 987 | } |
| 988 | |
| 989 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 990 | Suite(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 991 | { |
| 992 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 993 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 994 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 995 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 996 | p->kind = Suite_kind; |
| 997 | p->v.Suite.body = body; |
| 998 | return p; |
| 999 | } |
| 1000 | |
| 1001 | stmt_ty |
| 1002 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 1003 | decorator_list, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1004 | { |
| 1005 | stmt_ty p; |
| 1006 | if (!name) { |
| 1007 | PyErr_SetString(PyExc_ValueError, |
| 1008 | "field name is required for FunctionDef"); |
| 1009 | return NULL; |
| 1010 | } |
| 1011 | if (!args) { |
| 1012 | PyErr_SetString(PyExc_ValueError, |
| 1013 | "field args is required for FunctionDef"); |
| 1014 | return NULL; |
| 1015 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1016 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1017 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1018 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1019 | p->kind = FunctionDef_kind; |
| 1020 | p->v.FunctionDef.name = name; |
| 1021 | p->v.FunctionDef.args = args; |
| 1022 | p->v.FunctionDef.body = body; |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 1023 | p->v.FunctionDef.decorator_list = decorator_list; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1024 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1025 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1026 | return p; |
| 1027 | } |
| 1028 | |
| 1029 | stmt_ty |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 1030 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, asdl_seq * |
| 1031 | decorator_list, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1032 | { |
| 1033 | stmt_ty p; |
| 1034 | if (!name) { |
| 1035 | PyErr_SetString(PyExc_ValueError, |
| 1036 | "field name is required for ClassDef"); |
| 1037 | return NULL; |
| 1038 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1039 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1040 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1041 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1042 | p->kind = ClassDef_kind; |
| 1043 | p->v.ClassDef.name = name; |
| 1044 | p->v.ClassDef.bases = bases; |
| 1045 | p->v.ClassDef.body = body; |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 1046 | p->v.ClassDef.decorator_list = decorator_list; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1047 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1048 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1049 | return p; |
| 1050 | } |
| 1051 | |
| 1052 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1053 | Return(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1054 | { |
| 1055 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1056 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1057 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1058 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1059 | p->kind = Return_kind; |
| 1060 | p->v.Return.value = value; |
| 1061 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1062 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1063 | return p; |
| 1064 | } |
| 1065 | |
| 1066 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1067 | Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1068 | { |
| 1069 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1070 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1071 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1072 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1073 | p->kind = Delete_kind; |
| 1074 | p->v.Delete.targets = targets; |
| 1075 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1076 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1077 | return p; |
| 1078 | } |
| 1079 | |
| 1080 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1081 | Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena |
| 1082 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1083 | { |
| 1084 | stmt_ty p; |
| 1085 | if (!value) { |
| 1086 | PyErr_SetString(PyExc_ValueError, |
| 1087 | "field value is required for Assign"); |
| 1088 | return NULL; |
| 1089 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1090 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1091 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1092 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1093 | p->kind = Assign_kind; |
| 1094 | p->v.Assign.targets = targets; |
| 1095 | p->v.Assign.value = value; |
| 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 | AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int |
| 1103 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1104 | { |
| 1105 | stmt_ty p; |
| 1106 | if (!target) { |
| 1107 | PyErr_SetString(PyExc_ValueError, |
| 1108 | "field target is required for AugAssign"); |
| 1109 | return NULL; |
| 1110 | } |
| 1111 | if (!op) { |
| 1112 | PyErr_SetString(PyExc_ValueError, |
| 1113 | "field op is required for AugAssign"); |
| 1114 | return NULL; |
| 1115 | } |
| 1116 | if (!value) { |
| 1117 | PyErr_SetString(PyExc_ValueError, |
| 1118 | "field value is required for AugAssign"); |
| 1119 | return NULL; |
| 1120 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1121 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1122 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1123 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1124 | p->kind = AugAssign_kind; |
| 1125 | p->v.AugAssign.target = target; |
| 1126 | p->v.AugAssign.op = op; |
| 1127 | p->v.AugAssign.value = value; |
| 1128 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1129 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1130 | return p; |
| 1131 | } |
| 1132 | |
| 1133 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1134 | Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int col_offset, |
| 1135 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1136 | { |
| 1137 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1138 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1139 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1140 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1141 | p->kind = Print_kind; |
| 1142 | p->v.Print.dest = dest; |
| 1143 | p->v.Print.values = values; |
| 1144 | p->v.Print.nl = nl; |
| 1145 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1146 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1147 | return p; |
| 1148 | } |
| 1149 | |
| 1150 | stmt_ty |
| 1151 | 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] | 1152 | lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1153 | { |
| 1154 | stmt_ty p; |
| 1155 | if (!target) { |
| 1156 | PyErr_SetString(PyExc_ValueError, |
| 1157 | "field target is required for For"); |
| 1158 | return NULL; |
| 1159 | } |
| 1160 | if (!iter) { |
| 1161 | PyErr_SetString(PyExc_ValueError, |
| 1162 | "field iter is required for For"); |
| 1163 | return NULL; |
| 1164 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1165 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1166 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1167 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1168 | p->kind = For_kind; |
| 1169 | p->v.For.target = target; |
| 1170 | p->v.For.iter = iter; |
| 1171 | p->v.For.body = body; |
| 1172 | p->v.For.orelse = orelse; |
| 1173 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1174 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1175 | return p; |
| 1176 | } |
| 1177 | |
| 1178 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1179 | While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1180 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1181 | { |
| 1182 | stmt_ty p; |
| 1183 | if (!test) { |
| 1184 | PyErr_SetString(PyExc_ValueError, |
| 1185 | "field test is required for While"); |
| 1186 | return NULL; |
| 1187 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1188 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1189 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1190 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1191 | p->kind = While_kind; |
| 1192 | p->v.While.test = test; |
| 1193 | p->v.While.body = body; |
| 1194 | p->v.While.orelse = orelse; |
| 1195 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1196 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1197 | return p; |
| 1198 | } |
| 1199 | |
| 1200 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1201 | If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1202 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1203 | { |
| 1204 | stmt_ty p; |
| 1205 | if (!test) { |
| 1206 | PyErr_SetString(PyExc_ValueError, |
| 1207 | "field test is required for If"); |
| 1208 | return NULL; |
| 1209 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1210 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1211 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1212 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1213 | p->kind = If_kind; |
| 1214 | p->v.If.test = test; |
| 1215 | p->v.If.body = body; |
| 1216 | p->v.If.orelse = orelse; |
| 1217 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1218 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1219 | return p; |
| 1220 | } |
| 1221 | |
| 1222 | stmt_ty |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1223 | 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] | 1224 | int col_offset, PyArena *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1225 | { |
| 1226 | stmt_ty p; |
| 1227 | if (!context_expr) { |
| 1228 | PyErr_SetString(PyExc_ValueError, |
| 1229 | "field context_expr is required for With"); |
| 1230 | return NULL; |
| 1231 | } |
| 1232 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1233 | if (!p) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1234 | return NULL; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1235 | p->kind = With_kind; |
| 1236 | p->v.With.context_expr = context_expr; |
| 1237 | p->v.With.optional_vars = optional_vars; |
| 1238 | p->v.With.body = body; |
| 1239 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1240 | p->col_offset = col_offset; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1241 | return p; |
| 1242 | } |
| 1243 | |
| 1244 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1245 | Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset, |
| 1246 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1247 | { |
| 1248 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1249 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1250 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1251 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1252 | p->kind = Raise_kind; |
| 1253 | p->v.Raise.type = type; |
| 1254 | p->v.Raise.inst = inst; |
| 1255 | p->v.Raise.tback = tback; |
| 1256 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1257 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1258 | return p; |
| 1259 | } |
| 1260 | |
| 1261 | stmt_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1262 | 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] | 1263 | int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1264 | { |
| 1265 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1266 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1267 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1268 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1269 | p->kind = TryExcept_kind; |
| 1270 | p->v.TryExcept.body = body; |
| 1271 | p->v.TryExcept.handlers = handlers; |
| 1272 | p->v.TryExcept.orelse = orelse; |
| 1273 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1274 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1275 | return p; |
| 1276 | } |
| 1277 | |
| 1278 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1279 | TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset, |
| 1280 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1281 | { |
| 1282 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1283 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1284 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1285 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1286 | p->kind = TryFinally_kind; |
| 1287 | p->v.TryFinally.body = body; |
| 1288 | p->v.TryFinally.finalbody = finalbody; |
| 1289 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1290 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1291 | return p; |
| 1292 | } |
| 1293 | |
| 1294 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1295 | 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] | 1296 | { |
| 1297 | stmt_ty p; |
| 1298 | if (!test) { |
| 1299 | PyErr_SetString(PyExc_ValueError, |
| 1300 | "field test is required for Assert"); |
| 1301 | return NULL; |
| 1302 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1303 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1304 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1305 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1306 | p->kind = Assert_kind; |
| 1307 | p->v.Assert.test = test; |
| 1308 | p->v.Assert.msg = msg; |
| 1309 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1310 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1311 | return p; |
| 1312 | } |
| 1313 | |
| 1314 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1315 | Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1316 | { |
| 1317 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1318 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1319 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1320 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1321 | p->kind = Import_kind; |
| 1322 | p->v.Import.names = names; |
| 1323 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1324 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1325 | return p; |
| 1326 | } |
| 1327 | |
| 1328 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1329 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
| 1330 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1331 | { |
| 1332 | stmt_ty p; |
| 1333 | if (!module) { |
| 1334 | PyErr_SetString(PyExc_ValueError, |
| 1335 | "field module is required for ImportFrom"); |
| 1336 | return NULL; |
| 1337 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1338 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1339 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1340 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1341 | p->kind = ImportFrom_kind; |
| 1342 | p->v.ImportFrom.module = module; |
| 1343 | p->v.ImportFrom.names = names; |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 1344 | p->v.ImportFrom.level = level; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1345 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1346 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1347 | return p; |
| 1348 | } |
| 1349 | |
| 1350 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1351 | Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, int col_offset, |
| 1352 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1353 | { |
| 1354 | stmt_ty p; |
| 1355 | if (!body) { |
| 1356 | PyErr_SetString(PyExc_ValueError, |
| 1357 | "field body is required for Exec"); |
| 1358 | return NULL; |
| 1359 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1360 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1361 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1362 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1363 | p->kind = Exec_kind; |
| 1364 | p->v.Exec.body = body; |
| 1365 | p->v.Exec.globals = globals; |
| 1366 | p->v.Exec.locals = locals; |
| 1367 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1368 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1369 | return p; |
| 1370 | } |
| 1371 | |
| 1372 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1373 | Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1374 | { |
| 1375 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1376 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1377 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1378 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1379 | p->kind = Global_kind; |
| 1380 | p->v.Global.names = names; |
| 1381 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1382 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1383 | return p; |
| 1384 | } |
| 1385 | |
| 1386 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1387 | Expr(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1388 | { |
| 1389 | stmt_ty p; |
| 1390 | if (!value) { |
| 1391 | PyErr_SetString(PyExc_ValueError, |
| 1392 | "field value is required for Expr"); |
| 1393 | return NULL; |
| 1394 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1395 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1396 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1397 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1398 | p->kind = Expr_kind; |
| 1399 | p->v.Expr.value = value; |
| 1400 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1401 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1402 | return p; |
| 1403 | } |
| 1404 | |
| 1405 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1406 | Pass(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1407 | { |
| 1408 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1409 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1410 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1411 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1412 | p->kind = Pass_kind; |
| 1413 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1414 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1415 | return p; |
| 1416 | } |
| 1417 | |
| 1418 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1419 | Break(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1420 | { |
| 1421 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1422 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1423 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1424 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1425 | p->kind = Break_kind; |
| 1426 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1427 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1428 | return p; |
| 1429 | } |
| 1430 | |
| 1431 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1432 | Continue(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1433 | { |
| 1434 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1435 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1436 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1437 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1438 | p->kind = Continue_kind; |
| 1439 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1440 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1441 | return p; |
| 1442 | } |
| 1443 | |
| 1444 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1445 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1446 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1447 | { |
| 1448 | expr_ty p; |
| 1449 | if (!op) { |
| 1450 | PyErr_SetString(PyExc_ValueError, |
| 1451 | "field op is required for BoolOp"); |
| 1452 | return NULL; |
| 1453 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1454 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1455 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1456 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1457 | p->kind = BoolOp_kind; |
| 1458 | p->v.BoolOp.op = op; |
| 1459 | p->v.BoolOp.values = values; |
| 1460 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1461 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1462 | return p; |
| 1463 | } |
| 1464 | |
| 1465 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1466 | BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset, |
| 1467 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1468 | { |
| 1469 | expr_ty p; |
| 1470 | if (!left) { |
| 1471 | PyErr_SetString(PyExc_ValueError, |
| 1472 | "field left is required for BinOp"); |
| 1473 | return NULL; |
| 1474 | } |
| 1475 | if (!op) { |
| 1476 | PyErr_SetString(PyExc_ValueError, |
| 1477 | "field op is required for BinOp"); |
| 1478 | return NULL; |
| 1479 | } |
| 1480 | if (!right) { |
| 1481 | PyErr_SetString(PyExc_ValueError, |
| 1482 | "field right is required for BinOp"); |
| 1483 | return NULL; |
| 1484 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1485 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1486 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1487 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1488 | p->kind = BinOp_kind; |
| 1489 | p->v.BinOp.left = left; |
| 1490 | p->v.BinOp.op = op; |
| 1491 | p->v.BinOp.right = right; |
| 1492 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1493 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1494 | return p; |
| 1495 | } |
| 1496 | |
| 1497 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1498 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena |
| 1499 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1500 | { |
| 1501 | expr_ty p; |
| 1502 | if (!op) { |
| 1503 | PyErr_SetString(PyExc_ValueError, |
| 1504 | "field op is required for UnaryOp"); |
| 1505 | return NULL; |
| 1506 | } |
| 1507 | if (!operand) { |
| 1508 | PyErr_SetString(PyExc_ValueError, |
| 1509 | "field operand is required for UnaryOp"); |
| 1510 | return NULL; |
| 1511 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1512 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1513 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1514 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1515 | p->kind = UnaryOp_kind; |
| 1516 | p->v.UnaryOp.op = op; |
| 1517 | p->v.UnaryOp.operand = operand; |
| 1518 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1519 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1520 | return p; |
| 1521 | } |
| 1522 | |
| 1523 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1524 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena |
| 1525 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1526 | { |
| 1527 | expr_ty p; |
| 1528 | if (!args) { |
| 1529 | PyErr_SetString(PyExc_ValueError, |
| 1530 | "field args is required for Lambda"); |
| 1531 | return NULL; |
| 1532 | } |
| 1533 | if (!body) { |
| 1534 | PyErr_SetString(PyExc_ValueError, |
| 1535 | "field body is required for Lambda"); |
| 1536 | return NULL; |
| 1537 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1538 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1539 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1540 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1541 | p->kind = Lambda_kind; |
| 1542 | p->v.Lambda.args = args; |
| 1543 | p->v.Lambda.body = body; |
| 1544 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1545 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1546 | return p; |
| 1547 | } |
| 1548 | |
| 1549 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1550 | IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset, |
| 1551 | PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1552 | { |
| 1553 | expr_ty p; |
| 1554 | if (!test) { |
| 1555 | PyErr_SetString(PyExc_ValueError, |
| 1556 | "field test is required for IfExp"); |
| 1557 | return NULL; |
| 1558 | } |
| 1559 | if (!body) { |
| 1560 | PyErr_SetString(PyExc_ValueError, |
| 1561 | "field body is required for IfExp"); |
| 1562 | return NULL; |
| 1563 | } |
| 1564 | if (!orelse) { |
| 1565 | PyErr_SetString(PyExc_ValueError, |
| 1566 | "field orelse is required for IfExp"); |
| 1567 | return NULL; |
| 1568 | } |
| 1569 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1570 | if (!p) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1571 | return NULL; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1572 | p->kind = IfExp_kind; |
| 1573 | p->v.IfExp.test = test; |
| 1574 | p->v.IfExp.body = body; |
| 1575 | p->v.IfExp.orelse = orelse; |
| 1576 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1577 | p->col_offset = col_offset; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1578 | return p; |
| 1579 | } |
| 1580 | |
| 1581 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1582 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1583 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1584 | { |
| 1585 | expr_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1586 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1587 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1588 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1589 | p->kind = Dict_kind; |
| 1590 | p->v.Dict.keys = keys; |
| 1591 | p->v.Dict.values = values; |
| 1592 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1593 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1594 | return p; |
| 1595 | } |
| 1596 | |
| 1597 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1598 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1599 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1600 | { |
| 1601 | expr_ty p; |
| 1602 | if (!elt) { |
| 1603 | PyErr_SetString(PyExc_ValueError, |
| 1604 | "field elt is required for ListComp"); |
| 1605 | return NULL; |
| 1606 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1607 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1608 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1609 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1610 | p->kind = ListComp_kind; |
| 1611 | p->v.ListComp.elt = elt; |
| 1612 | p->v.ListComp.generators = generators; |
| 1613 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1614 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1615 | return p; |
| 1616 | } |
| 1617 | |
| 1618 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1619 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1620 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1621 | { |
| 1622 | expr_ty p; |
| 1623 | if (!elt) { |
| 1624 | PyErr_SetString(PyExc_ValueError, |
| 1625 | "field elt is required for GeneratorExp"); |
| 1626 | return NULL; |
| 1627 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1628 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1629 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1630 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1631 | p->kind = GeneratorExp_kind; |
| 1632 | p->v.GeneratorExp.elt = elt; |
| 1633 | p->v.GeneratorExp.generators = generators; |
| 1634 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1635 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1636 | return p; |
| 1637 | } |
| 1638 | |
| 1639 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1640 | Yield(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1641 | { |
| 1642 | expr_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1643 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1644 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1645 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1646 | p->kind = Yield_kind; |
| 1647 | p->v.Yield.value = value; |
| 1648 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1649 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1650 | return p; |
| 1651 | } |
| 1652 | |
| 1653 | expr_ty |
Martin v. Löwis | 0cc56e5 | 2006-04-13 12:29:43 +0000 | [diff] [blame] | 1654 | Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno, |
| 1655 | int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1656 | { |
| 1657 | expr_ty p; |
| 1658 | if (!left) { |
| 1659 | PyErr_SetString(PyExc_ValueError, |
| 1660 | "field left is required for Compare"); |
| 1661 | return NULL; |
| 1662 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1663 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1664 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1665 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1666 | p->kind = Compare_kind; |
| 1667 | p->v.Compare.left = left; |
| 1668 | p->v.Compare.ops = ops; |
| 1669 | p->v.Compare.comparators = comparators; |
| 1670 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1671 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1672 | return p; |
| 1673 | } |
| 1674 | |
| 1675 | expr_ty |
| 1676 | 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] | 1677 | expr_ty kwargs, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1678 | { |
| 1679 | expr_ty p; |
| 1680 | if (!func) { |
| 1681 | PyErr_SetString(PyExc_ValueError, |
| 1682 | "field func is required for Call"); |
| 1683 | return NULL; |
| 1684 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1685 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1686 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1687 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1688 | p->kind = Call_kind; |
| 1689 | p->v.Call.func = func; |
| 1690 | p->v.Call.args = args; |
| 1691 | p->v.Call.keywords = keywords; |
| 1692 | p->v.Call.starargs = starargs; |
| 1693 | p->v.Call.kwargs = kwargs; |
| 1694 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1695 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1696 | return p; |
| 1697 | } |
| 1698 | |
| 1699 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1700 | Repr(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1701 | { |
| 1702 | expr_ty p; |
| 1703 | if (!value) { |
| 1704 | PyErr_SetString(PyExc_ValueError, |
| 1705 | "field value is required for Repr"); |
| 1706 | return NULL; |
| 1707 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1708 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1709 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1710 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1711 | p->kind = Repr_kind; |
| 1712 | p->v.Repr.value = value; |
| 1713 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1714 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1715 | return p; |
| 1716 | } |
| 1717 | |
| 1718 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1719 | Num(object n, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1720 | { |
| 1721 | expr_ty p; |
| 1722 | if (!n) { |
| 1723 | PyErr_SetString(PyExc_ValueError, |
| 1724 | "field n is required for Num"); |
| 1725 | return NULL; |
| 1726 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1727 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1728 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1729 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1730 | p->kind = Num_kind; |
| 1731 | p->v.Num.n = n; |
| 1732 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1733 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1734 | return p; |
| 1735 | } |
| 1736 | |
| 1737 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1738 | Str(string s, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1739 | { |
| 1740 | expr_ty p; |
| 1741 | if (!s) { |
| 1742 | PyErr_SetString(PyExc_ValueError, |
| 1743 | "field s is required for Str"); |
| 1744 | return NULL; |
| 1745 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1746 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1747 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1748 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1749 | p->kind = Str_kind; |
| 1750 | p->v.Str.s = s; |
| 1751 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1752 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1753 | return p; |
| 1754 | } |
| 1755 | |
| 1756 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1757 | Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int |
| 1758 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1759 | { |
| 1760 | expr_ty p; |
| 1761 | if (!value) { |
| 1762 | PyErr_SetString(PyExc_ValueError, |
| 1763 | "field value is required for Attribute"); |
| 1764 | return NULL; |
| 1765 | } |
| 1766 | if (!attr) { |
| 1767 | PyErr_SetString(PyExc_ValueError, |
| 1768 | "field attr is required for Attribute"); |
| 1769 | return NULL; |
| 1770 | } |
| 1771 | if (!ctx) { |
| 1772 | PyErr_SetString(PyExc_ValueError, |
| 1773 | "field ctx is required for Attribute"); |
| 1774 | return NULL; |
| 1775 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1776 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1777 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1778 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1779 | p->kind = Attribute_kind; |
| 1780 | p->v.Attribute.value = value; |
| 1781 | p->v.Attribute.attr = attr; |
| 1782 | p->v.Attribute.ctx = ctx; |
| 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 |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1789 | Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int |
| 1790 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1791 | { |
| 1792 | expr_ty p; |
| 1793 | if (!value) { |
| 1794 | PyErr_SetString(PyExc_ValueError, |
| 1795 | "field value is required for Subscript"); |
| 1796 | return NULL; |
| 1797 | } |
| 1798 | if (!slice) { |
| 1799 | PyErr_SetString(PyExc_ValueError, |
| 1800 | "field slice is required for Subscript"); |
| 1801 | return NULL; |
| 1802 | } |
| 1803 | if (!ctx) { |
| 1804 | PyErr_SetString(PyExc_ValueError, |
| 1805 | "field ctx is required for Subscript"); |
| 1806 | return NULL; |
| 1807 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1808 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1809 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1810 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1811 | p->kind = Subscript_kind; |
| 1812 | p->v.Subscript.value = value; |
| 1813 | p->v.Subscript.slice = slice; |
| 1814 | p->v.Subscript.ctx = ctx; |
| 1815 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1816 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1817 | return p; |
| 1818 | } |
| 1819 | |
| 1820 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1821 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1822 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1823 | { |
| 1824 | expr_ty p; |
| 1825 | if (!id) { |
| 1826 | PyErr_SetString(PyExc_ValueError, |
| 1827 | "field id is required for Name"); |
| 1828 | return NULL; |
| 1829 | } |
| 1830 | if (!ctx) { |
| 1831 | PyErr_SetString(PyExc_ValueError, |
| 1832 | "field ctx is required for Name"); |
| 1833 | return NULL; |
| 1834 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1835 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1836 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1837 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1838 | p->kind = Name_kind; |
| 1839 | p->v.Name.id = id; |
| 1840 | p->v.Name.ctx = ctx; |
| 1841 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1842 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1843 | return p; |
| 1844 | } |
| 1845 | |
| 1846 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1847 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1848 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1849 | { |
| 1850 | expr_ty p; |
| 1851 | if (!ctx) { |
| 1852 | PyErr_SetString(PyExc_ValueError, |
| 1853 | "field ctx is required for List"); |
| 1854 | return NULL; |
| 1855 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1856 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1857 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1858 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1859 | p->kind = List_kind; |
| 1860 | p->v.List.elts = elts; |
| 1861 | p->v.List.ctx = ctx; |
| 1862 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1863 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1864 | return p; |
| 1865 | } |
| 1866 | |
| 1867 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1868 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1869 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1870 | { |
| 1871 | expr_ty p; |
| 1872 | if (!ctx) { |
| 1873 | PyErr_SetString(PyExc_ValueError, |
| 1874 | "field ctx is required for Tuple"); |
| 1875 | return NULL; |
| 1876 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1877 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1878 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1879 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1880 | p->kind = Tuple_kind; |
| 1881 | p->v.Tuple.elts = elts; |
| 1882 | p->v.Tuple.ctx = ctx; |
| 1883 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1884 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1885 | return p; |
| 1886 | } |
| 1887 | |
| 1888 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1889 | Ellipsis(PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1890 | { |
| 1891 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1892 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1893 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1894 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1895 | p->kind = Ellipsis_kind; |
| 1896 | return p; |
| 1897 | } |
| 1898 | |
| 1899 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1900 | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1901 | { |
| 1902 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1903 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1904 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1905 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1906 | p->kind = Slice_kind; |
| 1907 | p->v.Slice.lower = lower; |
| 1908 | p->v.Slice.upper = upper; |
| 1909 | p->v.Slice.step = step; |
| 1910 | return p; |
| 1911 | } |
| 1912 | |
| 1913 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1914 | ExtSlice(asdl_seq * dims, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1915 | { |
| 1916 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1917 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1918 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1919 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1920 | p->kind = ExtSlice_kind; |
| 1921 | p->v.ExtSlice.dims = dims; |
| 1922 | return p; |
| 1923 | } |
| 1924 | |
| 1925 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1926 | Index(expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1927 | { |
| 1928 | slice_ty p; |
| 1929 | if (!value) { |
| 1930 | PyErr_SetString(PyExc_ValueError, |
| 1931 | "field value is required for Index"); |
| 1932 | return NULL; |
| 1933 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1934 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1935 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1936 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1937 | p->kind = Index_kind; |
| 1938 | p->v.Index.value = value; |
| 1939 | return p; |
| 1940 | } |
| 1941 | |
| 1942 | comprehension_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1943 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1944 | { |
| 1945 | comprehension_ty p; |
| 1946 | if (!target) { |
| 1947 | PyErr_SetString(PyExc_ValueError, |
| 1948 | "field target is required for comprehension"); |
| 1949 | return NULL; |
| 1950 | } |
| 1951 | if (!iter) { |
| 1952 | PyErr_SetString(PyExc_ValueError, |
| 1953 | "field iter is required for comprehension"); |
| 1954 | return NULL; |
| 1955 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1956 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1957 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1958 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1959 | p->target = target; |
| 1960 | p->iter = iter; |
| 1961 | p->ifs = ifs; |
| 1962 | return p; |
| 1963 | } |
| 1964 | |
| 1965 | excepthandler_ty |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame] | 1966 | ExceptHandler(expr_ty type, expr_ty name, asdl_seq * body, int lineno, int |
Jeremy Hylton | 2f327c1 | 2006-04-04 04:00:23 +0000 | [diff] [blame] | 1967 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1968 | { |
| 1969 | excepthandler_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1970 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1971 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1972 | return NULL; |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame] | 1973 | p->kind = ExceptHandler_kind; |
| 1974 | p->v.ExceptHandler.type = type; |
| 1975 | p->v.ExceptHandler.name = name; |
| 1976 | p->v.ExceptHandler.body = body; |
Jeremy Hylton | 2f327c1 | 2006-04-04 04:00:23 +0000 | [diff] [blame] | 1977 | p->lineno = lineno; |
| 1978 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1979 | return p; |
| 1980 | } |
| 1981 | |
| 1982 | arguments_ty |
| 1983 | arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq * |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1984 | defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1985 | { |
| 1986 | arguments_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1987 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1988 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1989 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1990 | p->args = args; |
| 1991 | p->vararg = vararg; |
| 1992 | p->kwarg = kwarg; |
| 1993 | p->defaults = defaults; |
| 1994 | return p; |
| 1995 | } |
| 1996 | |
| 1997 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1998 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1999 | { |
| 2000 | keyword_ty p; |
| 2001 | if (!arg) { |
| 2002 | PyErr_SetString(PyExc_ValueError, |
| 2003 | "field arg is required for keyword"); |
| 2004 | return NULL; |
| 2005 | } |
| 2006 | if (!value) { |
| 2007 | PyErr_SetString(PyExc_ValueError, |
| 2008 | "field value is required for keyword"); |
| 2009 | return NULL; |
| 2010 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2011 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 2012 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2013 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2014 | p->arg = arg; |
| 2015 | p->value = value; |
| 2016 | return p; |
| 2017 | } |
| 2018 | |
| 2019 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2020 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2021 | { |
| 2022 | alias_ty p; |
| 2023 | if (!name) { |
| 2024 | PyErr_SetString(PyExc_ValueError, |
| 2025 | "field name is required for alias"); |
| 2026 | return NULL; |
| 2027 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2028 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 2029 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2030 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2031 | p->name = name; |
| 2032 | p->asname = asname; |
| 2033 | return p; |
| 2034 | } |
| 2035 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2036 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2037 | PyObject* |
| 2038 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2039 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2040 | mod_ty o = (mod_ty)_o; |
| 2041 | PyObject *result = NULL, *value = NULL; |
| 2042 | if (!o) { |
| 2043 | Py_INCREF(Py_None); |
| 2044 | return Py_None; |
| 2045 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2046 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2047 | switch (o->kind) { |
| 2048 | case Module_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2049 | result = PyType_GenericNew(Module_type, NULL, NULL); |
| 2050 | if (!result) goto failed; |
| 2051 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 2052 | if (!value) goto failed; |
| 2053 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2054 | goto failed; |
| 2055 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2056 | break; |
| 2057 | case Interactive_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2058 | result = PyType_GenericNew(Interactive_type, NULL, NULL); |
| 2059 | if (!result) goto failed; |
| 2060 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 2061 | if (!value) goto failed; |
| 2062 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2063 | goto failed; |
| 2064 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2065 | break; |
| 2066 | case Expression_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2067 | result = PyType_GenericNew(Expression_type, NULL, NULL); |
| 2068 | if (!result) goto failed; |
| 2069 | value = ast2obj_expr(o->v.Expression.body); |
| 2070 | if (!value) goto failed; |
| 2071 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2072 | goto failed; |
| 2073 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2074 | break; |
| 2075 | case Suite_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2076 | result = PyType_GenericNew(Suite_type, NULL, NULL); |
| 2077 | if (!result) goto failed; |
| 2078 | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
| 2079 | if (!value) goto failed; |
| 2080 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2081 | goto failed; |
| 2082 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2083 | break; |
| 2084 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2085 | return result; |
| 2086 | failed: |
| 2087 | Py_XDECREF(value); |
| 2088 | Py_XDECREF(result); |
| 2089 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2090 | } |
| 2091 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2092 | PyObject* |
| 2093 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2094 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2095 | stmt_ty o = (stmt_ty)_o; |
| 2096 | PyObject *result = NULL, *value = NULL; |
| 2097 | if (!o) { |
| 2098 | Py_INCREF(Py_None); |
| 2099 | return Py_None; |
| 2100 | } |
| 2101 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2102 | switch (o->kind) { |
| 2103 | case FunctionDef_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2104 | result = PyType_GenericNew(FunctionDef_type, NULL, NULL); |
| 2105 | if (!result) goto failed; |
| 2106 | value = ast2obj_identifier(o->v.FunctionDef.name); |
| 2107 | if (!value) goto failed; |
| 2108 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 2109 | goto failed; |
| 2110 | Py_DECREF(value); |
| 2111 | value = ast2obj_arguments(o->v.FunctionDef.args); |
| 2112 | if (!value) goto failed; |
| 2113 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 2114 | goto failed; |
| 2115 | Py_DECREF(value); |
| 2116 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 2117 | if (!value) goto failed; |
| 2118 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2119 | goto failed; |
| 2120 | Py_DECREF(value); |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 2121 | value = ast2obj_list(o->v.FunctionDef.decorator_list, |
| 2122 | ast2obj_expr); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2123 | if (!value) goto failed; |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 2124 | if (PyObject_SetAttrString(result, "decorator_list", value) == |
| 2125 | -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2126 | goto failed; |
| 2127 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2128 | break; |
| 2129 | case ClassDef_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2130 | result = PyType_GenericNew(ClassDef_type, NULL, NULL); |
| 2131 | if (!result) goto failed; |
| 2132 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 2133 | if (!value) goto failed; |
| 2134 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 2135 | goto failed; |
| 2136 | Py_DECREF(value); |
| 2137 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 2138 | if (!value) goto failed; |
| 2139 | if (PyObject_SetAttrString(result, "bases", value) == -1) |
| 2140 | goto failed; |
| 2141 | Py_DECREF(value); |
| 2142 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 2143 | if (!value) goto failed; |
| 2144 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2145 | goto failed; |
| 2146 | Py_DECREF(value); |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 2147 | value = ast2obj_list(o->v.ClassDef.decorator_list, |
| 2148 | ast2obj_expr); |
| 2149 | if (!value) goto failed; |
| 2150 | if (PyObject_SetAttrString(result, "decorator_list", value) == |
| 2151 | -1) |
| 2152 | goto failed; |
| 2153 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2154 | break; |
| 2155 | case Return_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2156 | result = PyType_GenericNew(Return_type, NULL, NULL); |
| 2157 | if (!result) goto failed; |
| 2158 | value = ast2obj_expr(o->v.Return.value); |
| 2159 | if (!value) goto failed; |
| 2160 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2161 | goto failed; |
| 2162 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2163 | break; |
| 2164 | case Delete_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2165 | result = PyType_GenericNew(Delete_type, NULL, NULL); |
| 2166 | if (!result) goto failed; |
| 2167 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 2168 | if (!value) goto failed; |
| 2169 | if (PyObject_SetAttrString(result, "targets", value) == -1) |
| 2170 | goto failed; |
| 2171 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2172 | break; |
| 2173 | case Assign_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2174 | result = PyType_GenericNew(Assign_type, NULL, NULL); |
| 2175 | if (!result) goto failed; |
| 2176 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 2177 | if (!value) goto failed; |
| 2178 | if (PyObject_SetAttrString(result, "targets", value) == -1) |
| 2179 | goto failed; |
| 2180 | Py_DECREF(value); |
| 2181 | value = ast2obj_expr(o->v.Assign.value); |
| 2182 | if (!value) goto failed; |
| 2183 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2184 | goto failed; |
| 2185 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2186 | break; |
| 2187 | case AugAssign_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2188 | result = PyType_GenericNew(AugAssign_type, NULL, NULL); |
| 2189 | if (!result) goto failed; |
| 2190 | value = ast2obj_expr(o->v.AugAssign.target); |
| 2191 | if (!value) goto failed; |
| 2192 | if (PyObject_SetAttrString(result, "target", value) == -1) |
| 2193 | goto failed; |
| 2194 | Py_DECREF(value); |
| 2195 | value = ast2obj_operator(o->v.AugAssign.op); |
| 2196 | if (!value) goto failed; |
| 2197 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2198 | goto failed; |
| 2199 | Py_DECREF(value); |
| 2200 | value = ast2obj_expr(o->v.AugAssign.value); |
| 2201 | if (!value) goto failed; |
| 2202 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2203 | goto failed; |
| 2204 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2205 | break; |
| 2206 | case Print_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2207 | result = PyType_GenericNew(Print_type, NULL, NULL); |
| 2208 | if (!result) goto failed; |
| 2209 | value = ast2obj_expr(o->v.Print.dest); |
| 2210 | if (!value) goto failed; |
| 2211 | if (PyObject_SetAttrString(result, "dest", value) == -1) |
| 2212 | goto failed; |
| 2213 | Py_DECREF(value); |
| 2214 | value = ast2obj_list(o->v.Print.values, ast2obj_expr); |
| 2215 | if (!value) goto failed; |
| 2216 | if (PyObject_SetAttrString(result, "values", value) == -1) |
| 2217 | goto failed; |
| 2218 | Py_DECREF(value); |
| 2219 | value = ast2obj_bool(o->v.Print.nl); |
| 2220 | if (!value) goto failed; |
| 2221 | if (PyObject_SetAttrString(result, "nl", value) == -1) |
| 2222 | goto failed; |
| 2223 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2224 | break; |
| 2225 | case For_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2226 | result = PyType_GenericNew(For_type, NULL, NULL); |
| 2227 | if (!result) goto failed; |
| 2228 | value = ast2obj_expr(o->v.For.target); |
| 2229 | if (!value) goto failed; |
| 2230 | if (PyObject_SetAttrString(result, "target", value) == -1) |
| 2231 | goto failed; |
| 2232 | Py_DECREF(value); |
| 2233 | value = ast2obj_expr(o->v.For.iter); |
| 2234 | if (!value) goto failed; |
| 2235 | if (PyObject_SetAttrString(result, "iter", value) == -1) |
| 2236 | goto failed; |
| 2237 | Py_DECREF(value); |
| 2238 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 2239 | if (!value) goto failed; |
| 2240 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2241 | goto failed; |
| 2242 | Py_DECREF(value); |
| 2243 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 2244 | if (!value) goto failed; |
| 2245 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2246 | goto failed; |
| 2247 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2248 | break; |
| 2249 | case While_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2250 | result = PyType_GenericNew(While_type, NULL, NULL); |
| 2251 | if (!result) goto failed; |
| 2252 | value = ast2obj_expr(o->v.While.test); |
| 2253 | if (!value) goto failed; |
| 2254 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2255 | goto failed; |
| 2256 | Py_DECREF(value); |
| 2257 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 2258 | if (!value) goto failed; |
| 2259 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2260 | goto failed; |
| 2261 | Py_DECREF(value); |
| 2262 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 2263 | if (!value) goto failed; |
| 2264 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2265 | goto failed; |
| 2266 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2267 | break; |
| 2268 | case If_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2269 | result = PyType_GenericNew(If_type, NULL, NULL); |
| 2270 | if (!result) goto failed; |
| 2271 | value = ast2obj_expr(o->v.If.test); |
| 2272 | if (!value) goto failed; |
| 2273 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2274 | goto failed; |
| 2275 | Py_DECREF(value); |
| 2276 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 2277 | if (!value) goto failed; |
| 2278 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2279 | goto failed; |
| 2280 | Py_DECREF(value); |
| 2281 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 2282 | if (!value) goto failed; |
| 2283 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2284 | goto failed; |
| 2285 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2286 | break; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2287 | case With_kind: |
| 2288 | result = PyType_GenericNew(With_type, NULL, NULL); |
| 2289 | if (!result) goto failed; |
| 2290 | value = ast2obj_expr(o->v.With.context_expr); |
| 2291 | if (!value) goto failed; |
| 2292 | if (PyObject_SetAttrString(result, "context_expr", value) == -1) |
| 2293 | goto failed; |
| 2294 | Py_DECREF(value); |
| 2295 | value = ast2obj_expr(o->v.With.optional_vars); |
| 2296 | if (!value) goto failed; |
| 2297 | if (PyObject_SetAttrString(result, "optional_vars", value) == |
| 2298 | -1) |
| 2299 | goto failed; |
| 2300 | Py_DECREF(value); |
| 2301 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 2302 | if (!value) goto failed; |
| 2303 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2304 | goto failed; |
| 2305 | Py_DECREF(value); |
| 2306 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2307 | case Raise_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2308 | result = PyType_GenericNew(Raise_type, NULL, NULL); |
| 2309 | if (!result) goto failed; |
| 2310 | value = ast2obj_expr(o->v.Raise.type); |
| 2311 | if (!value) goto failed; |
| 2312 | if (PyObject_SetAttrString(result, "type", value) == -1) |
| 2313 | goto failed; |
| 2314 | Py_DECREF(value); |
| 2315 | value = ast2obj_expr(o->v.Raise.inst); |
| 2316 | if (!value) goto failed; |
| 2317 | if (PyObject_SetAttrString(result, "inst", value) == -1) |
| 2318 | goto failed; |
| 2319 | Py_DECREF(value); |
| 2320 | value = ast2obj_expr(o->v.Raise.tback); |
| 2321 | if (!value) goto failed; |
| 2322 | if (PyObject_SetAttrString(result, "tback", value) == -1) |
| 2323 | goto failed; |
| 2324 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2325 | break; |
| 2326 | case TryExcept_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2327 | result = PyType_GenericNew(TryExcept_type, NULL, NULL); |
| 2328 | if (!result) goto failed; |
| 2329 | value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt); |
| 2330 | if (!value) goto failed; |
| 2331 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2332 | goto failed; |
| 2333 | Py_DECREF(value); |
| 2334 | value = ast2obj_list(o->v.TryExcept.handlers, |
| 2335 | ast2obj_excepthandler); |
| 2336 | if (!value) goto failed; |
| 2337 | if (PyObject_SetAttrString(result, "handlers", value) == -1) |
| 2338 | goto failed; |
| 2339 | Py_DECREF(value); |
| 2340 | value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt); |
| 2341 | if (!value) goto failed; |
| 2342 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2343 | goto failed; |
| 2344 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2345 | break; |
| 2346 | case TryFinally_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2347 | result = PyType_GenericNew(TryFinally_type, NULL, NULL); |
| 2348 | if (!result) goto failed; |
| 2349 | value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt); |
| 2350 | if (!value) goto failed; |
| 2351 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2352 | goto failed; |
| 2353 | Py_DECREF(value); |
| 2354 | value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt); |
| 2355 | if (!value) goto failed; |
| 2356 | if (PyObject_SetAttrString(result, "finalbody", value) == -1) |
| 2357 | goto failed; |
| 2358 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2359 | break; |
| 2360 | case Assert_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2361 | result = PyType_GenericNew(Assert_type, NULL, NULL); |
| 2362 | if (!result) goto failed; |
| 2363 | value = ast2obj_expr(o->v.Assert.test); |
| 2364 | if (!value) goto failed; |
| 2365 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2366 | goto failed; |
| 2367 | Py_DECREF(value); |
| 2368 | value = ast2obj_expr(o->v.Assert.msg); |
| 2369 | if (!value) goto failed; |
| 2370 | if (PyObject_SetAttrString(result, "msg", value) == -1) |
| 2371 | goto failed; |
| 2372 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2373 | break; |
| 2374 | case Import_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2375 | result = PyType_GenericNew(Import_type, NULL, NULL); |
| 2376 | if (!result) goto failed; |
| 2377 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 2378 | if (!value) goto failed; |
| 2379 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2380 | goto failed; |
| 2381 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2382 | break; |
| 2383 | case ImportFrom_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2384 | result = PyType_GenericNew(ImportFrom_type, NULL, NULL); |
| 2385 | if (!result) goto failed; |
| 2386 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 2387 | if (!value) goto failed; |
| 2388 | if (PyObject_SetAttrString(result, "module", value) == -1) |
| 2389 | goto failed; |
| 2390 | Py_DECREF(value); |
| 2391 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 2392 | if (!value) goto failed; |
| 2393 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2394 | goto failed; |
| 2395 | Py_DECREF(value); |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 2396 | value = ast2obj_int(o->v.ImportFrom.level); |
| 2397 | if (!value) goto failed; |
| 2398 | if (PyObject_SetAttrString(result, "level", value) == -1) |
| 2399 | goto failed; |
| 2400 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2401 | break; |
| 2402 | case Exec_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2403 | result = PyType_GenericNew(Exec_type, NULL, NULL); |
| 2404 | if (!result) goto failed; |
| 2405 | value = ast2obj_expr(o->v.Exec.body); |
| 2406 | if (!value) goto failed; |
| 2407 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2408 | goto failed; |
| 2409 | Py_DECREF(value); |
| 2410 | value = ast2obj_expr(o->v.Exec.globals); |
| 2411 | if (!value) goto failed; |
| 2412 | if (PyObject_SetAttrString(result, "globals", value) == -1) |
| 2413 | goto failed; |
| 2414 | Py_DECREF(value); |
| 2415 | value = ast2obj_expr(o->v.Exec.locals); |
| 2416 | if (!value) goto failed; |
| 2417 | if (PyObject_SetAttrString(result, "locals", value) == -1) |
| 2418 | goto failed; |
| 2419 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2420 | break; |
| 2421 | case Global_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2422 | result = PyType_GenericNew(Global_type, NULL, NULL); |
| 2423 | if (!result) goto failed; |
| 2424 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 2425 | if (!value) goto failed; |
| 2426 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2427 | goto failed; |
| 2428 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2429 | break; |
| 2430 | case Expr_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2431 | result = PyType_GenericNew(Expr_type, NULL, NULL); |
| 2432 | if (!result) goto failed; |
| 2433 | value = ast2obj_expr(o->v.Expr.value); |
| 2434 | if (!value) goto failed; |
| 2435 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2436 | goto failed; |
| 2437 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2438 | break; |
| 2439 | case Pass_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2440 | result = PyType_GenericNew(Pass_type, NULL, NULL); |
| 2441 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2442 | break; |
| 2443 | case Break_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2444 | result = PyType_GenericNew(Break_type, NULL, NULL); |
| 2445 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2446 | break; |
| 2447 | case Continue_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2448 | result = PyType_GenericNew(Continue_type, NULL, NULL); |
| 2449 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2450 | break; |
| 2451 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2452 | value = ast2obj_int(o->lineno); |
| 2453 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2454 | if (PyObject_SetAttrString(result, "lineno", value) < 0) |
| 2455 | goto failed; |
| 2456 | Py_DECREF(value); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2457 | value = ast2obj_int(o->col_offset); |
| 2458 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2459 | if (PyObject_SetAttrString(result, "col_offset", value) < 0) |
| 2460 | goto failed; |
| 2461 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2462 | return result; |
| 2463 | failed: |
| 2464 | Py_XDECREF(value); |
| 2465 | Py_XDECREF(result); |
| 2466 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2467 | } |
| 2468 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2469 | PyObject* |
| 2470 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2471 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2472 | expr_ty o = (expr_ty)_o; |
| 2473 | PyObject *result = NULL, *value = NULL; |
| 2474 | if (!o) { |
| 2475 | Py_INCREF(Py_None); |
| 2476 | return Py_None; |
| 2477 | } |
| 2478 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2479 | switch (o->kind) { |
| 2480 | case BoolOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2481 | result = PyType_GenericNew(BoolOp_type, NULL, NULL); |
| 2482 | if (!result) goto failed; |
| 2483 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 2484 | if (!value) goto failed; |
| 2485 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2486 | goto failed; |
| 2487 | Py_DECREF(value); |
| 2488 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 2489 | if (!value) goto failed; |
| 2490 | if (PyObject_SetAttrString(result, "values", value) == -1) |
| 2491 | goto failed; |
| 2492 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2493 | break; |
| 2494 | case BinOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2495 | result = PyType_GenericNew(BinOp_type, NULL, NULL); |
| 2496 | if (!result) goto failed; |
| 2497 | value = ast2obj_expr(o->v.BinOp.left); |
| 2498 | if (!value) goto failed; |
| 2499 | if (PyObject_SetAttrString(result, "left", value) == -1) |
| 2500 | goto failed; |
| 2501 | Py_DECREF(value); |
| 2502 | value = ast2obj_operator(o->v.BinOp.op); |
| 2503 | if (!value) goto failed; |
| 2504 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2505 | goto failed; |
| 2506 | Py_DECREF(value); |
| 2507 | value = ast2obj_expr(o->v.BinOp.right); |
| 2508 | if (!value) goto failed; |
| 2509 | if (PyObject_SetAttrString(result, "right", value) == -1) |
| 2510 | goto failed; |
| 2511 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2512 | break; |
| 2513 | case UnaryOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2514 | result = PyType_GenericNew(UnaryOp_type, NULL, NULL); |
| 2515 | if (!result) goto failed; |
| 2516 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 2517 | if (!value) goto failed; |
| 2518 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2519 | goto failed; |
| 2520 | Py_DECREF(value); |
| 2521 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 2522 | if (!value) goto failed; |
| 2523 | if (PyObject_SetAttrString(result, "operand", value) == -1) |
| 2524 | goto failed; |
| 2525 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2526 | break; |
| 2527 | case Lambda_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2528 | result = PyType_GenericNew(Lambda_type, NULL, NULL); |
| 2529 | if (!result) goto failed; |
| 2530 | value = ast2obj_arguments(o->v.Lambda.args); |
| 2531 | if (!value) goto failed; |
| 2532 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 2533 | goto failed; |
| 2534 | Py_DECREF(value); |
| 2535 | value = ast2obj_expr(o->v.Lambda.body); |
| 2536 | if (!value) goto failed; |
| 2537 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2538 | goto failed; |
| 2539 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2540 | break; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2541 | case IfExp_kind: |
| 2542 | result = PyType_GenericNew(IfExp_type, NULL, NULL); |
| 2543 | if (!result) goto failed; |
| 2544 | value = ast2obj_expr(o->v.IfExp.test); |
| 2545 | if (!value) goto failed; |
| 2546 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2547 | goto failed; |
| 2548 | Py_DECREF(value); |
| 2549 | value = ast2obj_expr(o->v.IfExp.body); |
| 2550 | if (!value) goto failed; |
| 2551 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2552 | goto failed; |
| 2553 | Py_DECREF(value); |
| 2554 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 2555 | if (!value) goto failed; |
| 2556 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2557 | goto failed; |
| 2558 | Py_DECREF(value); |
| 2559 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2560 | case Dict_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2561 | result = PyType_GenericNew(Dict_type, NULL, NULL); |
| 2562 | if (!result) goto failed; |
| 2563 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 2564 | if (!value) goto failed; |
| 2565 | if (PyObject_SetAttrString(result, "keys", value) == -1) |
| 2566 | goto failed; |
| 2567 | Py_DECREF(value); |
| 2568 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 2569 | if (!value) goto failed; |
| 2570 | if (PyObject_SetAttrString(result, "values", value) == -1) |
| 2571 | goto failed; |
| 2572 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2573 | break; |
| 2574 | case ListComp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2575 | result = PyType_GenericNew(ListComp_type, NULL, NULL); |
| 2576 | if (!result) goto failed; |
| 2577 | value = ast2obj_expr(o->v.ListComp.elt); |
| 2578 | if (!value) goto failed; |
| 2579 | if (PyObject_SetAttrString(result, "elt", value) == -1) |
| 2580 | goto failed; |
| 2581 | Py_DECREF(value); |
| 2582 | value = ast2obj_list(o->v.ListComp.generators, |
| 2583 | ast2obj_comprehension); |
| 2584 | if (!value) goto failed; |
| 2585 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2586 | goto failed; |
| 2587 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2588 | break; |
| 2589 | case GeneratorExp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2590 | result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); |
| 2591 | if (!result) goto failed; |
| 2592 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 2593 | if (!value) goto failed; |
| 2594 | if (PyObject_SetAttrString(result, "elt", value) == -1) |
| 2595 | goto failed; |
| 2596 | Py_DECREF(value); |
| 2597 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 2598 | ast2obj_comprehension); |
| 2599 | if (!value) goto failed; |
| 2600 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2601 | goto failed; |
| 2602 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2603 | break; |
| 2604 | case Yield_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2605 | result = PyType_GenericNew(Yield_type, NULL, NULL); |
| 2606 | if (!result) goto failed; |
| 2607 | value = ast2obj_expr(o->v.Yield.value); |
| 2608 | if (!value) goto failed; |
| 2609 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2610 | goto failed; |
| 2611 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2612 | break; |
| 2613 | case Compare_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2614 | result = PyType_GenericNew(Compare_type, NULL, NULL); |
| 2615 | if (!result) goto failed; |
| 2616 | value = ast2obj_expr(o->v.Compare.left); |
| 2617 | if (!value) goto failed; |
| 2618 | if (PyObject_SetAttrString(result, "left", value) == -1) |
| 2619 | goto failed; |
| 2620 | Py_DECREF(value); |
Martin v. Löwis | ce1d5d2 | 2006-02-26 20:51:25 +0000 | [diff] [blame] | 2621 | { |
| 2622 | int i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 2623 | value = PyList_New(n); |
| 2624 | if (!value) goto failed; |
| 2625 | for(i = 0; i < n; i++) |
Martin v. Löwis | 0cc56e5 | 2006-04-13 12:29:43 +0000 | [diff] [blame] | 2626 | PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i))); |
Martin v. Löwis | ce1d5d2 | 2006-02-26 20:51:25 +0000 | [diff] [blame] | 2627 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2628 | if (!value) goto failed; |
| 2629 | if (PyObject_SetAttrString(result, "ops", value) == -1) |
| 2630 | goto failed; |
| 2631 | Py_DECREF(value); |
| 2632 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
| 2633 | if (!value) goto failed; |
| 2634 | if (PyObject_SetAttrString(result, "comparators", value) == -1) |
| 2635 | goto failed; |
| 2636 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2637 | break; |
| 2638 | case Call_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2639 | result = PyType_GenericNew(Call_type, NULL, NULL); |
| 2640 | if (!result) goto failed; |
| 2641 | value = ast2obj_expr(o->v.Call.func); |
| 2642 | if (!value) goto failed; |
| 2643 | if (PyObject_SetAttrString(result, "func", value) == -1) |
| 2644 | goto failed; |
| 2645 | Py_DECREF(value); |
| 2646 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 2647 | if (!value) goto failed; |
| 2648 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 2649 | goto failed; |
| 2650 | Py_DECREF(value); |
| 2651 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 2652 | if (!value) goto failed; |
| 2653 | if (PyObject_SetAttrString(result, "keywords", value) == -1) |
| 2654 | goto failed; |
| 2655 | Py_DECREF(value); |
| 2656 | value = ast2obj_expr(o->v.Call.starargs); |
| 2657 | if (!value) goto failed; |
| 2658 | if (PyObject_SetAttrString(result, "starargs", value) == -1) |
| 2659 | goto failed; |
| 2660 | Py_DECREF(value); |
| 2661 | value = ast2obj_expr(o->v.Call.kwargs); |
| 2662 | if (!value) goto failed; |
| 2663 | if (PyObject_SetAttrString(result, "kwargs", value) == -1) |
| 2664 | goto failed; |
| 2665 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2666 | break; |
| 2667 | case Repr_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2668 | result = PyType_GenericNew(Repr_type, NULL, NULL); |
| 2669 | if (!result) goto failed; |
| 2670 | value = ast2obj_expr(o->v.Repr.value); |
| 2671 | if (!value) goto failed; |
| 2672 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2673 | goto failed; |
| 2674 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2675 | break; |
| 2676 | case Num_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2677 | result = PyType_GenericNew(Num_type, NULL, NULL); |
| 2678 | if (!result) goto failed; |
| 2679 | value = ast2obj_object(o->v.Num.n); |
| 2680 | if (!value) goto failed; |
| 2681 | if (PyObject_SetAttrString(result, "n", value) == -1) |
| 2682 | goto failed; |
| 2683 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2684 | break; |
| 2685 | case Str_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2686 | result = PyType_GenericNew(Str_type, NULL, NULL); |
| 2687 | if (!result) goto failed; |
| 2688 | value = ast2obj_string(o->v.Str.s); |
| 2689 | if (!value) goto failed; |
| 2690 | if (PyObject_SetAttrString(result, "s", value) == -1) |
| 2691 | goto failed; |
| 2692 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2693 | break; |
| 2694 | case Attribute_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2695 | result = PyType_GenericNew(Attribute_type, NULL, NULL); |
| 2696 | if (!result) goto failed; |
| 2697 | value = ast2obj_expr(o->v.Attribute.value); |
| 2698 | if (!value) goto failed; |
| 2699 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2700 | goto failed; |
| 2701 | Py_DECREF(value); |
| 2702 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 2703 | if (!value) goto failed; |
| 2704 | if (PyObject_SetAttrString(result, "attr", value) == -1) |
| 2705 | goto failed; |
| 2706 | Py_DECREF(value); |
| 2707 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 2708 | if (!value) goto failed; |
| 2709 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2710 | goto failed; |
| 2711 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2712 | break; |
| 2713 | case Subscript_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2714 | result = PyType_GenericNew(Subscript_type, NULL, NULL); |
| 2715 | if (!result) goto failed; |
| 2716 | value = ast2obj_expr(o->v.Subscript.value); |
| 2717 | if (!value) goto failed; |
| 2718 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2719 | goto failed; |
| 2720 | Py_DECREF(value); |
| 2721 | value = ast2obj_slice(o->v.Subscript.slice); |
| 2722 | if (!value) goto failed; |
| 2723 | if (PyObject_SetAttrString(result, "slice", value) == -1) |
| 2724 | goto failed; |
| 2725 | Py_DECREF(value); |
| 2726 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 2727 | if (!value) goto failed; |
| 2728 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2729 | goto failed; |
| 2730 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2731 | break; |
| 2732 | case Name_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2733 | result = PyType_GenericNew(Name_type, NULL, NULL); |
| 2734 | if (!result) goto failed; |
| 2735 | value = ast2obj_identifier(o->v.Name.id); |
| 2736 | if (!value) goto failed; |
| 2737 | if (PyObject_SetAttrString(result, "id", value) == -1) |
| 2738 | goto failed; |
| 2739 | Py_DECREF(value); |
| 2740 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 2741 | if (!value) goto failed; |
| 2742 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2743 | goto failed; |
| 2744 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2745 | break; |
| 2746 | case List_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2747 | result = PyType_GenericNew(List_type, NULL, NULL); |
| 2748 | if (!result) goto failed; |
| 2749 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 2750 | if (!value) goto failed; |
| 2751 | if (PyObject_SetAttrString(result, "elts", value) == -1) |
| 2752 | goto failed; |
| 2753 | Py_DECREF(value); |
| 2754 | value = ast2obj_expr_context(o->v.List.ctx); |
| 2755 | if (!value) goto failed; |
| 2756 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2757 | goto failed; |
| 2758 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2759 | break; |
| 2760 | case Tuple_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2761 | result = PyType_GenericNew(Tuple_type, NULL, NULL); |
| 2762 | if (!result) goto failed; |
| 2763 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 2764 | if (!value) goto failed; |
| 2765 | if (PyObject_SetAttrString(result, "elts", value) == -1) |
| 2766 | goto failed; |
| 2767 | Py_DECREF(value); |
| 2768 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 2769 | if (!value) goto failed; |
| 2770 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2771 | goto failed; |
| 2772 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2773 | break; |
| 2774 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2775 | value = ast2obj_int(o->lineno); |
| 2776 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2777 | if (PyObject_SetAttrString(result, "lineno", value) < 0) |
| 2778 | goto failed; |
| 2779 | Py_DECREF(value); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2780 | value = ast2obj_int(o->col_offset); |
| 2781 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2782 | if (PyObject_SetAttrString(result, "col_offset", value) < 0) |
| 2783 | goto failed; |
| 2784 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2785 | return result; |
| 2786 | failed: |
| 2787 | Py_XDECREF(value); |
| 2788 | Py_XDECREF(result); |
| 2789 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2790 | } |
| 2791 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2792 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2793 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2794 | switch(o) { |
| 2795 | case Load: |
| 2796 | Py_INCREF(Load_singleton); |
| 2797 | return Load_singleton; |
| 2798 | case Store: |
| 2799 | Py_INCREF(Store_singleton); |
| 2800 | return Store_singleton; |
| 2801 | case Del: |
| 2802 | Py_INCREF(Del_singleton); |
| 2803 | return Del_singleton; |
| 2804 | case AugLoad: |
| 2805 | Py_INCREF(AugLoad_singleton); |
| 2806 | return AugLoad_singleton; |
| 2807 | case AugStore: |
| 2808 | Py_INCREF(AugStore_singleton); |
| 2809 | return AugStore_singleton; |
| 2810 | case Param: |
| 2811 | Py_INCREF(Param_singleton); |
| 2812 | return Param_singleton; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 2813 | default: |
| 2814 | /* should never happen, but just in case ... */ |
| 2815 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 2816 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2817 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2818 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2819 | PyObject* |
| 2820 | ast2obj_slice(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2821 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2822 | slice_ty o = (slice_ty)_o; |
| 2823 | PyObject *result = NULL, *value = NULL; |
| 2824 | if (!o) { |
| 2825 | Py_INCREF(Py_None); |
| 2826 | return Py_None; |
| 2827 | } |
| 2828 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2829 | switch (o->kind) { |
| 2830 | case Ellipsis_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2831 | result = PyType_GenericNew(Ellipsis_type, NULL, NULL); |
| 2832 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2833 | break; |
| 2834 | case Slice_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2835 | result = PyType_GenericNew(Slice_type, NULL, NULL); |
| 2836 | if (!result) goto failed; |
| 2837 | value = ast2obj_expr(o->v.Slice.lower); |
| 2838 | if (!value) goto failed; |
| 2839 | if (PyObject_SetAttrString(result, "lower", value) == -1) |
| 2840 | goto failed; |
| 2841 | Py_DECREF(value); |
| 2842 | value = ast2obj_expr(o->v.Slice.upper); |
| 2843 | if (!value) goto failed; |
| 2844 | if (PyObject_SetAttrString(result, "upper", value) == -1) |
| 2845 | goto failed; |
| 2846 | Py_DECREF(value); |
| 2847 | value = ast2obj_expr(o->v.Slice.step); |
| 2848 | if (!value) goto failed; |
| 2849 | if (PyObject_SetAttrString(result, "step", value) == -1) |
| 2850 | goto failed; |
| 2851 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2852 | break; |
| 2853 | case ExtSlice_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2854 | result = PyType_GenericNew(ExtSlice_type, NULL, NULL); |
| 2855 | if (!result) goto failed; |
| 2856 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 2857 | if (!value) goto failed; |
| 2858 | if (PyObject_SetAttrString(result, "dims", value) == -1) |
| 2859 | goto failed; |
| 2860 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2861 | break; |
| 2862 | case Index_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2863 | result = PyType_GenericNew(Index_type, NULL, NULL); |
| 2864 | if (!result) goto failed; |
| 2865 | value = ast2obj_expr(o->v.Index.value); |
| 2866 | if (!value) goto failed; |
| 2867 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2868 | goto failed; |
| 2869 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2870 | break; |
| 2871 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2872 | return result; |
| 2873 | failed: |
| 2874 | Py_XDECREF(value); |
| 2875 | Py_XDECREF(result); |
| 2876 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2877 | } |
| 2878 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2879 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2880 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2881 | switch(o) { |
| 2882 | case And: |
| 2883 | Py_INCREF(And_singleton); |
| 2884 | return And_singleton; |
| 2885 | case Or: |
| 2886 | Py_INCREF(Or_singleton); |
| 2887 | return Or_singleton; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 2888 | default: |
| 2889 | /* should never happen, but just in case ... */ |
| 2890 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 2891 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2892 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2893 | } |
| 2894 | PyObject* ast2obj_operator(operator_ty o) |
| 2895 | { |
| 2896 | switch(o) { |
| 2897 | case Add: |
| 2898 | Py_INCREF(Add_singleton); |
| 2899 | return Add_singleton; |
| 2900 | case Sub: |
| 2901 | Py_INCREF(Sub_singleton); |
| 2902 | return Sub_singleton; |
| 2903 | case Mult: |
| 2904 | Py_INCREF(Mult_singleton); |
| 2905 | return Mult_singleton; |
| 2906 | case Div: |
| 2907 | Py_INCREF(Div_singleton); |
| 2908 | return Div_singleton; |
| 2909 | case Mod: |
| 2910 | Py_INCREF(Mod_singleton); |
| 2911 | return Mod_singleton; |
| 2912 | case Pow: |
| 2913 | Py_INCREF(Pow_singleton); |
| 2914 | return Pow_singleton; |
| 2915 | case LShift: |
| 2916 | Py_INCREF(LShift_singleton); |
| 2917 | return LShift_singleton; |
| 2918 | case RShift: |
| 2919 | Py_INCREF(RShift_singleton); |
| 2920 | return RShift_singleton; |
| 2921 | case BitOr: |
| 2922 | Py_INCREF(BitOr_singleton); |
| 2923 | return BitOr_singleton; |
| 2924 | case BitXor: |
| 2925 | Py_INCREF(BitXor_singleton); |
| 2926 | return BitXor_singleton; |
| 2927 | case BitAnd: |
| 2928 | Py_INCREF(BitAnd_singleton); |
| 2929 | return BitAnd_singleton; |
| 2930 | case FloorDiv: |
| 2931 | Py_INCREF(FloorDiv_singleton); |
| 2932 | return FloorDiv_singleton; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 2933 | default: |
| 2934 | /* should never happen, but just in case ... */ |
| 2935 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 2936 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2937 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2938 | } |
| 2939 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 2940 | { |
| 2941 | switch(o) { |
| 2942 | case Invert: |
| 2943 | Py_INCREF(Invert_singleton); |
| 2944 | return Invert_singleton; |
| 2945 | case Not: |
| 2946 | Py_INCREF(Not_singleton); |
| 2947 | return Not_singleton; |
| 2948 | case UAdd: |
| 2949 | Py_INCREF(UAdd_singleton); |
| 2950 | return UAdd_singleton; |
| 2951 | case USub: |
| 2952 | Py_INCREF(USub_singleton); |
| 2953 | return USub_singleton; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 2954 | default: |
| 2955 | /* should never happen, but just in case ... */ |
| 2956 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 2957 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2958 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2959 | } |
| 2960 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 2961 | { |
| 2962 | switch(o) { |
| 2963 | case Eq: |
| 2964 | Py_INCREF(Eq_singleton); |
| 2965 | return Eq_singleton; |
| 2966 | case NotEq: |
| 2967 | Py_INCREF(NotEq_singleton); |
| 2968 | return NotEq_singleton; |
| 2969 | case Lt: |
| 2970 | Py_INCREF(Lt_singleton); |
| 2971 | return Lt_singleton; |
| 2972 | case LtE: |
| 2973 | Py_INCREF(LtE_singleton); |
| 2974 | return LtE_singleton; |
| 2975 | case Gt: |
| 2976 | Py_INCREF(Gt_singleton); |
| 2977 | return Gt_singleton; |
| 2978 | case GtE: |
| 2979 | Py_INCREF(GtE_singleton); |
| 2980 | return GtE_singleton; |
| 2981 | case Is: |
| 2982 | Py_INCREF(Is_singleton); |
| 2983 | return Is_singleton; |
| 2984 | case IsNot: |
| 2985 | Py_INCREF(IsNot_singleton); |
| 2986 | return IsNot_singleton; |
| 2987 | case In: |
| 2988 | Py_INCREF(In_singleton); |
| 2989 | return In_singleton; |
| 2990 | case NotIn: |
| 2991 | Py_INCREF(NotIn_singleton); |
| 2992 | return NotIn_singleton; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 2993 | default: |
| 2994 | /* should never happen, but just in case ... */ |
| 2995 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 2996 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2997 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2998 | } |
| 2999 | PyObject* |
| 3000 | ast2obj_comprehension(void* _o) |
| 3001 | { |
| 3002 | comprehension_ty o = (comprehension_ty)_o; |
| 3003 | PyObject *result = NULL, *value = NULL; |
| 3004 | if (!o) { |
| 3005 | Py_INCREF(Py_None); |
| 3006 | return Py_None; |
| 3007 | } |
| 3008 | |
| 3009 | result = PyType_GenericNew(comprehension_type, NULL, NULL); |
| 3010 | if (!result) return NULL; |
| 3011 | value = ast2obj_expr(o->target); |
| 3012 | if (!value) goto failed; |
| 3013 | if (PyObject_SetAttrString(result, "target", value) == -1) |
| 3014 | goto failed; |
| 3015 | Py_DECREF(value); |
| 3016 | value = ast2obj_expr(o->iter); |
| 3017 | if (!value) goto failed; |
| 3018 | if (PyObject_SetAttrString(result, "iter", value) == -1) |
| 3019 | goto failed; |
| 3020 | Py_DECREF(value); |
| 3021 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 3022 | if (!value) goto failed; |
| 3023 | if (PyObject_SetAttrString(result, "ifs", value) == -1) |
| 3024 | goto failed; |
| 3025 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3026 | return result; |
| 3027 | failed: |
| 3028 | Py_XDECREF(value); |
| 3029 | Py_XDECREF(result); |
| 3030 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3031 | } |
| 3032 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3033 | PyObject* |
| 3034 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3035 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3036 | excepthandler_ty o = (excepthandler_ty)_o; |
| 3037 | PyObject *result = NULL, *value = NULL; |
| 3038 | if (!o) { |
| 3039 | Py_INCREF(Py_None); |
| 3040 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3041 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3042 | |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame] | 3043 | switch (o->kind) { |
| 3044 | case ExceptHandler_kind: |
| 3045 | result = PyType_GenericNew(ExceptHandler_type, NULL, NULL); |
| 3046 | if (!result) goto failed; |
| 3047 | value = ast2obj_expr(o->v.ExceptHandler.type); |
| 3048 | if (!value) goto failed; |
| 3049 | if (PyObject_SetAttrString(result, "type", value) == -1) |
| 3050 | goto failed; |
| 3051 | Py_DECREF(value); |
| 3052 | value = ast2obj_expr(o->v.ExceptHandler.name); |
| 3053 | if (!value) goto failed; |
| 3054 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 3055 | goto failed; |
| 3056 | Py_DECREF(value); |
| 3057 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 3058 | if (!value) goto failed; |
| 3059 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 3060 | goto failed; |
| 3061 | Py_DECREF(value); |
| 3062 | break; |
| 3063 | } |
Jeremy Hylton | 2f327c1 | 2006-04-04 04:00:23 +0000 | [diff] [blame] | 3064 | value = ast2obj_int(o->lineno); |
| 3065 | if (!value) goto failed; |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame] | 3066 | if (PyObject_SetAttrString(result, "lineno", value) < 0) |
Jeremy Hylton | 2f327c1 | 2006-04-04 04:00:23 +0000 | [diff] [blame] | 3067 | goto failed; |
| 3068 | Py_DECREF(value); |
| 3069 | value = ast2obj_int(o->col_offset); |
| 3070 | if (!value) goto failed; |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame] | 3071 | if (PyObject_SetAttrString(result, "col_offset", value) < 0) |
Jeremy Hylton | 2f327c1 | 2006-04-04 04:00:23 +0000 | [diff] [blame] | 3072 | goto failed; |
| 3073 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3074 | return result; |
| 3075 | failed: |
| 3076 | Py_XDECREF(value); |
| 3077 | Py_XDECREF(result); |
| 3078 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3079 | } |
| 3080 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3081 | PyObject* |
| 3082 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3083 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3084 | arguments_ty o = (arguments_ty)_o; |
| 3085 | PyObject *result = NULL, *value = NULL; |
| 3086 | if (!o) { |
| 3087 | Py_INCREF(Py_None); |
| 3088 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3089 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3090 | |
| 3091 | result = PyType_GenericNew(arguments_type, NULL, NULL); |
| 3092 | if (!result) return NULL; |
| 3093 | value = ast2obj_list(o->args, ast2obj_expr); |
| 3094 | if (!value) goto failed; |
| 3095 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 3096 | goto failed; |
| 3097 | Py_DECREF(value); |
| 3098 | value = ast2obj_identifier(o->vararg); |
| 3099 | if (!value) goto failed; |
| 3100 | if (PyObject_SetAttrString(result, "vararg", value) == -1) |
| 3101 | goto failed; |
| 3102 | Py_DECREF(value); |
| 3103 | value = ast2obj_identifier(o->kwarg); |
| 3104 | if (!value) goto failed; |
| 3105 | if (PyObject_SetAttrString(result, "kwarg", value) == -1) |
| 3106 | goto failed; |
| 3107 | Py_DECREF(value); |
| 3108 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 3109 | if (!value) goto failed; |
| 3110 | if (PyObject_SetAttrString(result, "defaults", value) == -1) |
| 3111 | goto failed; |
| 3112 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3113 | return result; |
| 3114 | failed: |
| 3115 | Py_XDECREF(value); |
| 3116 | Py_XDECREF(result); |
| 3117 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3118 | } |
| 3119 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3120 | PyObject* |
| 3121 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3122 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3123 | keyword_ty o = (keyword_ty)_o; |
| 3124 | PyObject *result = NULL, *value = NULL; |
| 3125 | if (!o) { |
| 3126 | Py_INCREF(Py_None); |
| 3127 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3128 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3129 | |
| 3130 | result = PyType_GenericNew(keyword_type, NULL, NULL); |
| 3131 | if (!result) return NULL; |
| 3132 | value = ast2obj_identifier(o->arg); |
| 3133 | if (!value) goto failed; |
| 3134 | if (PyObject_SetAttrString(result, "arg", value) == -1) |
| 3135 | goto failed; |
| 3136 | Py_DECREF(value); |
| 3137 | value = ast2obj_expr(o->value); |
| 3138 | if (!value) goto failed; |
| 3139 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 3140 | goto failed; |
| 3141 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3142 | return result; |
| 3143 | failed: |
| 3144 | Py_XDECREF(value); |
| 3145 | Py_XDECREF(result); |
| 3146 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3147 | } |
| 3148 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3149 | PyObject* |
| 3150 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3151 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3152 | alias_ty o = (alias_ty)_o; |
| 3153 | PyObject *result = NULL, *value = NULL; |
| 3154 | if (!o) { |
| 3155 | Py_INCREF(Py_None); |
| 3156 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3157 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3158 | |
| 3159 | result = PyType_GenericNew(alias_type, NULL, NULL); |
| 3160 | if (!result) return NULL; |
| 3161 | value = ast2obj_identifier(o->name); |
| 3162 | if (!value) goto failed; |
| 3163 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 3164 | goto failed; |
| 3165 | Py_DECREF(value); |
| 3166 | value = ast2obj_identifier(o->asname); |
| 3167 | if (!value) goto failed; |
| 3168 | if (PyObject_SetAttrString(result, "asname", 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 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3178 | |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3179 | int |
| 3180 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 3181 | { |
| 3182 | PyObject* tmp = NULL; |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 3183 | int isinstance; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3184 | |
| 3185 | |
| 3186 | if (obj == Py_None) { |
| 3187 | *out = NULL; |
| 3188 | return 0; |
| 3189 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 3190 | isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type); |
| 3191 | if (isinstance == -1) { |
| 3192 | return 1; |
| 3193 | } |
| 3194 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3195 | asdl_seq* body; |
| 3196 | |
| 3197 | if (PyObject_HasAttrString(obj, "body")) { |
| 3198 | int res; |
| 3199 | Py_ssize_t len; |
| 3200 | Py_ssize_t i; |
| 3201 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3202 | if (tmp == NULL) goto failed; |
| 3203 | if (!PyList_Check(tmp)) { |
| 3204 | PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3205 | goto failed; |
| 3206 | } |
| 3207 | len = PyList_GET_SIZE(tmp); |
| 3208 | body = asdl_seq_new(len, arena); |
| 3209 | if (body == NULL) goto failed; |
| 3210 | for (i = 0; i < len; i++) { |
| 3211 | stmt_ty value; |
| 3212 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3213 | if (res != 0) goto failed; |
| 3214 | asdl_seq_SET(body, i, value); |
| 3215 | } |
| 3216 | Py_XDECREF(tmp); |
| 3217 | tmp = NULL; |
| 3218 | } else { |
| 3219 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 3220 | return 1; |
| 3221 | } |
| 3222 | *out = Module(body, arena); |
| 3223 | if (*out == NULL) goto failed; |
| 3224 | return 0; |
| 3225 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 3226 | isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type); |
| 3227 | if (isinstance == -1) { |
| 3228 | return 1; |
| 3229 | } |
| 3230 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3231 | asdl_seq* body; |
| 3232 | |
| 3233 | if (PyObject_HasAttrString(obj, "body")) { |
| 3234 | int res; |
| 3235 | Py_ssize_t len; |
| 3236 | Py_ssize_t i; |
| 3237 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3238 | if (tmp == NULL) goto failed; |
| 3239 | if (!PyList_Check(tmp)) { |
| 3240 | PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3241 | goto failed; |
| 3242 | } |
| 3243 | len = PyList_GET_SIZE(tmp); |
| 3244 | body = asdl_seq_new(len, arena); |
| 3245 | if (body == NULL) goto failed; |
| 3246 | for (i = 0; i < len; i++) { |
| 3247 | stmt_ty value; |
| 3248 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3249 | if (res != 0) goto failed; |
| 3250 | asdl_seq_SET(body, i, value); |
| 3251 | } |
| 3252 | Py_XDECREF(tmp); |
| 3253 | tmp = NULL; |
| 3254 | } else { |
| 3255 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 3256 | return 1; |
| 3257 | } |
| 3258 | *out = Interactive(body, arena); |
| 3259 | if (*out == NULL) goto failed; |
| 3260 | return 0; |
| 3261 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 3262 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type); |
| 3263 | if (isinstance == -1) { |
| 3264 | return 1; |
| 3265 | } |
| 3266 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3267 | expr_ty body; |
| 3268 | |
| 3269 | if (PyObject_HasAttrString(obj, "body")) { |
| 3270 | int res; |
| 3271 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3272 | if (tmp == NULL) goto failed; |
| 3273 | res = obj2ast_expr(tmp, &body, arena); |
| 3274 | if (res != 0) goto failed; |
| 3275 | Py_XDECREF(tmp); |
| 3276 | tmp = NULL; |
| 3277 | } else { |
| 3278 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 3279 | return 1; |
| 3280 | } |
| 3281 | *out = Expression(body, arena); |
| 3282 | if (*out == NULL) goto failed; |
| 3283 | return 0; |
| 3284 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 3285 | isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type); |
| 3286 | if (isinstance == -1) { |
| 3287 | return 1; |
| 3288 | } |
| 3289 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3290 | asdl_seq* body; |
| 3291 | |
| 3292 | if (PyObject_HasAttrString(obj, "body")) { |
| 3293 | int res; |
| 3294 | Py_ssize_t len; |
| 3295 | Py_ssize_t i; |
| 3296 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3297 | if (tmp == NULL) goto failed; |
| 3298 | if (!PyList_Check(tmp)) { |
| 3299 | PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3300 | goto failed; |
| 3301 | } |
| 3302 | len = PyList_GET_SIZE(tmp); |
| 3303 | body = asdl_seq_new(len, arena); |
| 3304 | if (body == NULL) goto failed; |
| 3305 | for (i = 0; i < len; i++) { |
| 3306 | stmt_ty value; |
| 3307 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3308 | if (res != 0) goto failed; |
| 3309 | asdl_seq_SET(body, i, value); |
| 3310 | } |
| 3311 | Py_XDECREF(tmp); |
| 3312 | tmp = NULL; |
| 3313 | } else { |
| 3314 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite"); |
| 3315 | return 1; |
| 3316 | } |
| 3317 | *out = Suite(body, arena); |
| 3318 | if (*out == NULL) goto failed; |
| 3319 | return 0; |
| 3320 | } |
| 3321 | |
| 3322 | tmp = PyObject_Repr(obj); |
| 3323 | if (tmp == NULL) goto failed; |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 3324 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %.400s", PyString_AS_STRING(tmp)); |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3325 | failed: |
| 3326 | Py_XDECREF(tmp); |
| 3327 | return 1; |
| 3328 | } |
| 3329 | |
| 3330 | int |
| 3331 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 3332 | { |
| 3333 | PyObject* tmp = NULL; |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 3334 | int isinstance; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3335 | |
| 3336 | int lineno; |
| 3337 | int col_offset; |
| 3338 | |
| 3339 | if (obj == Py_None) { |
| 3340 | *out = NULL; |
| 3341 | return 0; |
| 3342 | } |
| 3343 | if (PyObject_HasAttrString(obj, "lineno")) { |
| 3344 | int res; |
| 3345 | tmp = PyObject_GetAttrString(obj, "lineno"); |
| 3346 | if (tmp == NULL) goto failed; |
| 3347 | res = obj2ast_int(tmp, &lineno, arena); |
| 3348 | if (res != 0) goto failed; |
| 3349 | Py_XDECREF(tmp); |
| 3350 | tmp = NULL; |
| 3351 | } else { |
| 3352 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 3353 | return 1; |
| 3354 | } |
| 3355 | if (PyObject_HasAttrString(obj, "col_offset")) { |
| 3356 | int res; |
| 3357 | tmp = PyObject_GetAttrString(obj, "col_offset"); |
| 3358 | if (tmp == NULL) goto failed; |
| 3359 | res = obj2ast_int(tmp, &col_offset, arena); |
| 3360 | if (res != 0) goto failed; |
| 3361 | Py_XDECREF(tmp); |
| 3362 | tmp = NULL; |
| 3363 | } else { |
| 3364 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 3365 | return 1; |
| 3366 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 3367 | isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type); |
| 3368 | if (isinstance == -1) { |
| 3369 | return 1; |
| 3370 | } |
| 3371 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3372 | identifier name; |
| 3373 | arguments_ty args; |
| 3374 | asdl_seq* body; |
| 3375 | asdl_seq* decorator_list; |
| 3376 | |
| 3377 | if (PyObject_HasAttrString(obj, "name")) { |
| 3378 | int res; |
| 3379 | tmp = PyObject_GetAttrString(obj, "name"); |
| 3380 | if (tmp == NULL) goto failed; |
| 3381 | res = obj2ast_identifier(tmp, &name, arena); |
| 3382 | if (res != 0) goto failed; |
| 3383 | Py_XDECREF(tmp); |
| 3384 | tmp = NULL; |
| 3385 | } else { |
| 3386 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 3387 | return 1; |
| 3388 | } |
| 3389 | if (PyObject_HasAttrString(obj, "args")) { |
| 3390 | int res; |
| 3391 | tmp = PyObject_GetAttrString(obj, "args"); |
| 3392 | if (tmp == NULL) goto failed; |
| 3393 | res = obj2ast_arguments(tmp, &args, arena); |
| 3394 | if (res != 0) goto failed; |
| 3395 | Py_XDECREF(tmp); |
| 3396 | tmp = NULL; |
| 3397 | } else { |
| 3398 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 3399 | return 1; |
| 3400 | } |
| 3401 | if (PyObject_HasAttrString(obj, "body")) { |
| 3402 | int res; |
| 3403 | Py_ssize_t len; |
| 3404 | Py_ssize_t i; |
| 3405 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3406 | if (tmp == NULL) goto failed; |
| 3407 | if (!PyList_Check(tmp)) { |
| 3408 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3409 | goto failed; |
| 3410 | } |
| 3411 | len = PyList_GET_SIZE(tmp); |
| 3412 | body = asdl_seq_new(len, arena); |
| 3413 | if (body == NULL) goto failed; |
| 3414 | for (i = 0; i < len; i++) { |
| 3415 | stmt_ty value; |
| 3416 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3417 | if (res != 0) goto failed; |
| 3418 | asdl_seq_SET(body, i, value); |
| 3419 | } |
| 3420 | Py_XDECREF(tmp); |
| 3421 | tmp = NULL; |
| 3422 | } else { |
| 3423 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 3424 | return 1; |
| 3425 | } |
| 3426 | if (PyObject_HasAttrString(obj, "decorator_list")) { |
| 3427 | int res; |
| 3428 | Py_ssize_t len; |
| 3429 | Py_ssize_t i; |
| 3430 | tmp = PyObject_GetAttrString(obj, "decorator_list"); |
| 3431 | if (tmp == NULL) goto failed; |
| 3432 | if (!PyList_Check(tmp)) { |
| 3433 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3434 | goto failed; |
| 3435 | } |
| 3436 | len = PyList_GET_SIZE(tmp); |
| 3437 | decorator_list = asdl_seq_new(len, arena); |
| 3438 | if (decorator_list == NULL) goto failed; |
| 3439 | for (i = 0; i < len; i++) { |
| 3440 | expr_ty value; |
| 3441 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3442 | if (res != 0) goto failed; |
| 3443 | asdl_seq_SET(decorator_list, i, value); |
| 3444 | } |
| 3445 | Py_XDECREF(tmp); |
| 3446 | tmp = NULL; |
| 3447 | } else { |
| 3448 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 3449 | return 1; |
| 3450 | } |
| 3451 | *out = FunctionDef(name, args, body, decorator_list, lineno, |
| 3452 | col_offset, arena); |
| 3453 | if (*out == NULL) goto failed; |
| 3454 | return 0; |
| 3455 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 3456 | isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type); |
| 3457 | if (isinstance == -1) { |
| 3458 | return 1; |
| 3459 | } |
| 3460 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3461 | identifier name; |
| 3462 | asdl_seq* bases; |
| 3463 | asdl_seq* body; |
| 3464 | asdl_seq* decorator_list; |
| 3465 | |
| 3466 | if (PyObject_HasAttrString(obj, "name")) { |
| 3467 | int res; |
| 3468 | tmp = PyObject_GetAttrString(obj, "name"); |
| 3469 | if (tmp == NULL) goto failed; |
| 3470 | res = obj2ast_identifier(tmp, &name, arena); |
| 3471 | if (res != 0) goto failed; |
| 3472 | Py_XDECREF(tmp); |
| 3473 | tmp = NULL; |
| 3474 | } else { |
| 3475 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 3476 | return 1; |
| 3477 | } |
| 3478 | if (PyObject_HasAttrString(obj, "bases")) { |
| 3479 | int res; |
| 3480 | Py_ssize_t len; |
| 3481 | Py_ssize_t i; |
| 3482 | tmp = PyObject_GetAttrString(obj, "bases"); |
| 3483 | if (tmp == NULL) goto failed; |
| 3484 | if (!PyList_Check(tmp)) { |
| 3485 | PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3486 | goto failed; |
| 3487 | } |
| 3488 | len = PyList_GET_SIZE(tmp); |
| 3489 | bases = asdl_seq_new(len, arena); |
| 3490 | if (bases == NULL) goto failed; |
| 3491 | for (i = 0; i < len; i++) { |
| 3492 | expr_ty value; |
| 3493 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3494 | if (res != 0) goto failed; |
| 3495 | asdl_seq_SET(bases, i, value); |
| 3496 | } |
| 3497 | Py_XDECREF(tmp); |
| 3498 | tmp = NULL; |
| 3499 | } else { |
| 3500 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 3501 | return 1; |
| 3502 | } |
| 3503 | if (PyObject_HasAttrString(obj, "body")) { |
| 3504 | int res; |
| 3505 | Py_ssize_t len; |
| 3506 | Py_ssize_t i; |
| 3507 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3508 | if (tmp == NULL) goto failed; |
| 3509 | if (!PyList_Check(tmp)) { |
| 3510 | PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3511 | goto failed; |
| 3512 | } |
| 3513 | len = PyList_GET_SIZE(tmp); |
| 3514 | body = asdl_seq_new(len, arena); |
| 3515 | if (body == NULL) goto failed; |
| 3516 | for (i = 0; i < len; i++) { |
| 3517 | stmt_ty value; |
| 3518 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3519 | if (res != 0) goto failed; |
| 3520 | asdl_seq_SET(body, i, value); |
| 3521 | } |
| 3522 | Py_XDECREF(tmp); |
| 3523 | tmp = NULL; |
| 3524 | } else { |
| 3525 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 3526 | return 1; |
| 3527 | } |
| 3528 | if (PyObject_HasAttrString(obj, "decorator_list")) { |
| 3529 | int res; |
| 3530 | Py_ssize_t len; |
| 3531 | Py_ssize_t i; |
| 3532 | tmp = PyObject_GetAttrString(obj, "decorator_list"); |
| 3533 | if (tmp == NULL) goto failed; |
| 3534 | if (!PyList_Check(tmp)) { |
| 3535 | PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3536 | goto failed; |
| 3537 | } |
| 3538 | len = PyList_GET_SIZE(tmp); |
| 3539 | decorator_list = asdl_seq_new(len, arena); |
| 3540 | if (decorator_list == NULL) goto failed; |
| 3541 | for (i = 0; i < len; i++) { |
| 3542 | expr_ty value; |
| 3543 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3544 | if (res != 0) goto failed; |
| 3545 | asdl_seq_SET(decorator_list, i, value); |
| 3546 | } |
| 3547 | Py_XDECREF(tmp); |
| 3548 | tmp = NULL; |
| 3549 | } else { |
| 3550 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 3551 | return 1; |
| 3552 | } |
| 3553 | *out = ClassDef(name, bases, body, decorator_list, lineno, |
| 3554 | col_offset, arena); |
| 3555 | if (*out == NULL) goto failed; |
| 3556 | return 0; |
| 3557 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 3558 | isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type); |
| 3559 | if (isinstance == -1) { |
| 3560 | return 1; |
| 3561 | } |
| 3562 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3563 | expr_ty value; |
| 3564 | |
| 3565 | if (PyObject_HasAttrString(obj, "value")) { |
| 3566 | int res; |
| 3567 | tmp = PyObject_GetAttrString(obj, "value"); |
| 3568 | if (tmp == NULL) goto failed; |
| 3569 | res = obj2ast_expr(tmp, &value, arena); |
| 3570 | if (res != 0) goto failed; |
| 3571 | Py_XDECREF(tmp); |
| 3572 | tmp = NULL; |
| 3573 | } else { |
| 3574 | value = NULL; |
| 3575 | } |
| 3576 | *out = Return(value, lineno, col_offset, arena); |
| 3577 | if (*out == NULL) goto failed; |
| 3578 | return 0; |
| 3579 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 3580 | isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type); |
| 3581 | if (isinstance == -1) { |
| 3582 | return 1; |
| 3583 | } |
| 3584 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3585 | asdl_seq* targets; |
| 3586 | |
| 3587 | if (PyObject_HasAttrString(obj, "targets")) { |
| 3588 | int res; |
| 3589 | Py_ssize_t len; |
| 3590 | Py_ssize_t i; |
| 3591 | tmp = PyObject_GetAttrString(obj, "targets"); |
| 3592 | if (tmp == NULL) goto failed; |
| 3593 | if (!PyList_Check(tmp)) { |
| 3594 | PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3595 | goto failed; |
| 3596 | } |
| 3597 | len = PyList_GET_SIZE(tmp); |
| 3598 | targets = asdl_seq_new(len, arena); |
| 3599 | if (targets == NULL) goto failed; |
| 3600 | for (i = 0; i < len; i++) { |
| 3601 | expr_ty value; |
| 3602 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3603 | if (res != 0) goto failed; |
| 3604 | asdl_seq_SET(targets, i, value); |
| 3605 | } |
| 3606 | Py_XDECREF(tmp); |
| 3607 | tmp = NULL; |
| 3608 | } else { |
| 3609 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 3610 | return 1; |
| 3611 | } |
| 3612 | *out = Delete(targets, lineno, col_offset, arena); |
| 3613 | if (*out == NULL) goto failed; |
| 3614 | return 0; |
| 3615 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 3616 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type); |
| 3617 | if (isinstance == -1) { |
| 3618 | return 1; |
| 3619 | } |
| 3620 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3621 | asdl_seq* targets; |
| 3622 | expr_ty value; |
| 3623 | |
| 3624 | if (PyObject_HasAttrString(obj, "targets")) { |
| 3625 | int res; |
| 3626 | Py_ssize_t len; |
| 3627 | Py_ssize_t i; |
| 3628 | tmp = PyObject_GetAttrString(obj, "targets"); |
| 3629 | if (tmp == NULL) goto failed; |
| 3630 | if (!PyList_Check(tmp)) { |
| 3631 | PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3632 | goto failed; |
| 3633 | } |
| 3634 | len = PyList_GET_SIZE(tmp); |
| 3635 | targets = asdl_seq_new(len, arena); |
| 3636 | if (targets == NULL) goto failed; |
| 3637 | for (i = 0; i < len; i++) { |
| 3638 | expr_ty value; |
| 3639 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3640 | if (res != 0) goto failed; |
| 3641 | asdl_seq_SET(targets, i, value); |
| 3642 | } |
| 3643 | Py_XDECREF(tmp); |
| 3644 | tmp = NULL; |
| 3645 | } else { |
| 3646 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 3647 | return 1; |
| 3648 | } |
| 3649 | if (PyObject_HasAttrString(obj, "value")) { |
| 3650 | int res; |
| 3651 | tmp = PyObject_GetAttrString(obj, "value"); |
| 3652 | if (tmp == NULL) goto failed; |
| 3653 | res = obj2ast_expr(tmp, &value, arena); |
| 3654 | if (res != 0) goto failed; |
| 3655 | Py_XDECREF(tmp); |
| 3656 | tmp = NULL; |
| 3657 | } else { |
| 3658 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 3659 | return 1; |
| 3660 | } |
| 3661 | *out = Assign(targets, value, lineno, col_offset, arena); |
| 3662 | if (*out == NULL) goto failed; |
| 3663 | return 0; |
| 3664 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 3665 | isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type); |
| 3666 | if (isinstance == -1) { |
| 3667 | return 1; |
| 3668 | } |
| 3669 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3670 | expr_ty target; |
| 3671 | operator_ty op; |
| 3672 | expr_ty value; |
| 3673 | |
| 3674 | if (PyObject_HasAttrString(obj, "target")) { |
| 3675 | int res; |
| 3676 | tmp = PyObject_GetAttrString(obj, "target"); |
| 3677 | if (tmp == NULL) goto failed; |
| 3678 | res = obj2ast_expr(tmp, &target, arena); |
| 3679 | if (res != 0) goto failed; |
| 3680 | Py_XDECREF(tmp); |
| 3681 | tmp = NULL; |
| 3682 | } else { |
| 3683 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 3684 | return 1; |
| 3685 | } |
| 3686 | if (PyObject_HasAttrString(obj, "op")) { |
| 3687 | int res; |
| 3688 | tmp = PyObject_GetAttrString(obj, "op"); |
| 3689 | if (tmp == NULL) goto failed; |
| 3690 | res = obj2ast_operator(tmp, &op, arena); |
| 3691 | if (res != 0) goto failed; |
| 3692 | Py_XDECREF(tmp); |
| 3693 | tmp = NULL; |
| 3694 | } else { |
| 3695 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 3696 | return 1; |
| 3697 | } |
| 3698 | if (PyObject_HasAttrString(obj, "value")) { |
| 3699 | int res; |
| 3700 | tmp = PyObject_GetAttrString(obj, "value"); |
| 3701 | if (tmp == NULL) goto failed; |
| 3702 | res = obj2ast_expr(tmp, &value, arena); |
| 3703 | if (res != 0) goto failed; |
| 3704 | Py_XDECREF(tmp); |
| 3705 | tmp = NULL; |
| 3706 | } else { |
| 3707 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 3708 | return 1; |
| 3709 | } |
| 3710 | *out = AugAssign(target, op, value, lineno, col_offset, arena); |
| 3711 | if (*out == NULL) goto failed; |
| 3712 | return 0; |
| 3713 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 3714 | isinstance = PyObject_IsInstance(obj, (PyObject*)Print_type); |
| 3715 | if (isinstance == -1) { |
| 3716 | return 1; |
| 3717 | } |
| 3718 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3719 | expr_ty dest; |
| 3720 | asdl_seq* values; |
| 3721 | bool nl; |
| 3722 | |
| 3723 | if (PyObject_HasAttrString(obj, "dest")) { |
| 3724 | int res; |
| 3725 | tmp = PyObject_GetAttrString(obj, "dest"); |
| 3726 | if (tmp == NULL) goto failed; |
| 3727 | res = obj2ast_expr(tmp, &dest, arena); |
| 3728 | if (res != 0) goto failed; |
| 3729 | Py_XDECREF(tmp); |
| 3730 | tmp = NULL; |
| 3731 | } else { |
| 3732 | dest = NULL; |
| 3733 | } |
| 3734 | if (PyObject_HasAttrString(obj, "values")) { |
| 3735 | int res; |
| 3736 | Py_ssize_t len; |
| 3737 | Py_ssize_t i; |
| 3738 | tmp = PyObject_GetAttrString(obj, "values"); |
| 3739 | if (tmp == NULL) goto failed; |
| 3740 | if (!PyList_Check(tmp)) { |
| 3741 | PyErr_Format(PyExc_TypeError, "Print field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3742 | goto failed; |
| 3743 | } |
| 3744 | len = PyList_GET_SIZE(tmp); |
| 3745 | values = asdl_seq_new(len, arena); |
| 3746 | if (values == NULL) goto failed; |
| 3747 | for (i = 0; i < len; i++) { |
| 3748 | expr_ty value; |
| 3749 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3750 | if (res != 0) goto failed; |
| 3751 | asdl_seq_SET(values, i, value); |
| 3752 | } |
| 3753 | Py_XDECREF(tmp); |
| 3754 | tmp = NULL; |
| 3755 | } else { |
| 3756 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Print"); |
| 3757 | return 1; |
| 3758 | } |
| 3759 | if (PyObject_HasAttrString(obj, "nl")) { |
| 3760 | int res; |
| 3761 | tmp = PyObject_GetAttrString(obj, "nl"); |
| 3762 | if (tmp == NULL) goto failed; |
| 3763 | res = obj2ast_bool(tmp, &nl, arena); |
| 3764 | if (res != 0) goto failed; |
| 3765 | Py_XDECREF(tmp); |
| 3766 | tmp = NULL; |
| 3767 | } else { |
| 3768 | PyErr_SetString(PyExc_TypeError, "required field \"nl\" missing from Print"); |
| 3769 | return 1; |
| 3770 | } |
| 3771 | *out = Print(dest, values, nl, lineno, col_offset, arena); |
| 3772 | if (*out == NULL) goto failed; |
| 3773 | return 0; |
| 3774 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 3775 | isinstance = PyObject_IsInstance(obj, (PyObject*)For_type); |
| 3776 | if (isinstance == -1) { |
| 3777 | return 1; |
| 3778 | } |
| 3779 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3780 | expr_ty target; |
| 3781 | expr_ty iter; |
| 3782 | asdl_seq* body; |
| 3783 | asdl_seq* orelse; |
| 3784 | |
| 3785 | if (PyObject_HasAttrString(obj, "target")) { |
| 3786 | int res; |
| 3787 | tmp = PyObject_GetAttrString(obj, "target"); |
| 3788 | if (tmp == NULL) goto failed; |
| 3789 | res = obj2ast_expr(tmp, &target, arena); |
| 3790 | if (res != 0) goto failed; |
| 3791 | Py_XDECREF(tmp); |
| 3792 | tmp = NULL; |
| 3793 | } else { |
| 3794 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 3795 | return 1; |
| 3796 | } |
| 3797 | if (PyObject_HasAttrString(obj, "iter")) { |
| 3798 | int res; |
| 3799 | tmp = PyObject_GetAttrString(obj, "iter"); |
| 3800 | if (tmp == NULL) goto failed; |
| 3801 | res = obj2ast_expr(tmp, &iter, arena); |
| 3802 | if (res != 0) goto failed; |
| 3803 | Py_XDECREF(tmp); |
| 3804 | tmp = NULL; |
| 3805 | } else { |
| 3806 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 3807 | return 1; |
| 3808 | } |
| 3809 | if (PyObject_HasAttrString(obj, "body")) { |
| 3810 | int res; |
| 3811 | Py_ssize_t len; |
| 3812 | Py_ssize_t i; |
| 3813 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3814 | if (tmp == NULL) goto failed; |
| 3815 | if (!PyList_Check(tmp)) { |
| 3816 | PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3817 | goto failed; |
| 3818 | } |
| 3819 | len = PyList_GET_SIZE(tmp); |
| 3820 | body = asdl_seq_new(len, arena); |
| 3821 | if (body == NULL) goto failed; |
| 3822 | for (i = 0; i < len; i++) { |
| 3823 | stmt_ty value; |
| 3824 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3825 | if (res != 0) goto failed; |
| 3826 | asdl_seq_SET(body, i, value); |
| 3827 | } |
| 3828 | Py_XDECREF(tmp); |
| 3829 | tmp = NULL; |
| 3830 | } else { |
| 3831 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 3832 | return 1; |
| 3833 | } |
| 3834 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 3835 | int res; |
| 3836 | Py_ssize_t len; |
| 3837 | Py_ssize_t i; |
| 3838 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 3839 | if (tmp == NULL) goto failed; |
| 3840 | if (!PyList_Check(tmp)) { |
| 3841 | PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3842 | goto failed; |
| 3843 | } |
| 3844 | len = PyList_GET_SIZE(tmp); |
| 3845 | orelse = asdl_seq_new(len, arena); |
| 3846 | if (orelse == NULL) goto failed; |
| 3847 | for (i = 0; i < len; i++) { |
| 3848 | stmt_ty value; |
| 3849 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3850 | if (res != 0) goto failed; |
| 3851 | asdl_seq_SET(orelse, i, value); |
| 3852 | } |
| 3853 | Py_XDECREF(tmp); |
| 3854 | tmp = NULL; |
| 3855 | } else { |
| 3856 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 3857 | return 1; |
| 3858 | } |
| 3859 | *out = For(target, iter, body, orelse, lineno, col_offset, |
| 3860 | arena); |
| 3861 | if (*out == NULL) goto failed; |
| 3862 | return 0; |
| 3863 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 3864 | isinstance = PyObject_IsInstance(obj, (PyObject*)While_type); |
| 3865 | if (isinstance == -1) { |
| 3866 | return 1; |
| 3867 | } |
| 3868 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3869 | expr_ty test; |
| 3870 | asdl_seq* body; |
| 3871 | asdl_seq* orelse; |
| 3872 | |
| 3873 | if (PyObject_HasAttrString(obj, "test")) { |
| 3874 | int res; |
| 3875 | tmp = PyObject_GetAttrString(obj, "test"); |
| 3876 | if (tmp == NULL) goto failed; |
| 3877 | res = obj2ast_expr(tmp, &test, arena); |
| 3878 | if (res != 0) goto failed; |
| 3879 | Py_XDECREF(tmp); |
| 3880 | tmp = NULL; |
| 3881 | } else { |
| 3882 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 3883 | return 1; |
| 3884 | } |
| 3885 | if (PyObject_HasAttrString(obj, "body")) { |
| 3886 | int res; |
| 3887 | Py_ssize_t len; |
| 3888 | Py_ssize_t i; |
| 3889 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3890 | if (tmp == NULL) goto failed; |
| 3891 | if (!PyList_Check(tmp)) { |
| 3892 | PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3893 | goto failed; |
| 3894 | } |
| 3895 | len = PyList_GET_SIZE(tmp); |
| 3896 | body = asdl_seq_new(len, arena); |
| 3897 | if (body == NULL) goto failed; |
| 3898 | for (i = 0; i < len; i++) { |
| 3899 | stmt_ty value; |
| 3900 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3901 | if (res != 0) goto failed; |
| 3902 | asdl_seq_SET(body, i, value); |
| 3903 | } |
| 3904 | Py_XDECREF(tmp); |
| 3905 | tmp = NULL; |
| 3906 | } else { |
| 3907 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 3908 | return 1; |
| 3909 | } |
| 3910 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 3911 | int res; |
| 3912 | Py_ssize_t len; |
| 3913 | Py_ssize_t i; |
| 3914 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 3915 | if (tmp == NULL) goto failed; |
| 3916 | if (!PyList_Check(tmp)) { |
| 3917 | PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3918 | goto failed; |
| 3919 | } |
| 3920 | len = PyList_GET_SIZE(tmp); |
| 3921 | orelse = asdl_seq_new(len, arena); |
| 3922 | if (orelse == NULL) goto failed; |
| 3923 | for (i = 0; i < len; i++) { |
| 3924 | stmt_ty value; |
| 3925 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3926 | if (res != 0) goto failed; |
| 3927 | asdl_seq_SET(orelse, i, value); |
| 3928 | } |
| 3929 | Py_XDECREF(tmp); |
| 3930 | tmp = NULL; |
| 3931 | } else { |
| 3932 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 3933 | return 1; |
| 3934 | } |
| 3935 | *out = While(test, body, orelse, lineno, col_offset, arena); |
| 3936 | if (*out == NULL) goto failed; |
| 3937 | return 0; |
| 3938 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 3939 | isinstance = PyObject_IsInstance(obj, (PyObject*)If_type); |
| 3940 | if (isinstance == -1) { |
| 3941 | return 1; |
| 3942 | } |
| 3943 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3944 | expr_ty test; |
| 3945 | asdl_seq* body; |
| 3946 | asdl_seq* orelse; |
| 3947 | |
| 3948 | if (PyObject_HasAttrString(obj, "test")) { |
| 3949 | int res; |
| 3950 | tmp = PyObject_GetAttrString(obj, "test"); |
| 3951 | if (tmp == NULL) goto failed; |
| 3952 | res = obj2ast_expr(tmp, &test, arena); |
| 3953 | if (res != 0) goto failed; |
| 3954 | Py_XDECREF(tmp); |
| 3955 | tmp = NULL; |
| 3956 | } else { |
| 3957 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 3958 | return 1; |
| 3959 | } |
| 3960 | if (PyObject_HasAttrString(obj, "body")) { |
| 3961 | int res; |
| 3962 | Py_ssize_t len; |
| 3963 | Py_ssize_t i; |
| 3964 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3965 | if (tmp == NULL) goto failed; |
| 3966 | if (!PyList_Check(tmp)) { |
| 3967 | PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3968 | goto failed; |
| 3969 | } |
| 3970 | len = PyList_GET_SIZE(tmp); |
| 3971 | body = asdl_seq_new(len, arena); |
| 3972 | if (body == NULL) goto failed; |
| 3973 | for (i = 0; i < len; i++) { |
| 3974 | stmt_ty value; |
| 3975 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3976 | if (res != 0) goto failed; |
| 3977 | asdl_seq_SET(body, i, value); |
| 3978 | } |
| 3979 | Py_XDECREF(tmp); |
| 3980 | tmp = NULL; |
| 3981 | } else { |
| 3982 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 3983 | return 1; |
| 3984 | } |
| 3985 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 3986 | int res; |
| 3987 | Py_ssize_t len; |
| 3988 | Py_ssize_t i; |
| 3989 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 3990 | if (tmp == NULL) goto failed; |
| 3991 | if (!PyList_Check(tmp)) { |
| 3992 | PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3993 | goto failed; |
| 3994 | } |
| 3995 | len = PyList_GET_SIZE(tmp); |
| 3996 | orelse = asdl_seq_new(len, arena); |
| 3997 | if (orelse == NULL) goto failed; |
| 3998 | for (i = 0; i < len; i++) { |
| 3999 | stmt_ty value; |
| 4000 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4001 | if (res != 0) goto failed; |
| 4002 | asdl_seq_SET(orelse, i, value); |
| 4003 | } |
| 4004 | Py_XDECREF(tmp); |
| 4005 | tmp = NULL; |
| 4006 | } else { |
| 4007 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 4008 | return 1; |
| 4009 | } |
| 4010 | *out = If(test, body, orelse, lineno, col_offset, arena); |
| 4011 | if (*out == NULL) goto failed; |
| 4012 | return 0; |
| 4013 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 4014 | isinstance = PyObject_IsInstance(obj, (PyObject*)With_type); |
| 4015 | if (isinstance == -1) { |
| 4016 | return 1; |
| 4017 | } |
| 4018 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4019 | expr_ty context_expr; |
| 4020 | expr_ty optional_vars; |
| 4021 | asdl_seq* body; |
| 4022 | |
| 4023 | if (PyObject_HasAttrString(obj, "context_expr")) { |
| 4024 | int res; |
| 4025 | tmp = PyObject_GetAttrString(obj, "context_expr"); |
| 4026 | if (tmp == NULL) goto failed; |
| 4027 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 4028 | if (res != 0) goto failed; |
| 4029 | Py_XDECREF(tmp); |
| 4030 | tmp = NULL; |
| 4031 | } else { |
| 4032 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from With"); |
| 4033 | return 1; |
| 4034 | } |
| 4035 | if (PyObject_HasAttrString(obj, "optional_vars")) { |
| 4036 | int res; |
| 4037 | tmp = PyObject_GetAttrString(obj, "optional_vars"); |
| 4038 | if (tmp == NULL) goto failed; |
| 4039 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 4040 | if (res != 0) goto failed; |
| 4041 | Py_XDECREF(tmp); |
| 4042 | tmp = NULL; |
| 4043 | } else { |
| 4044 | optional_vars = NULL; |
| 4045 | } |
| 4046 | if (PyObject_HasAttrString(obj, "body")) { |
| 4047 | int res; |
| 4048 | Py_ssize_t len; |
| 4049 | Py_ssize_t i; |
| 4050 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4051 | if (tmp == NULL) goto failed; |
| 4052 | if (!PyList_Check(tmp)) { |
| 4053 | PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4054 | goto failed; |
| 4055 | } |
| 4056 | len = PyList_GET_SIZE(tmp); |
| 4057 | body = asdl_seq_new(len, arena); |
| 4058 | if (body == NULL) goto failed; |
| 4059 | for (i = 0; i < len; i++) { |
| 4060 | stmt_ty value; |
| 4061 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4062 | if (res != 0) goto failed; |
| 4063 | asdl_seq_SET(body, i, value); |
| 4064 | } |
| 4065 | Py_XDECREF(tmp); |
| 4066 | tmp = NULL; |
| 4067 | } else { |
| 4068 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 4069 | return 1; |
| 4070 | } |
| 4071 | *out = With(context_expr, optional_vars, body, lineno, |
| 4072 | col_offset, arena); |
| 4073 | if (*out == NULL) goto failed; |
| 4074 | return 0; |
| 4075 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 4076 | isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type); |
| 4077 | if (isinstance == -1) { |
| 4078 | return 1; |
| 4079 | } |
| 4080 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4081 | expr_ty type; |
| 4082 | expr_ty inst; |
| 4083 | expr_ty tback; |
| 4084 | |
| 4085 | if (PyObject_HasAttrString(obj, "type")) { |
| 4086 | int res; |
| 4087 | tmp = PyObject_GetAttrString(obj, "type"); |
| 4088 | if (tmp == NULL) goto failed; |
| 4089 | res = obj2ast_expr(tmp, &type, arena); |
| 4090 | if (res != 0) goto failed; |
| 4091 | Py_XDECREF(tmp); |
| 4092 | tmp = NULL; |
| 4093 | } else { |
| 4094 | type = NULL; |
| 4095 | } |
| 4096 | if (PyObject_HasAttrString(obj, "inst")) { |
| 4097 | int res; |
| 4098 | tmp = PyObject_GetAttrString(obj, "inst"); |
| 4099 | if (tmp == NULL) goto failed; |
| 4100 | res = obj2ast_expr(tmp, &inst, arena); |
| 4101 | if (res != 0) goto failed; |
| 4102 | Py_XDECREF(tmp); |
| 4103 | tmp = NULL; |
| 4104 | } else { |
| 4105 | inst = NULL; |
| 4106 | } |
| 4107 | if (PyObject_HasAttrString(obj, "tback")) { |
| 4108 | int res; |
| 4109 | tmp = PyObject_GetAttrString(obj, "tback"); |
| 4110 | if (tmp == NULL) goto failed; |
| 4111 | res = obj2ast_expr(tmp, &tback, arena); |
| 4112 | if (res != 0) goto failed; |
| 4113 | Py_XDECREF(tmp); |
| 4114 | tmp = NULL; |
| 4115 | } else { |
| 4116 | tback = NULL; |
| 4117 | } |
| 4118 | *out = Raise(type, inst, tback, lineno, col_offset, arena); |
| 4119 | if (*out == NULL) goto failed; |
| 4120 | return 0; |
| 4121 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 4122 | isinstance = PyObject_IsInstance(obj, (PyObject*)TryExcept_type); |
| 4123 | if (isinstance == -1) { |
| 4124 | return 1; |
| 4125 | } |
| 4126 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4127 | asdl_seq* body; |
| 4128 | asdl_seq* handlers; |
| 4129 | asdl_seq* orelse; |
| 4130 | |
| 4131 | if (PyObject_HasAttrString(obj, "body")) { |
| 4132 | int res; |
| 4133 | Py_ssize_t len; |
| 4134 | Py_ssize_t i; |
| 4135 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4136 | if (tmp == NULL) goto failed; |
| 4137 | if (!PyList_Check(tmp)) { |
| 4138 | PyErr_Format(PyExc_TypeError, "TryExcept field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4139 | goto failed; |
| 4140 | } |
| 4141 | len = PyList_GET_SIZE(tmp); |
| 4142 | body = asdl_seq_new(len, arena); |
| 4143 | if (body == NULL) goto failed; |
| 4144 | for (i = 0; i < len; i++) { |
| 4145 | stmt_ty value; |
| 4146 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4147 | if (res != 0) goto failed; |
| 4148 | asdl_seq_SET(body, i, value); |
| 4149 | } |
| 4150 | Py_XDECREF(tmp); |
| 4151 | tmp = NULL; |
| 4152 | } else { |
| 4153 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryExcept"); |
| 4154 | return 1; |
| 4155 | } |
| 4156 | if (PyObject_HasAttrString(obj, "handlers")) { |
| 4157 | int res; |
| 4158 | Py_ssize_t len; |
| 4159 | Py_ssize_t i; |
| 4160 | tmp = PyObject_GetAttrString(obj, "handlers"); |
| 4161 | if (tmp == NULL) goto failed; |
| 4162 | if (!PyList_Check(tmp)) { |
| 4163 | PyErr_Format(PyExc_TypeError, "TryExcept field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4164 | goto failed; |
| 4165 | } |
| 4166 | len = PyList_GET_SIZE(tmp); |
| 4167 | handlers = asdl_seq_new(len, arena); |
| 4168 | if (handlers == NULL) goto failed; |
| 4169 | for (i = 0; i < len; i++) { |
| 4170 | excepthandler_ty value; |
| 4171 | res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4172 | if (res != 0) goto failed; |
| 4173 | asdl_seq_SET(handlers, i, value); |
| 4174 | } |
| 4175 | Py_XDECREF(tmp); |
| 4176 | tmp = NULL; |
| 4177 | } else { |
| 4178 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from TryExcept"); |
| 4179 | return 1; |
| 4180 | } |
| 4181 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4182 | int res; |
| 4183 | Py_ssize_t len; |
| 4184 | Py_ssize_t i; |
| 4185 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4186 | if (tmp == NULL) goto failed; |
| 4187 | if (!PyList_Check(tmp)) { |
| 4188 | PyErr_Format(PyExc_TypeError, "TryExcept field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4189 | goto failed; |
| 4190 | } |
| 4191 | len = PyList_GET_SIZE(tmp); |
| 4192 | orelse = asdl_seq_new(len, arena); |
| 4193 | if (orelse == NULL) goto failed; |
| 4194 | for (i = 0; i < len; i++) { |
| 4195 | stmt_ty value; |
| 4196 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4197 | if (res != 0) goto failed; |
| 4198 | asdl_seq_SET(orelse, i, value); |
| 4199 | } |
| 4200 | Py_XDECREF(tmp); |
| 4201 | tmp = NULL; |
| 4202 | } else { |
| 4203 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from TryExcept"); |
| 4204 | return 1; |
| 4205 | } |
| 4206 | *out = TryExcept(body, handlers, orelse, lineno, col_offset, |
| 4207 | arena); |
| 4208 | if (*out == NULL) goto failed; |
| 4209 | return 0; |
| 4210 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 4211 | isinstance = PyObject_IsInstance(obj, (PyObject*)TryFinally_type); |
| 4212 | if (isinstance == -1) { |
| 4213 | return 1; |
| 4214 | } |
| 4215 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4216 | asdl_seq* body; |
| 4217 | asdl_seq* finalbody; |
| 4218 | |
| 4219 | if (PyObject_HasAttrString(obj, "body")) { |
| 4220 | int res; |
| 4221 | Py_ssize_t len; |
| 4222 | Py_ssize_t i; |
| 4223 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4224 | if (tmp == NULL) goto failed; |
| 4225 | if (!PyList_Check(tmp)) { |
| 4226 | PyErr_Format(PyExc_TypeError, "TryFinally field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4227 | goto failed; |
| 4228 | } |
| 4229 | len = PyList_GET_SIZE(tmp); |
| 4230 | body = asdl_seq_new(len, arena); |
| 4231 | if (body == NULL) goto failed; |
| 4232 | for (i = 0; i < len; i++) { |
| 4233 | stmt_ty value; |
| 4234 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4235 | if (res != 0) goto failed; |
| 4236 | asdl_seq_SET(body, i, value); |
| 4237 | } |
| 4238 | Py_XDECREF(tmp); |
| 4239 | tmp = NULL; |
| 4240 | } else { |
| 4241 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryFinally"); |
| 4242 | return 1; |
| 4243 | } |
| 4244 | if (PyObject_HasAttrString(obj, "finalbody")) { |
| 4245 | int res; |
| 4246 | Py_ssize_t len; |
| 4247 | Py_ssize_t i; |
| 4248 | tmp = PyObject_GetAttrString(obj, "finalbody"); |
| 4249 | if (tmp == NULL) goto failed; |
| 4250 | if (!PyList_Check(tmp)) { |
| 4251 | PyErr_Format(PyExc_TypeError, "TryFinally field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4252 | goto failed; |
| 4253 | } |
| 4254 | len = PyList_GET_SIZE(tmp); |
| 4255 | finalbody = asdl_seq_new(len, arena); |
| 4256 | if (finalbody == NULL) goto failed; |
| 4257 | for (i = 0; i < len; i++) { |
| 4258 | stmt_ty value; |
| 4259 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4260 | if (res != 0) goto failed; |
| 4261 | asdl_seq_SET(finalbody, i, value); |
| 4262 | } |
| 4263 | Py_XDECREF(tmp); |
| 4264 | tmp = NULL; |
| 4265 | } else { |
| 4266 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from TryFinally"); |
| 4267 | return 1; |
| 4268 | } |
| 4269 | *out = TryFinally(body, finalbody, lineno, col_offset, arena); |
| 4270 | if (*out == NULL) goto failed; |
| 4271 | return 0; |
| 4272 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 4273 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type); |
| 4274 | if (isinstance == -1) { |
| 4275 | return 1; |
| 4276 | } |
| 4277 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4278 | expr_ty test; |
| 4279 | expr_ty msg; |
| 4280 | |
| 4281 | if (PyObject_HasAttrString(obj, "test")) { |
| 4282 | int res; |
| 4283 | tmp = PyObject_GetAttrString(obj, "test"); |
| 4284 | if (tmp == NULL) goto failed; |
| 4285 | res = obj2ast_expr(tmp, &test, arena); |
| 4286 | if (res != 0) goto failed; |
| 4287 | Py_XDECREF(tmp); |
| 4288 | tmp = NULL; |
| 4289 | } else { |
| 4290 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 4291 | return 1; |
| 4292 | } |
| 4293 | if (PyObject_HasAttrString(obj, "msg")) { |
| 4294 | int res; |
| 4295 | tmp = PyObject_GetAttrString(obj, "msg"); |
| 4296 | if (tmp == NULL) goto failed; |
| 4297 | res = obj2ast_expr(tmp, &msg, arena); |
| 4298 | if (res != 0) goto failed; |
| 4299 | Py_XDECREF(tmp); |
| 4300 | tmp = NULL; |
| 4301 | } else { |
| 4302 | msg = NULL; |
| 4303 | } |
| 4304 | *out = Assert(test, msg, lineno, col_offset, arena); |
| 4305 | if (*out == NULL) goto failed; |
| 4306 | return 0; |
| 4307 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 4308 | isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type); |
| 4309 | if (isinstance == -1) { |
| 4310 | return 1; |
| 4311 | } |
| 4312 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4313 | asdl_seq* names; |
| 4314 | |
| 4315 | if (PyObject_HasAttrString(obj, "names")) { |
| 4316 | int res; |
| 4317 | Py_ssize_t len; |
| 4318 | Py_ssize_t i; |
| 4319 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4320 | if (tmp == NULL) goto failed; |
| 4321 | if (!PyList_Check(tmp)) { |
| 4322 | PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4323 | goto failed; |
| 4324 | } |
| 4325 | len = PyList_GET_SIZE(tmp); |
| 4326 | names = asdl_seq_new(len, arena); |
| 4327 | if (names == NULL) goto failed; |
| 4328 | for (i = 0; i < len; i++) { |
| 4329 | alias_ty value; |
| 4330 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4331 | if (res != 0) goto failed; |
| 4332 | asdl_seq_SET(names, i, value); |
| 4333 | } |
| 4334 | Py_XDECREF(tmp); |
| 4335 | tmp = NULL; |
| 4336 | } else { |
| 4337 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 4338 | return 1; |
| 4339 | } |
| 4340 | *out = Import(names, lineno, col_offset, arena); |
| 4341 | if (*out == NULL) goto failed; |
| 4342 | return 0; |
| 4343 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 4344 | isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type); |
| 4345 | if (isinstance == -1) { |
| 4346 | return 1; |
| 4347 | } |
| 4348 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4349 | identifier module; |
| 4350 | asdl_seq* names; |
| 4351 | int level; |
| 4352 | |
| 4353 | if (PyObject_HasAttrString(obj, "module")) { |
| 4354 | int res; |
| 4355 | tmp = PyObject_GetAttrString(obj, "module"); |
| 4356 | if (tmp == NULL) goto failed; |
| 4357 | res = obj2ast_identifier(tmp, &module, arena); |
| 4358 | if (res != 0) goto failed; |
| 4359 | Py_XDECREF(tmp); |
| 4360 | tmp = NULL; |
| 4361 | } else { |
| 4362 | PyErr_SetString(PyExc_TypeError, "required field \"module\" missing from ImportFrom"); |
| 4363 | return 1; |
| 4364 | } |
| 4365 | if (PyObject_HasAttrString(obj, "names")) { |
| 4366 | int res; |
| 4367 | Py_ssize_t len; |
| 4368 | Py_ssize_t i; |
| 4369 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4370 | if (tmp == NULL) goto failed; |
| 4371 | if (!PyList_Check(tmp)) { |
| 4372 | PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4373 | goto failed; |
| 4374 | } |
| 4375 | len = PyList_GET_SIZE(tmp); |
| 4376 | names = asdl_seq_new(len, arena); |
| 4377 | if (names == NULL) goto failed; |
| 4378 | for (i = 0; i < len; i++) { |
| 4379 | alias_ty value; |
| 4380 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4381 | if (res != 0) goto failed; |
| 4382 | asdl_seq_SET(names, i, value); |
| 4383 | } |
| 4384 | Py_XDECREF(tmp); |
| 4385 | tmp = NULL; |
| 4386 | } else { |
| 4387 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 4388 | return 1; |
| 4389 | } |
| 4390 | if (PyObject_HasAttrString(obj, "level")) { |
| 4391 | int res; |
| 4392 | tmp = PyObject_GetAttrString(obj, "level"); |
| 4393 | if (tmp == NULL) goto failed; |
| 4394 | res = obj2ast_int(tmp, &level, arena); |
| 4395 | if (res != 0) goto failed; |
| 4396 | Py_XDECREF(tmp); |
| 4397 | tmp = NULL; |
| 4398 | } else { |
| 4399 | level = 0; |
| 4400 | } |
| 4401 | *out = ImportFrom(module, names, level, lineno, col_offset, |
| 4402 | arena); |
| 4403 | if (*out == NULL) goto failed; |
| 4404 | return 0; |
| 4405 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 4406 | isinstance = PyObject_IsInstance(obj, (PyObject*)Exec_type); |
| 4407 | if (isinstance == -1) { |
| 4408 | return 1; |
| 4409 | } |
| 4410 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4411 | expr_ty body; |
| 4412 | expr_ty globals; |
| 4413 | expr_ty locals; |
| 4414 | |
| 4415 | if (PyObject_HasAttrString(obj, "body")) { |
| 4416 | int res; |
| 4417 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4418 | if (tmp == NULL) goto failed; |
| 4419 | res = obj2ast_expr(tmp, &body, arena); |
| 4420 | if (res != 0) goto failed; |
| 4421 | Py_XDECREF(tmp); |
| 4422 | tmp = NULL; |
| 4423 | } else { |
| 4424 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Exec"); |
| 4425 | return 1; |
| 4426 | } |
| 4427 | if (PyObject_HasAttrString(obj, "globals")) { |
| 4428 | int res; |
| 4429 | tmp = PyObject_GetAttrString(obj, "globals"); |
| 4430 | if (tmp == NULL) goto failed; |
| 4431 | res = obj2ast_expr(tmp, &globals, arena); |
| 4432 | if (res != 0) goto failed; |
| 4433 | Py_XDECREF(tmp); |
| 4434 | tmp = NULL; |
| 4435 | } else { |
| 4436 | globals = NULL; |
| 4437 | } |
| 4438 | if (PyObject_HasAttrString(obj, "locals")) { |
| 4439 | int res; |
| 4440 | tmp = PyObject_GetAttrString(obj, "locals"); |
| 4441 | if (tmp == NULL) goto failed; |
| 4442 | res = obj2ast_expr(tmp, &locals, arena); |
| 4443 | if (res != 0) goto failed; |
| 4444 | Py_XDECREF(tmp); |
| 4445 | tmp = NULL; |
| 4446 | } else { |
| 4447 | locals = NULL; |
| 4448 | } |
| 4449 | *out = Exec(body, globals, locals, lineno, col_offset, arena); |
| 4450 | if (*out == NULL) goto failed; |
| 4451 | return 0; |
| 4452 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 4453 | isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type); |
| 4454 | if (isinstance == -1) { |
| 4455 | return 1; |
| 4456 | } |
| 4457 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4458 | asdl_seq* names; |
| 4459 | |
| 4460 | if (PyObject_HasAttrString(obj, "names")) { |
| 4461 | int res; |
| 4462 | Py_ssize_t len; |
| 4463 | Py_ssize_t i; |
| 4464 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4465 | if (tmp == NULL) goto failed; |
| 4466 | if (!PyList_Check(tmp)) { |
| 4467 | PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4468 | goto failed; |
| 4469 | } |
| 4470 | len = PyList_GET_SIZE(tmp); |
| 4471 | names = asdl_seq_new(len, arena); |
| 4472 | if (names == NULL) goto failed; |
| 4473 | for (i = 0; i < len; i++) { |
| 4474 | identifier value; |
| 4475 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4476 | if (res != 0) goto failed; |
| 4477 | asdl_seq_SET(names, i, value); |
| 4478 | } |
| 4479 | Py_XDECREF(tmp); |
| 4480 | tmp = NULL; |
| 4481 | } else { |
| 4482 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 4483 | return 1; |
| 4484 | } |
| 4485 | *out = Global(names, lineno, col_offset, arena); |
| 4486 | if (*out == NULL) goto failed; |
| 4487 | return 0; |
| 4488 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 4489 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type); |
| 4490 | if (isinstance == -1) { |
| 4491 | return 1; |
| 4492 | } |
| 4493 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4494 | expr_ty value; |
| 4495 | |
| 4496 | if (PyObject_HasAttrString(obj, "value")) { |
| 4497 | int res; |
| 4498 | tmp = PyObject_GetAttrString(obj, "value"); |
| 4499 | if (tmp == NULL) goto failed; |
| 4500 | res = obj2ast_expr(tmp, &value, arena); |
| 4501 | if (res != 0) goto failed; |
| 4502 | Py_XDECREF(tmp); |
| 4503 | tmp = NULL; |
| 4504 | } else { |
| 4505 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 4506 | return 1; |
| 4507 | } |
| 4508 | *out = Expr(value, lineno, col_offset, arena); |
| 4509 | if (*out == NULL) goto failed; |
| 4510 | return 0; |
| 4511 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 4512 | isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type); |
| 4513 | if (isinstance == -1) { |
| 4514 | return 1; |
| 4515 | } |
| 4516 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4517 | |
| 4518 | *out = Pass(lineno, col_offset, arena); |
| 4519 | if (*out == NULL) goto failed; |
| 4520 | return 0; |
| 4521 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 4522 | isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type); |
| 4523 | if (isinstance == -1) { |
| 4524 | return 1; |
| 4525 | } |
| 4526 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4527 | |
| 4528 | *out = Break(lineno, col_offset, arena); |
| 4529 | if (*out == NULL) goto failed; |
| 4530 | return 0; |
| 4531 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 4532 | isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type); |
| 4533 | if (isinstance == -1) { |
| 4534 | return 1; |
| 4535 | } |
| 4536 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4537 | |
| 4538 | *out = Continue(lineno, col_offset, arena); |
| 4539 | if (*out == NULL) goto failed; |
| 4540 | return 0; |
| 4541 | } |
| 4542 | |
| 4543 | tmp = PyObject_Repr(obj); |
| 4544 | if (tmp == NULL) goto failed; |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 4545 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %.400s", PyString_AS_STRING(tmp)); |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4546 | failed: |
| 4547 | Py_XDECREF(tmp); |
| 4548 | return 1; |
| 4549 | } |
| 4550 | |
| 4551 | int |
| 4552 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 4553 | { |
| 4554 | PyObject* tmp = NULL; |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 4555 | int isinstance; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4556 | |
| 4557 | int lineno; |
| 4558 | int col_offset; |
| 4559 | |
| 4560 | if (obj == Py_None) { |
| 4561 | *out = NULL; |
| 4562 | return 0; |
| 4563 | } |
| 4564 | if (PyObject_HasAttrString(obj, "lineno")) { |
| 4565 | int res; |
| 4566 | tmp = PyObject_GetAttrString(obj, "lineno"); |
| 4567 | if (tmp == NULL) goto failed; |
| 4568 | res = obj2ast_int(tmp, &lineno, arena); |
| 4569 | if (res != 0) goto failed; |
| 4570 | Py_XDECREF(tmp); |
| 4571 | tmp = NULL; |
| 4572 | } else { |
| 4573 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 4574 | return 1; |
| 4575 | } |
| 4576 | if (PyObject_HasAttrString(obj, "col_offset")) { |
| 4577 | int res; |
| 4578 | tmp = PyObject_GetAttrString(obj, "col_offset"); |
| 4579 | if (tmp == NULL) goto failed; |
| 4580 | res = obj2ast_int(tmp, &col_offset, arena); |
| 4581 | if (res != 0) goto failed; |
| 4582 | Py_XDECREF(tmp); |
| 4583 | tmp = NULL; |
| 4584 | } else { |
| 4585 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 4586 | return 1; |
| 4587 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 4588 | isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type); |
| 4589 | if (isinstance == -1) { |
| 4590 | return 1; |
| 4591 | } |
| 4592 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4593 | boolop_ty op; |
| 4594 | asdl_seq* values; |
| 4595 | |
| 4596 | if (PyObject_HasAttrString(obj, "op")) { |
| 4597 | int res; |
| 4598 | tmp = PyObject_GetAttrString(obj, "op"); |
| 4599 | if (tmp == NULL) goto failed; |
| 4600 | res = obj2ast_boolop(tmp, &op, arena); |
| 4601 | if (res != 0) goto failed; |
| 4602 | Py_XDECREF(tmp); |
| 4603 | tmp = NULL; |
| 4604 | } else { |
| 4605 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 4606 | return 1; |
| 4607 | } |
| 4608 | if (PyObject_HasAttrString(obj, "values")) { |
| 4609 | int res; |
| 4610 | Py_ssize_t len; |
| 4611 | Py_ssize_t i; |
| 4612 | tmp = PyObject_GetAttrString(obj, "values"); |
| 4613 | if (tmp == NULL) goto failed; |
| 4614 | if (!PyList_Check(tmp)) { |
| 4615 | PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4616 | goto failed; |
| 4617 | } |
| 4618 | len = PyList_GET_SIZE(tmp); |
| 4619 | values = asdl_seq_new(len, arena); |
| 4620 | if (values == NULL) goto failed; |
| 4621 | for (i = 0; i < len; i++) { |
| 4622 | expr_ty value; |
| 4623 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4624 | if (res != 0) goto failed; |
| 4625 | asdl_seq_SET(values, i, value); |
| 4626 | } |
| 4627 | Py_XDECREF(tmp); |
| 4628 | tmp = NULL; |
| 4629 | } else { |
| 4630 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 4631 | return 1; |
| 4632 | } |
| 4633 | *out = BoolOp(op, values, lineno, col_offset, arena); |
| 4634 | if (*out == NULL) goto failed; |
| 4635 | return 0; |
| 4636 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 4637 | isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type); |
| 4638 | if (isinstance == -1) { |
| 4639 | return 1; |
| 4640 | } |
| 4641 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4642 | expr_ty left; |
| 4643 | operator_ty op; |
| 4644 | expr_ty right; |
| 4645 | |
| 4646 | if (PyObject_HasAttrString(obj, "left")) { |
| 4647 | int res; |
| 4648 | tmp = PyObject_GetAttrString(obj, "left"); |
| 4649 | if (tmp == NULL) goto failed; |
| 4650 | res = obj2ast_expr(tmp, &left, arena); |
| 4651 | if (res != 0) goto failed; |
| 4652 | Py_XDECREF(tmp); |
| 4653 | tmp = NULL; |
| 4654 | } else { |
| 4655 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 4656 | return 1; |
| 4657 | } |
| 4658 | if (PyObject_HasAttrString(obj, "op")) { |
| 4659 | int res; |
| 4660 | tmp = PyObject_GetAttrString(obj, "op"); |
| 4661 | if (tmp == NULL) goto failed; |
| 4662 | res = obj2ast_operator(tmp, &op, arena); |
| 4663 | if (res != 0) goto failed; |
| 4664 | Py_XDECREF(tmp); |
| 4665 | tmp = NULL; |
| 4666 | } else { |
| 4667 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 4668 | return 1; |
| 4669 | } |
| 4670 | if (PyObject_HasAttrString(obj, "right")) { |
| 4671 | int res; |
| 4672 | tmp = PyObject_GetAttrString(obj, "right"); |
| 4673 | if (tmp == NULL) goto failed; |
| 4674 | res = obj2ast_expr(tmp, &right, arena); |
| 4675 | if (res != 0) goto failed; |
| 4676 | Py_XDECREF(tmp); |
| 4677 | tmp = NULL; |
| 4678 | } else { |
| 4679 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 4680 | return 1; |
| 4681 | } |
| 4682 | *out = BinOp(left, op, right, lineno, col_offset, arena); |
| 4683 | if (*out == NULL) goto failed; |
| 4684 | return 0; |
| 4685 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 4686 | isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type); |
| 4687 | if (isinstance == -1) { |
| 4688 | return 1; |
| 4689 | } |
| 4690 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4691 | unaryop_ty op; |
| 4692 | expr_ty operand; |
| 4693 | |
| 4694 | if (PyObject_HasAttrString(obj, "op")) { |
| 4695 | int res; |
| 4696 | tmp = PyObject_GetAttrString(obj, "op"); |
| 4697 | if (tmp == NULL) goto failed; |
| 4698 | res = obj2ast_unaryop(tmp, &op, arena); |
| 4699 | if (res != 0) goto failed; |
| 4700 | Py_XDECREF(tmp); |
| 4701 | tmp = NULL; |
| 4702 | } else { |
| 4703 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 4704 | return 1; |
| 4705 | } |
| 4706 | if (PyObject_HasAttrString(obj, "operand")) { |
| 4707 | int res; |
| 4708 | tmp = PyObject_GetAttrString(obj, "operand"); |
| 4709 | if (tmp == NULL) goto failed; |
| 4710 | res = obj2ast_expr(tmp, &operand, arena); |
| 4711 | if (res != 0) goto failed; |
| 4712 | Py_XDECREF(tmp); |
| 4713 | tmp = NULL; |
| 4714 | } else { |
| 4715 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 4716 | return 1; |
| 4717 | } |
| 4718 | *out = UnaryOp(op, operand, lineno, col_offset, arena); |
| 4719 | if (*out == NULL) goto failed; |
| 4720 | return 0; |
| 4721 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 4722 | isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type); |
| 4723 | if (isinstance == -1) { |
| 4724 | return 1; |
| 4725 | } |
| 4726 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4727 | arguments_ty args; |
| 4728 | expr_ty body; |
| 4729 | |
| 4730 | if (PyObject_HasAttrString(obj, "args")) { |
| 4731 | int res; |
| 4732 | tmp = PyObject_GetAttrString(obj, "args"); |
| 4733 | if (tmp == NULL) goto failed; |
| 4734 | res = obj2ast_arguments(tmp, &args, arena); |
| 4735 | if (res != 0) goto failed; |
| 4736 | Py_XDECREF(tmp); |
| 4737 | tmp = NULL; |
| 4738 | } else { |
| 4739 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 4740 | return 1; |
| 4741 | } |
| 4742 | if (PyObject_HasAttrString(obj, "body")) { |
| 4743 | int res; |
| 4744 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4745 | if (tmp == NULL) goto failed; |
| 4746 | res = obj2ast_expr(tmp, &body, arena); |
| 4747 | if (res != 0) goto failed; |
| 4748 | Py_XDECREF(tmp); |
| 4749 | tmp = NULL; |
| 4750 | } else { |
| 4751 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 4752 | return 1; |
| 4753 | } |
| 4754 | *out = Lambda(args, body, lineno, col_offset, arena); |
| 4755 | if (*out == NULL) goto failed; |
| 4756 | return 0; |
| 4757 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 4758 | isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type); |
| 4759 | if (isinstance == -1) { |
| 4760 | return 1; |
| 4761 | } |
| 4762 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4763 | expr_ty test; |
| 4764 | expr_ty body; |
| 4765 | expr_ty orelse; |
| 4766 | |
| 4767 | if (PyObject_HasAttrString(obj, "test")) { |
| 4768 | int res; |
| 4769 | tmp = PyObject_GetAttrString(obj, "test"); |
| 4770 | if (tmp == NULL) goto failed; |
| 4771 | res = obj2ast_expr(tmp, &test, arena); |
| 4772 | if (res != 0) goto failed; |
| 4773 | Py_XDECREF(tmp); |
| 4774 | tmp = NULL; |
| 4775 | } else { |
| 4776 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 4777 | return 1; |
| 4778 | } |
| 4779 | if (PyObject_HasAttrString(obj, "body")) { |
| 4780 | int res; |
| 4781 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4782 | if (tmp == NULL) goto failed; |
| 4783 | res = obj2ast_expr(tmp, &body, arena); |
| 4784 | if (res != 0) goto failed; |
| 4785 | Py_XDECREF(tmp); |
| 4786 | tmp = NULL; |
| 4787 | } else { |
| 4788 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 4789 | return 1; |
| 4790 | } |
| 4791 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4792 | int res; |
| 4793 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4794 | if (tmp == NULL) goto failed; |
| 4795 | res = obj2ast_expr(tmp, &orelse, arena); |
| 4796 | if (res != 0) goto failed; |
| 4797 | Py_XDECREF(tmp); |
| 4798 | tmp = NULL; |
| 4799 | } else { |
| 4800 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 4801 | return 1; |
| 4802 | } |
| 4803 | *out = IfExp(test, body, orelse, lineno, col_offset, arena); |
| 4804 | if (*out == NULL) goto failed; |
| 4805 | return 0; |
| 4806 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 4807 | isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type); |
| 4808 | if (isinstance == -1) { |
| 4809 | return 1; |
| 4810 | } |
| 4811 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4812 | asdl_seq* keys; |
| 4813 | asdl_seq* values; |
| 4814 | |
| 4815 | if (PyObject_HasAttrString(obj, "keys")) { |
| 4816 | int res; |
| 4817 | Py_ssize_t len; |
| 4818 | Py_ssize_t i; |
| 4819 | tmp = PyObject_GetAttrString(obj, "keys"); |
| 4820 | if (tmp == NULL) goto failed; |
| 4821 | if (!PyList_Check(tmp)) { |
| 4822 | PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4823 | goto failed; |
| 4824 | } |
| 4825 | len = PyList_GET_SIZE(tmp); |
| 4826 | keys = asdl_seq_new(len, arena); |
| 4827 | if (keys == NULL) goto failed; |
| 4828 | for (i = 0; i < len; i++) { |
| 4829 | expr_ty value; |
| 4830 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4831 | if (res != 0) goto failed; |
| 4832 | asdl_seq_SET(keys, i, value); |
| 4833 | } |
| 4834 | Py_XDECREF(tmp); |
| 4835 | tmp = NULL; |
| 4836 | } else { |
| 4837 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 4838 | return 1; |
| 4839 | } |
| 4840 | if (PyObject_HasAttrString(obj, "values")) { |
| 4841 | int res; |
| 4842 | Py_ssize_t len; |
| 4843 | Py_ssize_t i; |
| 4844 | tmp = PyObject_GetAttrString(obj, "values"); |
| 4845 | if (tmp == NULL) goto failed; |
| 4846 | if (!PyList_Check(tmp)) { |
| 4847 | PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4848 | goto failed; |
| 4849 | } |
| 4850 | len = PyList_GET_SIZE(tmp); |
| 4851 | values = asdl_seq_new(len, arena); |
| 4852 | if (values == NULL) goto failed; |
| 4853 | for (i = 0; i < len; i++) { |
| 4854 | expr_ty value; |
| 4855 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4856 | if (res != 0) goto failed; |
| 4857 | asdl_seq_SET(values, i, value); |
| 4858 | } |
| 4859 | Py_XDECREF(tmp); |
| 4860 | tmp = NULL; |
| 4861 | } else { |
| 4862 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 4863 | return 1; |
| 4864 | } |
| 4865 | *out = Dict(keys, values, lineno, col_offset, arena); |
| 4866 | if (*out == NULL) goto failed; |
| 4867 | return 0; |
| 4868 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 4869 | isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type); |
| 4870 | if (isinstance == -1) { |
| 4871 | return 1; |
| 4872 | } |
| 4873 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4874 | expr_ty elt; |
| 4875 | asdl_seq* generators; |
| 4876 | |
| 4877 | if (PyObject_HasAttrString(obj, "elt")) { |
| 4878 | int res; |
| 4879 | tmp = PyObject_GetAttrString(obj, "elt"); |
| 4880 | if (tmp == NULL) goto failed; |
| 4881 | res = obj2ast_expr(tmp, &elt, arena); |
| 4882 | if (res != 0) goto failed; |
| 4883 | Py_XDECREF(tmp); |
| 4884 | tmp = NULL; |
| 4885 | } else { |
| 4886 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 4887 | return 1; |
| 4888 | } |
| 4889 | if (PyObject_HasAttrString(obj, "generators")) { |
| 4890 | int res; |
| 4891 | Py_ssize_t len; |
| 4892 | Py_ssize_t i; |
| 4893 | tmp = PyObject_GetAttrString(obj, "generators"); |
| 4894 | if (tmp == NULL) goto failed; |
| 4895 | if (!PyList_Check(tmp)) { |
| 4896 | PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4897 | goto failed; |
| 4898 | } |
| 4899 | len = PyList_GET_SIZE(tmp); |
| 4900 | generators = asdl_seq_new(len, arena); |
| 4901 | if (generators == NULL) goto failed; |
| 4902 | for (i = 0; i < len; i++) { |
| 4903 | comprehension_ty value; |
| 4904 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4905 | if (res != 0) goto failed; |
| 4906 | asdl_seq_SET(generators, i, value); |
| 4907 | } |
| 4908 | Py_XDECREF(tmp); |
| 4909 | tmp = NULL; |
| 4910 | } else { |
| 4911 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 4912 | return 1; |
| 4913 | } |
| 4914 | *out = ListComp(elt, generators, lineno, col_offset, arena); |
| 4915 | if (*out == NULL) goto failed; |
| 4916 | return 0; |
| 4917 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 4918 | isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type); |
| 4919 | if (isinstance == -1) { |
| 4920 | return 1; |
| 4921 | } |
| 4922 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4923 | expr_ty elt; |
| 4924 | asdl_seq* generators; |
| 4925 | |
| 4926 | if (PyObject_HasAttrString(obj, "elt")) { |
| 4927 | int res; |
| 4928 | tmp = PyObject_GetAttrString(obj, "elt"); |
| 4929 | if (tmp == NULL) goto failed; |
| 4930 | res = obj2ast_expr(tmp, &elt, arena); |
| 4931 | if (res != 0) goto failed; |
| 4932 | Py_XDECREF(tmp); |
| 4933 | tmp = NULL; |
| 4934 | } else { |
| 4935 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 4936 | return 1; |
| 4937 | } |
| 4938 | if (PyObject_HasAttrString(obj, "generators")) { |
| 4939 | int res; |
| 4940 | Py_ssize_t len; |
| 4941 | Py_ssize_t i; |
| 4942 | tmp = PyObject_GetAttrString(obj, "generators"); |
| 4943 | if (tmp == NULL) goto failed; |
| 4944 | if (!PyList_Check(tmp)) { |
| 4945 | PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4946 | goto failed; |
| 4947 | } |
| 4948 | len = PyList_GET_SIZE(tmp); |
| 4949 | generators = asdl_seq_new(len, arena); |
| 4950 | if (generators == NULL) goto failed; |
| 4951 | for (i = 0; i < len; i++) { |
| 4952 | comprehension_ty value; |
| 4953 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4954 | if (res != 0) goto failed; |
| 4955 | asdl_seq_SET(generators, i, value); |
| 4956 | } |
| 4957 | Py_XDECREF(tmp); |
| 4958 | tmp = NULL; |
| 4959 | } else { |
| 4960 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 4961 | return 1; |
| 4962 | } |
| 4963 | *out = GeneratorExp(elt, generators, lineno, col_offset, arena); |
| 4964 | if (*out == NULL) goto failed; |
| 4965 | return 0; |
| 4966 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 4967 | isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); |
| 4968 | if (isinstance == -1) { |
| 4969 | return 1; |
| 4970 | } |
| 4971 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4972 | expr_ty value; |
| 4973 | |
| 4974 | if (PyObject_HasAttrString(obj, "value")) { |
| 4975 | int res; |
| 4976 | tmp = PyObject_GetAttrString(obj, "value"); |
| 4977 | if (tmp == NULL) goto failed; |
| 4978 | res = obj2ast_expr(tmp, &value, arena); |
| 4979 | if (res != 0) goto failed; |
| 4980 | Py_XDECREF(tmp); |
| 4981 | tmp = NULL; |
| 4982 | } else { |
| 4983 | value = NULL; |
| 4984 | } |
| 4985 | *out = Yield(value, lineno, col_offset, arena); |
| 4986 | if (*out == NULL) goto failed; |
| 4987 | return 0; |
| 4988 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 4989 | isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); |
| 4990 | if (isinstance == -1) { |
| 4991 | return 1; |
| 4992 | } |
| 4993 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4994 | expr_ty left; |
| 4995 | asdl_int_seq* ops; |
| 4996 | asdl_seq* comparators; |
| 4997 | |
| 4998 | if (PyObject_HasAttrString(obj, "left")) { |
| 4999 | int res; |
| 5000 | tmp = PyObject_GetAttrString(obj, "left"); |
| 5001 | if (tmp == NULL) goto failed; |
| 5002 | res = obj2ast_expr(tmp, &left, arena); |
| 5003 | if (res != 0) goto failed; |
| 5004 | Py_XDECREF(tmp); |
| 5005 | tmp = NULL; |
| 5006 | } else { |
| 5007 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 5008 | return 1; |
| 5009 | } |
| 5010 | if (PyObject_HasAttrString(obj, "ops")) { |
| 5011 | int res; |
| 5012 | Py_ssize_t len; |
| 5013 | Py_ssize_t i; |
| 5014 | tmp = PyObject_GetAttrString(obj, "ops"); |
| 5015 | if (tmp == NULL) goto failed; |
| 5016 | if (!PyList_Check(tmp)) { |
| 5017 | PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5018 | goto failed; |
| 5019 | } |
| 5020 | len = PyList_GET_SIZE(tmp); |
| 5021 | ops = asdl_int_seq_new(len, arena); |
| 5022 | if (ops == NULL) goto failed; |
| 5023 | for (i = 0; i < len; i++) { |
| 5024 | cmpop_ty value; |
| 5025 | res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5026 | if (res != 0) goto failed; |
| 5027 | asdl_seq_SET(ops, i, value); |
| 5028 | } |
| 5029 | Py_XDECREF(tmp); |
| 5030 | tmp = NULL; |
| 5031 | } else { |
| 5032 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 5033 | return 1; |
| 5034 | } |
| 5035 | if (PyObject_HasAttrString(obj, "comparators")) { |
| 5036 | int res; |
| 5037 | Py_ssize_t len; |
| 5038 | Py_ssize_t i; |
| 5039 | tmp = PyObject_GetAttrString(obj, "comparators"); |
| 5040 | if (tmp == NULL) goto failed; |
| 5041 | if (!PyList_Check(tmp)) { |
| 5042 | PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5043 | goto failed; |
| 5044 | } |
| 5045 | len = PyList_GET_SIZE(tmp); |
| 5046 | comparators = asdl_seq_new(len, arena); |
| 5047 | if (comparators == NULL) goto failed; |
| 5048 | for (i = 0; i < len; i++) { |
| 5049 | expr_ty value; |
| 5050 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5051 | if (res != 0) goto failed; |
| 5052 | asdl_seq_SET(comparators, i, value); |
| 5053 | } |
| 5054 | Py_XDECREF(tmp); |
| 5055 | tmp = NULL; |
| 5056 | } else { |
| 5057 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 5058 | return 1; |
| 5059 | } |
| 5060 | *out = Compare(left, ops, comparators, lineno, col_offset, |
| 5061 | arena); |
| 5062 | if (*out == NULL) goto failed; |
| 5063 | return 0; |
| 5064 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5065 | isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type); |
| 5066 | if (isinstance == -1) { |
| 5067 | return 1; |
| 5068 | } |
| 5069 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5070 | expr_ty func; |
| 5071 | asdl_seq* args; |
| 5072 | asdl_seq* keywords; |
| 5073 | expr_ty starargs; |
| 5074 | expr_ty kwargs; |
| 5075 | |
| 5076 | if (PyObject_HasAttrString(obj, "func")) { |
| 5077 | int res; |
| 5078 | tmp = PyObject_GetAttrString(obj, "func"); |
| 5079 | if (tmp == NULL) goto failed; |
| 5080 | res = obj2ast_expr(tmp, &func, arena); |
| 5081 | if (res != 0) goto failed; |
| 5082 | Py_XDECREF(tmp); |
| 5083 | tmp = NULL; |
| 5084 | } else { |
| 5085 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 5086 | return 1; |
| 5087 | } |
| 5088 | if (PyObject_HasAttrString(obj, "args")) { |
| 5089 | int res; |
| 5090 | Py_ssize_t len; |
| 5091 | Py_ssize_t i; |
| 5092 | tmp = PyObject_GetAttrString(obj, "args"); |
| 5093 | if (tmp == NULL) goto failed; |
| 5094 | if (!PyList_Check(tmp)) { |
| 5095 | PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5096 | goto failed; |
| 5097 | } |
| 5098 | len = PyList_GET_SIZE(tmp); |
| 5099 | args = asdl_seq_new(len, arena); |
| 5100 | if (args == NULL) goto failed; |
| 5101 | for (i = 0; i < len; i++) { |
| 5102 | expr_ty value; |
| 5103 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5104 | if (res != 0) goto failed; |
| 5105 | asdl_seq_SET(args, i, value); |
| 5106 | } |
| 5107 | Py_XDECREF(tmp); |
| 5108 | tmp = NULL; |
| 5109 | } else { |
| 5110 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 5111 | return 1; |
| 5112 | } |
| 5113 | if (PyObject_HasAttrString(obj, "keywords")) { |
| 5114 | int res; |
| 5115 | Py_ssize_t len; |
| 5116 | Py_ssize_t i; |
| 5117 | tmp = PyObject_GetAttrString(obj, "keywords"); |
| 5118 | if (tmp == NULL) goto failed; |
| 5119 | if (!PyList_Check(tmp)) { |
| 5120 | PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5121 | goto failed; |
| 5122 | } |
| 5123 | len = PyList_GET_SIZE(tmp); |
| 5124 | keywords = asdl_seq_new(len, arena); |
| 5125 | if (keywords == NULL) goto failed; |
| 5126 | for (i = 0; i < len; i++) { |
| 5127 | keyword_ty value; |
| 5128 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5129 | if (res != 0) goto failed; |
| 5130 | asdl_seq_SET(keywords, i, value); |
| 5131 | } |
| 5132 | Py_XDECREF(tmp); |
| 5133 | tmp = NULL; |
| 5134 | } else { |
| 5135 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 5136 | return 1; |
| 5137 | } |
| 5138 | if (PyObject_HasAttrString(obj, "starargs")) { |
| 5139 | int res; |
| 5140 | tmp = PyObject_GetAttrString(obj, "starargs"); |
| 5141 | if (tmp == NULL) goto failed; |
| 5142 | res = obj2ast_expr(tmp, &starargs, arena); |
| 5143 | if (res != 0) goto failed; |
| 5144 | Py_XDECREF(tmp); |
| 5145 | tmp = NULL; |
| 5146 | } else { |
| 5147 | starargs = NULL; |
| 5148 | } |
| 5149 | if (PyObject_HasAttrString(obj, "kwargs")) { |
| 5150 | int res; |
| 5151 | tmp = PyObject_GetAttrString(obj, "kwargs"); |
| 5152 | if (tmp == NULL) goto failed; |
| 5153 | res = obj2ast_expr(tmp, &kwargs, arena); |
| 5154 | if (res != 0) goto failed; |
| 5155 | Py_XDECREF(tmp); |
| 5156 | tmp = NULL; |
| 5157 | } else { |
| 5158 | kwargs = NULL; |
| 5159 | } |
| 5160 | *out = Call(func, args, keywords, starargs, kwargs, lineno, |
| 5161 | col_offset, arena); |
| 5162 | if (*out == NULL) goto failed; |
| 5163 | return 0; |
| 5164 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5165 | isinstance = PyObject_IsInstance(obj, (PyObject*)Repr_type); |
| 5166 | if (isinstance == -1) { |
| 5167 | return 1; |
| 5168 | } |
| 5169 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5170 | expr_ty value; |
| 5171 | |
| 5172 | if (PyObject_HasAttrString(obj, "value")) { |
| 5173 | int res; |
| 5174 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5175 | if (tmp == NULL) goto failed; |
| 5176 | res = obj2ast_expr(tmp, &value, arena); |
| 5177 | if (res != 0) goto failed; |
| 5178 | Py_XDECREF(tmp); |
| 5179 | tmp = NULL; |
| 5180 | } else { |
| 5181 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Repr"); |
| 5182 | return 1; |
| 5183 | } |
| 5184 | *out = Repr(value, lineno, col_offset, arena); |
| 5185 | if (*out == NULL) goto failed; |
| 5186 | return 0; |
| 5187 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5188 | isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type); |
| 5189 | if (isinstance == -1) { |
| 5190 | return 1; |
| 5191 | } |
| 5192 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5193 | object n; |
| 5194 | |
| 5195 | if (PyObject_HasAttrString(obj, "n")) { |
| 5196 | int res; |
| 5197 | tmp = PyObject_GetAttrString(obj, "n"); |
| 5198 | if (tmp == NULL) goto failed; |
| 5199 | res = obj2ast_object(tmp, &n, arena); |
| 5200 | if (res != 0) goto failed; |
| 5201 | Py_XDECREF(tmp); |
| 5202 | tmp = NULL; |
| 5203 | } else { |
| 5204 | PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num"); |
| 5205 | return 1; |
| 5206 | } |
| 5207 | *out = Num(n, lineno, col_offset, arena); |
| 5208 | if (*out == NULL) goto failed; |
| 5209 | return 0; |
| 5210 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5211 | isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type); |
| 5212 | if (isinstance == -1) { |
| 5213 | return 1; |
| 5214 | } |
| 5215 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5216 | string s; |
| 5217 | |
| 5218 | if (PyObject_HasAttrString(obj, "s")) { |
| 5219 | int res; |
| 5220 | tmp = PyObject_GetAttrString(obj, "s"); |
| 5221 | if (tmp == NULL) goto failed; |
| 5222 | res = obj2ast_string(tmp, &s, arena); |
| 5223 | if (res != 0) goto failed; |
| 5224 | Py_XDECREF(tmp); |
| 5225 | tmp = NULL; |
| 5226 | } else { |
| 5227 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str"); |
| 5228 | return 1; |
| 5229 | } |
| 5230 | *out = Str(s, lineno, col_offset, arena); |
| 5231 | if (*out == NULL) goto failed; |
| 5232 | return 0; |
| 5233 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5234 | isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type); |
| 5235 | if (isinstance == -1) { |
| 5236 | return 1; |
| 5237 | } |
| 5238 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5239 | expr_ty value; |
| 5240 | identifier attr; |
| 5241 | expr_context_ty ctx; |
| 5242 | |
| 5243 | if (PyObject_HasAttrString(obj, "value")) { |
| 5244 | int res; |
| 5245 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5246 | if (tmp == NULL) goto failed; |
| 5247 | res = obj2ast_expr(tmp, &value, arena); |
| 5248 | if (res != 0) goto failed; |
| 5249 | Py_XDECREF(tmp); |
| 5250 | tmp = NULL; |
| 5251 | } else { |
| 5252 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 5253 | return 1; |
| 5254 | } |
| 5255 | if (PyObject_HasAttrString(obj, "attr")) { |
| 5256 | int res; |
| 5257 | tmp = PyObject_GetAttrString(obj, "attr"); |
| 5258 | if (tmp == NULL) goto failed; |
| 5259 | res = obj2ast_identifier(tmp, &attr, arena); |
| 5260 | if (res != 0) goto failed; |
| 5261 | Py_XDECREF(tmp); |
| 5262 | tmp = NULL; |
| 5263 | } else { |
| 5264 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 5265 | return 1; |
| 5266 | } |
| 5267 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5268 | int res; |
| 5269 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5270 | if (tmp == NULL) goto failed; |
| 5271 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5272 | if (res != 0) goto failed; |
| 5273 | Py_XDECREF(tmp); |
| 5274 | tmp = NULL; |
| 5275 | } else { |
| 5276 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 5277 | return 1; |
| 5278 | } |
| 5279 | *out = Attribute(value, attr, ctx, lineno, col_offset, arena); |
| 5280 | if (*out == NULL) goto failed; |
| 5281 | return 0; |
| 5282 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5283 | isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type); |
| 5284 | if (isinstance == -1) { |
| 5285 | return 1; |
| 5286 | } |
| 5287 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5288 | expr_ty value; |
| 5289 | slice_ty slice; |
| 5290 | expr_context_ty ctx; |
| 5291 | |
| 5292 | if (PyObject_HasAttrString(obj, "value")) { |
| 5293 | int res; |
| 5294 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5295 | if (tmp == NULL) goto failed; |
| 5296 | res = obj2ast_expr(tmp, &value, arena); |
| 5297 | if (res != 0) goto failed; |
| 5298 | Py_XDECREF(tmp); |
| 5299 | tmp = NULL; |
| 5300 | } else { |
| 5301 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 5302 | return 1; |
| 5303 | } |
| 5304 | if (PyObject_HasAttrString(obj, "slice")) { |
| 5305 | int res; |
| 5306 | tmp = PyObject_GetAttrString(obj, "slice"); |
| 5307 | if (tmp == NULL) goto failed; |
| 5308 | res = obj2ast_slice(tmp, &slice, arena); |
| 5309 | if (res != 0) goto failed; |
| 5310 | Py_XDECREF(tmp); |
| 5311 | tmp = NULL; |
| 5312 | } else { |
| 5313 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 5314 | return 1; |
| 5315 | } |
| 5316 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5317 | int res; |
| 5318 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5319 | if (tmp == NULL) goto failed; |
| 5320 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5321 | if (res != 0) goto failed; |
| 5322 | Py_XDECREF(tmp); |
| 5323 | tmp = NULL; |
| 5324 | } else { |
| 5325 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 5326 | return 1; |
| 5327 | } |
| 5328 | *out = Subscript(value, slice, ctx, lineno, col_offset, arena); |
| 5329 | if (*out == NULL) goto failed; |
| 5330 | return 0; |
| 5331 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5332 | isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type); |
| 5333 | if (isinstance == -1) { |
| 5334 | return 1; |
| 5335 | } |
| 5336 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5337 | identifier id; |
| 5338 | expr_context_ty ctx; |
| 5339 | |
| 5340 | if (PyObject_HasAttrString(obj, "id")) { |
| 5341 | int res; |
| 5342 | tmp = PyObject_GetAttrString(obj, "id"); |
| 5343 | if (tmp == NULL) goto failed; |
| 5344 | res = obj2ast_identifier(tmp, &id, arena); |
| 5345 | if (res != 0) goto failed; |
| 5346 | Py_XDECREF(tmp); |
| 5347 | tmp = NULL; |
| 5348 | } else { |
| 5349 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 5350 | return 1; |
| 5351 | } |
| 5352 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5353 | int res; |
| 5354 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5355 | if (tmp == NULL) goto failed; |
| 5356 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5357 | if (res != 0) goto failed; |
| 5358 | Py_XDECREF(tmp); |
| 5359 | tmp = NULL; |
| 5360 | } else { |
| 5361 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 5362 | return 1; |
| 5363 | } |
| 5364 | *out = Name(id, ctx, lineno, col_offset, arena); |
| 5365 | if (*out == NULL) goto failed; |
| 5366 | return 0; |
| 5367 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5368 | isinstance = PyObject_IsInstance(obj, (PyObject*)List_type); |
| 5369 | if (isinstance == -1) { |
| 5370 | return 1; |
| 5371 | } |
| 5372 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5373 | asdl_seq* elts; |
| 5374 | expr_context_ty ctx; |
| 5375 | |
| 5376 | if (PyObject_HasAttrString(obj, "elts")) { |
| 5377 | int res; |
| 5378 | Py_ssize_t len; |
| 5379 | Py_ssize_t i; |
| 5380 | tmp = PyObject_GetAttrString(obj, "elts"); |
| 5381 | if (tmp == NULL) goto failed; |
| 5382 | if (!PyList_Check(tmp)) { |
| 5383 | PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5384 | goto failed; |
| 5385 | } |
| 5386 | len = PyList_GET_SIZE(tmp); |
| 5387 | elts = asdl_seq_new(len, arena); |
| 5388 | if (elts == NULL) goto failed; |
| 5389 | for (i = 0; i < len; i++) { |
| 5390 | expr_ty value; |
| 5391 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5392 | if (res != 0) goto failed; |
| 5393 | asdl_seq_SET(elts, i, value); |
| 5394 | } |
| 5395 | Py_XDECREF(tmp); |
| 5396 | tmp = NULL; |
| 5397 | } else { |
| 5398 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 5399 | return 1; |
| 5400 | } |
| 5401 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5402 | int res; |
| 5403 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5404 | if (tmp == NULL) goto failed; |
| 5405 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5406 | if (res != 0) goto failed; |
| 5407 | Py_XDECREF(tmp); |
| 5408 | tmp = NULL; |
| 5409 | } else { |
| 5410 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 5411 | return 1; |
| 5412 | } |
| 5413 | *out = List(elts, ctx, lineno, col_offset, arena); |
| 5414 | if (*out == NULL) goto failed; |
| 5415 | return 0; |
| 5416 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5417 | isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type); |
| 5418 | if (isinstance == -1) { |
| 5419 | return 1; |
| 5420 | } |
| 5421 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5422 | asdl_seq* elts; |
| 5423 | expr_context_ty ctx; |
| 5424 | |
| 5425 | if (PyObject_HasAttrString(obj, "elts")) { |
| 5426 | int res; |
| 5427 | Py_ssize_t len; |
| 5428 | Py_ssize_t i; |
| 5429 | tmp = PyObject_GetAttrString(obj, "elts"); |
| 5430 | if (tmp == NULL) goto failed; |
| 5431 | if (!PyList_Check(tmp)) { |
| 5432 | PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5433 | goto failed; |
| 5434 | } |
| 5435 | len = PyList_GET_SIZE(tmp); |
| 5436 | elts = asdl_seq_new(len, arena); |
| 5437 | if (elts == NULL) goto failed; |
| 5438 | for (i = 0; i < len; i++) { |
| 5439 | expr_ty value; |
| 5440 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5441 | if (res != 0) goto failed; |
| 5442 | asdl_seq_SET(elts, i, value); |
| 5443 | } |
| 5444 | Py_XDECREF(tmp); |
| 5445 | tmp = NULL; |
| 5446 | } else { |
| 5447 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 5448 | return 1; |
| 5449 | } |
| 5450 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5451 | int res; |
| 5452 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5453 | if (tmp == NULL) goto failed; |
| 5454 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5455 | if (res != 0) goto failed; |
| 5456 | Py_XDECREF(tmp); |
| 5457 | tmp = NULL; |
| 5458 | } else { |
| 5459 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 5460 | return 1; |
| 5461 | } |
| 5462 | *out = Tuple(elts, ctx, lineno, col_offset, arena); |
| 5463 | if (*out == NULL) goto failed; |
| 5464 | return 0; |
| 5465 | } |
| 5466 | |
| 5467 | tmp = PyObject_Repr(obj); |
| 5468 | if (tmp == NULL) goto failed; |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 5469 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %.400s", PyString_AS_STRING(tmp)); |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5470 | failed: |
| 5471 | Py_XDECREF(tmp); |
| 5472 | return 1; |
| 5473 | } |
| 5474 | |
| 5475 | int |
| 5476 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 5477 | { |
| 5478 | PyObject* tmp = NULL; |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5479 | int isinstance; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5480 | |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5481 | isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); |
| 5482 | if (isinstance == -1) { |
| 5483 | return 1; |
| 5484 | } |
| 5485 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5486 | *out = Load; |
| 5487 | return 0; |
| 5488 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5489 | isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type); |
| 5490 | if (isinstance == -1) { |
| 5491 | return 1; |
| 5492 | } |
| 5493 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5494 | *out = Store; |
| 5495 | return 0; |
| 5496 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5497 | isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type); |
| 5498 | if (isinstance == -1) { |
| 5499 | return 1; |
| 5500 | } |
| 5501 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5502 | *out = Del; |
| 5503 | return 0; |
| 5504 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5505 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type); |
| 5506 | if (isinstance == -1) { |
| 5507 | return 1; |
| 5508 | } |
| 5509 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5510 | *out = AugLoad; |
| 5511 | return 0; |
| 5512 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5513 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type); |
| 5514 | if (isinstance == -1) { |
| 5515 | return 1; |
| 5516 | } |
| 5517 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5518 | *out = AugStore; |
| 5519 | return 0; |
| 5520 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5521 | isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type); |
| 5522 | if (isinstance == -1) { |
| 5523 | return 1; |
| 5524 | } |
| 5525 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5526 | *out = Param; |
| 5527 | return 0; |
| 5528 | } |
| 5529 | |
| 5530 | tmp = PyObject_Repr(obj); |
| 5531 | if (tmp == NULL) goto failed; |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 5532 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %.400s", PyString_AS_STRING(tmp)); |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5533 | failed: |
| 5534 | Py_XDECREF(tmp); |
| 5535 | return 1; |
| 5536 | } |
| 5537 | |
| 5538 | int |
| 5539 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
| 5540 | { |
| 5541 | PyObject* tmp = NULL; |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5542 | int isinstance; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5543 | |
| 5544 | |
| 5545 | if (obj == Py_None) { |
| 5546 | *out = NULL; |
| 5547 | return 0; |
| 5548 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5549 | isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type); |
| 5550 | if (isinstance == -1) { |
| 5551 | return 1; |
| 5552 | } |
| 5553 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5554 | |
| 5555 | *out = Ellipsis(arena); |
| 5556 | if (*out == NULL) goto failed; |
| 5557 | return 0; |
| 5558 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5559 | isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type); |
| 5560 | if (isinstance == -1) { |
| 5561 | return 1; |
| 5562 | } |
| 5563 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5564 | expr_ty lower; |
| 5565 | expr_ty upper; |
| 5566 | expr_ty step; |
| 5567 | |
| 5568 | if (PyObject_HasAttrString(obj, "lower")) { |
| 5569 | int res; |
| 5570 | tmp = PyObject_GetAttrString(obj, "lower"); |
| 5571 | if (tmp == NULL) goto failed; |
| 5572 | res = obj2ast_expr(tmp, &lower, arena); |
| 5573 | if (res != 0) goto failed; |
| 5574 | Py_XDECREF(tmp); |
| 5575 | tmp = NULL; |
| 5576 | } else { |
| 5577 | lower = NULL; |
| 5578 | } |
| 5579 | if (PyObject_HasAttrString(obj, "upper")) { |
| 5580 | int res; |
| 5581 | tmp = PyObject_GetAttrString(obj, "upper"); |
| 5582 | if (tmp == NULL) goto failed; |
| 5583 | res = obj2ast_expr(tmp, &upper, arena); |
| 5584 | if (res != 0) goto failed; |
| 5585 | Py_XDECREF(tmp); |
| 5586 | tmp = NULL; |
| 5587 | } else { |
| 5588 | upper = NULL; |
| 5589 | } |
| 5590 | if (PyObject_HasAttrString(obj, "step")) { |
| 5591 | int res; |
| 5592 | tmp = PyObject_GetAttrString(obj, "step"); |
| 5593 | if (tmp == NULL) goto failed; |
| 5594 | res = obj2ast_expr(tmp, &step, arena); |
| 5595 | if (res != 0) goto failed; |
| 5596 | Py_XDECREF(tmp); |
| 5597 | tmp = NULL; |
| 5598 | } else { |
| 5599 | step = NULL; |
| 5600 | } |
| 5601 | *out = Slice(lower, upper, step, arena); |
| 5602 | if (*out == NULL) goto failed; |
| 5603 | return 0; |
| 5604 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5605 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type); |
| 5606 | if (isinstance == -1) { |
| 5607 | return 1; |
| 5608 | } |
| 5609 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5610 | asdl_seq* dims; |
| 5611 | |
| 5612 | if (PyObject_HasAttrString(obj, "dims")) { |
| 5613 | int res; |
| 5614 | Py_ssize_t len; |
| 5615 | Py_ssize_t i; |
| 5616 | tmp = PyObject_GetAttrString(obj, "dims"); |
| 5617 | if (tmp == NULL) goto failed; |
| 5618 | if (!PyList_Check(tmp)) { |
| 5619 | PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5620 | goto failed; |
| 5621 | } |
| 5622 | len = PyList_GET_SIZE(tmp); |
| 5623 | dims = asdl_seq_new(len, arena); |
| 5624 | if (dims == NULL) goto failed; |
| 5625 | for (i = 0; i < len; i++) { |
| 5626 | slice_ty value; |
| 5627 | res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5628 | if (res != 0) goto failed; |
| 5629 | asdl_seq_SET(dims, i, value); |
| 5630 | } |
| 5631 | Py_XDECREF(tmp); |
| 5632 | tmp = NULL; |
| 5633 | } else { |
| 5634 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
| 5635 | return 1; |
| 5636 | } |
| 5637 | *out = ExtSlice(dims, arena); |
| 5638 | if (*out == NULL) goto failed; |
| 5639 | return 0; |
| 5640 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5641 | isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type); |
| 5642 | if (isinstance == -1) { |
| 5643 | return 1; |
| 5644 | } |
| 5645 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5646 | expr_ty value; |
| 5647 | |
| 5648 | if (PyObject_HasAttrString(obj, "value")) { |
| 5649 | int res; |
| 5650 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5651 | if (tmp == NULL) goto failed; |
| 5652 | res = obj2ast_expr(tmp, &value, arena); |
| 5653 | if (res != 0) goto failed; |
| 5654 | Py_XDECREF(tmp); |
| 5655 | tmp = NULL; |
| 5656 | } else { |
| 5657 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
| 5658 | return 1; |
| 5659 | } |
| 5660 | *out = Index(value, arena); |
| 5661 | if (*out == NULL) goto failed; |
| 5662 | return 0; |
| 5663 | } |
| 5664 | |
| 5665 | tmp = PyObject_Repr(obj); |
| 5666 | if (tmp == NULL) goto failed; |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 5667 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %.400s", PyString_AS_STRING(tmp)); |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5668 | failed: |
| 5669 | Py_XDECREF(tmp); |
| 5670 | return 1; |
| 5671 | } |
| 5672 | |
| 5673 | int |
| 5674 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 5675 | { |
| 5676 | PyObject* tmp = NULL; |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5677 | int isinstance; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5678 | |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5679 | isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); |
| 5680 | if (isinstance == -1) { |
| 5681 | return 1; |
| 5682 | } |
| 5683 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5684 | *out = And; |
| 5685 | return 0; |
| 5686 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5687 | isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type); |
| 5688 | if (isinstance == -1) { |
| 5689 | return 1; |
| 5690 | } |
| 5691 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5692 | *out = Or; |
| 5693 | return 0; |
| 5694 | } |
| 5695 | |
| 5696 | tmp = PyObject_Repr(obj); |
| 5697 | if (tmp == NULL) goto failed; |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 5698 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %.400s", PyString_AS_STRING(tmp)); |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5699 | failed: |
| 5700 | Py_XDECREF(tmp); |
| 5701 | return 1; |
| 5702 | } |
| 5703 | |
| 5704 | int |
| 5705 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 5706 | { |
| 5707 | PyObject* tmp = NULL; |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5708 | int isinstance; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5709 | |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5710 | isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); |
| 5711 | if (isinstance == -1) { |
| 5712 | return 1; |
| 5713 | } |
| 5714 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5715 | *out = Add; |
| 5716 | return 0; |
| 5717 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5718 | isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type); |
| 5719 | if (isinstance == -1) { |
| 5720 | return 1; |
| 5721 | } |
| 5722 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5723 | *out = Sub; |
| 5724 | return 0; |
| 5725 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5726 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type); |
| 5727 | if (isinstance == -1) { |
| 5728 | return 1; |
| 5729 | } |
| 5730 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5731 | *out = Mult; |
| 5732 | return 0; |
| 5733 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5734 | isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type); |
| 5735 | if (isinstance == -1) { |
| 5736 | return 1; |
| 5737 | } |
| 5738 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5739 | *out = Div; |
| 5740 | return 0; |
| 5741 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5742 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type); |
| 5743 | if (isinstance == -1) { |
| 5744 | return 1; |
| 5745 | } |
| 5746 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5747 | *out = Mod; |
| 5748 | return 0; |
| 5749 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5750 | isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type); |
| 5751 | if (isinstance == -1) { |
| 5752 | return 1; |
| 5753 | } |
| 5754 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5755 | *out = Pow; |
| 5756 | return 0; |
| 5757 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5758 | isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type); |
| 5759 | if (isinstance == -1) { |
| 5760 | return 1; |
| 5761 | } |
| 5762 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5763 | *out = LShift; |
| 5764 | return 0; |
| 5765 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5766 | isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type); |
| 5767 | if (isinstance == -1) { |
| 5768 | return 1; |
| 5769 | } |
| 5770 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5771 | *out = RShift; |
| 5772 | return 0; |
| 5773 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5774 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type); |
| 5775 | if (isinstance == -1) { |
| 5776 | return 1; |
| 5777 | } |
| 5778 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5779 | *out = BitOr; |
| 5780 | return 0; |
| 5781 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5782 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type); |
| 5783 | if (isinstance == -1) { |
| 5784 | return 1; |
| 5785 | } |
| 5786 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5787 | *out = BitXor; |
| 5788 | return 0; |
| 5789 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5790 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type); |
| 5791 | if (isinstance == -1) { |
| 5792 | return 1; |
| 5793 | } |
| 5794 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5795 | *out = BitAnd; |
| 5796 | return 0; |
| 5797 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5798 | isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type); |
| 5799 | if (isinstance == -1) { |
| 5800 | return 1; |
| 5801 | } |
| 5802 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5803 | *out = FloorDiv; |
| 5804 | return 0; |
| 5805 | } |
| 5806 | |
| 5807 | tmp = PyObject_Repr(obj); |
| 5808 | if (tmp == NULL) goto failed; |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 5809 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %.400s", PyString_AS_STRING(tmp)); |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5810 | failed: |
| 5811 | Py_XDECREF(tmp); |
| 5812 | return 1; |
| 5813 | } |
| 5814 | |
| 5815 | int |
| 5816 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 5817 | { |
| 5818 | PyObject* tmp = NULL; |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5819 | int isinstance; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5820 | |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5821 | isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); |
| 5822 | if (isinstance == -1) { |
| 5823 | return 1; |
| 5824 | } |
| 5825 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5826 | *out = Invert; |
| 5827 | return 0; |
| 5828 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5829 | isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type); |
| 5830 | if (isinstance == -1) { |
| 5831 | return 1; |
| 5832 | } |
| 5833 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5834 | *out = Not; |
| 5835 | return 0; |
| 5836 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5837 | isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type); |
| 5838 | if (isinstance == -1) { |
| 5839 | return 1; |
| 5840 | } |
| 5841 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5842 | *out = UAdd; |
| 5843 | return 0; |
| 5844 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5845 | isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type); |
| 5846 | if (isinstance == -1) { |
| 5847 | return 1; |
| 5848 | } |
| 5849 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5850 | *out = USub; |
| 5851 | return 0; |
| 5852 | } |
| 5853 | |
| 5854 | tmp = PyObject_Repr(obj); |
| 5855 | if (tmp == NULL) goto failed; |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 5856 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %.400s", PyString_AS_STRING(tmp)); |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5857 | failed: |
| 5858 | Py_XDECREF(tmp); |
| 5859 | return 1; |
| 5860 | } |
| 5861 | |
| 5862 | int |
| 5863 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 5864 | { |
| 5865 | PyObject* tmp = NULL; |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5866 | int isinstance; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5867 | |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5868 | isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); |
| 5869 | if (isinstance == -1) { |
| 5870 | return 1; |
| 5871 | } |
| 5872 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5873 | *out = Eq; |
| 5874 | return 0; |
| 5875 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5876 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type); |
| 5877 | if (isinstance == -1) { |
| 5878 | return 1; |
| 5879 | } |
| 5880 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5881 | *out = NotEq; |
| 5882 | return 0; |
| 5883 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5884 | isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type); |
| 5885 | if (isinstance == -1) { |
| 5886 | return 1; |
| 5887 | } |
| 5888 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5889 | *out = Lt; |
| 5890 | return 0; |
| 5891 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5892 | isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type); |
| 5893 | if (isinstance == -1) { |
| 5894 | return 1; |
| 5895 | } |
| 5896 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5897 | *out = LtE; |
| 5898 | return 0; |
| 5899 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5900 | isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type); |
| 5901 | if (isinstance == -1) { |
| 5902 | return 1; |
| 5903 | } |
| 5904 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5905 | *out = Gt; |
| 5906 | return 0; |
| 5907 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5908 | isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type); |
| 5909 | if (isinstance == -1) { |
| 5910 | return 1; |
| 5911 | } |
| 5912 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5913 | *out = GtE; |
| 5914 | return 0; |
| 5915 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5916 | isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type); |
| 5917 | if (isinstance == -1) { |
| 5918 | return 1; |
| 5919 | } |
| 5920 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5921 | *out = Is; |
| 5922 | return 0; |
| 5923 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5924 | isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type); |
| 5925 | if (isinstance == -1) { |
| 5926 | return 1; |
| 5927 | } |
| 5928 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5929 | *out = IsNot; |
| 5930 | return 0; |
| 5931 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5932 | isinstance = PyObject_IsInstance(obj, (PyObject *)In_type); |
| 5933 | if (isinstance == -1) { |
| 5934 | return 1; |
| 5935 | } |
| 5936 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5937 | *out = In; |
| 5938 | return 0; |
| 5939 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 5940 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type); |
| 5941 | if (isinstance == -1) { |
| 5942 | return 1; |
| 5943 | } |
| 5944 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5945 | *out = NotIn; |
| 5946 | return 0; |
| 5947 | } |
| 5948 | |
| 5949 | tmp = PyObject_Repr(obj); |
| 5950 | if (tmp == NULL) goto failed; |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 5951 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %.400s", PyString_AS_STRING(tmp)); |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5952 | failed: |
| 5953 | Py_XDECREF(tmp); |
| 5954 | return 1; |
| 5955 | } |
| 5956 | |
| 5957 | int |
| 5958 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 5959 | { |
| 5960 | PyObject* tmp = NULL; |
| 5961 | expr_ty target; |
| 5962 | expr_ty iter; |
| 5963 | asdl_seq* ifs; |
| 5964 | |
| 5965 | if (PyObject_HasAttrString(obj, "target")) { |
| 5966 | int res; |
| 5967 | tmp = PyObject_GetAttrString(obj, "target"); |
| 5968 | if (tmp == NULL) goto failed; |
| 5969 | res = obj2ast_expr(tmp, &target, arena); |
| 5970 | if (res != 0) goto failed; |
| 5971 | Py_XDECREF(tmp); |
| 5972 | tmp = NULL; |
| 5973 | } else { |
| 5974 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 5975 | return 1; |
| 5976 | } |
| 5977 | if (PyObject_HasAttrString(obj, "iter")) { |
| 5978 | int res; |
| 5979 | tmp = PyObject_GetAttrString(obj, "iter"); |
| 5980 | if (tmp == NULL) goto failed; |
| 5981 | res = obj2ast_expr(tmp, &iter, arena); |
| 5982 | if (res != 0) goto failed; |
| 5983 | Py_XDECREF(tmp); |
| 5984 | tmp = NULL; |
| 5985 | } else { |
| 5986 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 5987 | return 1; |
| 5988 | } |
| 5989 | if (PyObject_HasAttrString(obj, "ifs")) { |
| 5990 | int res; |
| 5991 | Py_ssize_t len; |
| 5992 | Py_ssize_t i; |
| 5993 | tmp = PyObject_GetAttrString(obj, "ifs"); |
| 5994 | if (tmp == NULL) goto failed; |
| 5995 | if (!PyList_Check(tmp)) { |
| 5996 | PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5997 | goto failed; |
| 5998 | } |
| 5999 | len = PyList_GET_SIZE(tmp); |
| 6000 | ifs = asdl_seq_new(len, arena); |
| 6001 | if (ifs == NULL) goto failed; |
| 6002 | for (i = 0; i < len; i++) { |
| 6003 | expr_ty value; |
| 6004 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6005 | if (res != 0) goto failed; |
| 6006 | asdl_seq_SET(ifs, i, value); |
| 6007 | } |
| 6008 | Py_XDECREF(tmp); |
| 6009 | tmp = NULL; |
| 6010 | } else { |
| 6011 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 6012 | return 1; |
| 6013 | } |
| 6014 | *out = comprehension(target, iter, ifs, arena); |
| 6015 | return 0; |
| 6016 | failed: |
| 6017 | Py_XDECREF(tmp); |
| 6018 | return 1; |
| 6019 | } |
| 6020 | |
| 6021 | int |
| 6022 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 6023 | { |
| 6024 | PyObject* tmp = NULL; |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 6025 | int isinstance; |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame] | 6026 | |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 6027 | int lineno; |
| 6028 | int col_offset; |
| 6029 | |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame] | 6030 | if (obj == Py_None) { |
| 6031 | *out = NULL; |
| 6032 | return 0; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 6033 | } |
| 6034 | if (PyObject_HasAttrString(obj, "lineno")) { |
| 6035 | int res; |
| 6036 | tmp = PyObject_GetAttrString(obj, "lineno"); |
| 6037 | if (tmp == NULL) goto failed; |
| 6038 | res = obj2ast_int(tmp, &lineno, arena); |
| 6039 | if (res != 0) goto failed; |
| 6040 | Py_XDECREF(tmp); |
| 6041 | tmp = NULL; |
| 6042 | } else { |
| 6043 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 6044 | return 1; |
| 6045 | } |
| 6046 | if (PyObject_HasAttrString(obj, "col_offset")) { |
| 6047 | int res; |
| 6048 | tmp = PyObject_GetAttrString(obj, "col_offset"); |
| 6049 | if (tmp == NULL) goto failed; |
| 6050 | res = obj2ast_int(tmp, &col_offset, arena); |
| 6051 | if (res != 0) goto failed; |
| 6052 | Py_XDECREF(tmp); |
| 6053 | tmp = NULL; |
| 6054 | } else { |
| 6055 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 6056 | return 1; |
| 6057 | } |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 6058 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type); |
| 6059 | if (isinstance == -1) { |
| 6060 | return 1; |
| 6061 | } |
| 6062 | if (isinstance) { |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame] | 6063 | expr_ty type; |
| 6064 | expr_ty name; |
| 6065 | asdl_seq* body; |
| 6066 | |
| 6067 | if (PyObject_HasAttrString(obj, "type")) { |
| 6068 | int res; |
| 6069 | tmp = PyObject_GetAttrString(obj, "type"); |
| 6070 | if (tmp == NULL) goto failed; |
| 6071 | res = obj2ast_expr(tmp, &type, arena); |
| 6072 | if (res != 0) goto failed; |
| 6073 | Py_XDECREF(tmp); |
| 6074 | tmp = NULL; |
| 6075 | } else { |
| 6076 | type = NULL; |
| 6077 | } |
| 6078 | if (PyObject_HasAttrString(obj, "name")) { |
| 6079 | int res; |
| 6080 | tmp = PyObject_GetAttrString(obj, "name"); |
| 6081 | if (tmp == NULL) goto failed; |
| 6082 | res = obj2ast_expr(tmp, &name, arena); |
| 6083 | if (res != 0) goto failed; |
| 6084 | Py_XDECREF(tmp); |
| 6085 | tmp = NULL; |
| 6086 | } else { |
| 6087 | name = NULL; |
| 6088 | } |
| 6089 | if (PyObject_HasAttrString(obj, "body")) { |
| 6090 | int res; |
| 6091 | Py_ssize_t len; |
| 6092 | Py_ssize_t i; |
| 6093 | tmp = PyObject_GetAttrString(obj, "body"); |
| 6094 | if (tmp == NULL) goto failed; |
| 6095 | if (!PyList_Check(tmp)) { |
| 6096 | PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6097 | goto failed; |
| 6098 | } |
| 6099 | len = PyList_GET_SIZE(tmp); |
| 6100 | body = asdl_seq_new(len, arena); |
| 6101 | if (body == NULL) goto failed; |
| 6102 | for (i = 0; i < len; i++) { |
| 6103 | stmt_ty value; |
| 6104 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6105 | if (res != 0) goto failed; |
| 6106 | asdl_seq_SET(body, i, value); |
| 6107 | } |
| 6108 | Py_XDECREF(tmp); |
| 6109 | tmp = NULL; |
| 6110 | } else { |
| 6111 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 6112 | return 1; |
| 6113 | } |
| 6114 | *out = ExceptHandler(type, name, body, lineno, col_offset, |
| 6115 | arena); |
| 6116 | if (*out == NULL) goto failed; |
| 6117 | return 0; |
| 6118 | } |
| 6119 | |
| 6120 | tmp = PyObject_Repr(obj); |
| 6121 | if (tmp == NULL) goto failed; |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 6122 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %.400s", PyString_AS_STRING(tmp)); |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 6123 | failed: |
| 6124 | Py_XDECREF(tmp); |
| 6125 | return 1; |
| 6126 | } |
| 6127 | |
| 6128 | int |
| 6129 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 6130 | { |
| 6131 | PyObject* tmp = NULL; |
| 6132 | asdl_seq* args; |
| 6133 | identifier vararg; |
| 6134 | identifier kwarg; |
| 6135 | asdl_seq* defaults; |
| 6136 | |
| 6137 | if (PyObject_HasAttrString(obj, "args")) { |
| 6138 | int res; |
| 6139 | Py_ssize_t len; |
| 6140 | Py_ssize_t i; |
| 6141 | tmp = PyObject_GetAttrString(obj, "args"); |
| 6142 | if (tmp == NULL) goto failed; |
| 6143 | if (!PyList_Check(tmp)) { |
| 6144 | PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6145 | goto failed; |
| 6146 | } |
| 6147 | len = PyList_GET_SIZE(tmp); |
| 6148 | args = asdl_seq_new(len, arena); |
| 6149 | if (args == NULL) goto failed; |
| 6150 | for (i = 0; i < len; i++) { |
| 6151 | expr_ty value; |
| 6152 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6153 | if (res != 0) goto failed; |
| 6154 | asdl_seq_SET(args, i, value); |
| 6155 | } |
| 6156 | Py_XDECREF(tmp); |
| 6157 | tmp = NULL; |
| 6158 | } else { |
| 6159 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 6160 | return 1; |
| 6161 | } |
| 6162 | if (PyObject_HasAttrString(obj, "vararg")) { |
| 6163 | int res; |
| 6164 | tmp = PyObject_GetAttrString(obj, "vararg"); |
| 6165 | if (tmp == NULL) goto failed; |
| 6166 | res = obj2ast_identifier(tmp, &vararg, arena); |
| 6167 | if (res != 0) goto failed; |
| 6168 | Py_XDECREF(tmp); |
| 6169 | tmp = NULL; |
| 6170 | } else { |
| 6171 | vararg = NULL; |
| 6172 | } |
| 6173 | if (PyObject_HasAttrString(obj, "kwarg")) { |
| 6174 | int res; |
| 6175 | tmp = PyObject_GetAttrString(obj, "kwarg"); |
| 6176 | if (tmp == NULL) goto failed; |
| 6177 | res = obj2ast_identifier(tmp, &kwarg, arena); |
| 6178 | if (res != 0) goto failed; |
| 6179 | Py_XDECREF(tmp); |
| 6180 | tmp = NULL; |
| 6181 | } else { |
| 6182 | kwarg = NULL; |
| 6183 | } |
| 6184 | if (PyObject_HasAttrString(obj, "defaults")) { |
| 6185 | int res; |
| 6186 | Py_ssize_t len; |
| 6187 | Py_ssize_t i; |
| 6188 | tmp = PyObject_GetAttrString(obj, "defaults"); |
| 6189 | if (tmp == NULL) goto failed; |
| 6190 | if (!PyList_Check(tmp)) { |
| 6191 | PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6192 | goto failed; |
| 6193 | } |
| 6194 | len = PyList_GET_SIZE(tmp); |
| 6195 | defaults = asdl_seq_new(len, arena); |
| 6196 | if (defaults == NULL) goto failed; |
| 6197 | for (i = 0; i < len; i++) { |
| 6198 | expr_ty value; |
| 6199 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6200 | if (res != 0) goto failed; |
| 6201 | asdl_seq_SET(defaults, i, value); |
| 6202 | } |
| 6203 | Py_XDECREF(tmp); |
| 6204 | tmp = NULL; |
| 6205 | } else { |
| 6206 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 6207 | return 1; |
| 6208 | } |
| 6209 | *out = arguments(args, vararg, kwarg, defaults, arena); |
| 6210 | return 0; |
| 6211 | failed: |
| 6212 | Py_XDECREF(tmp); |
| 6213 | return 1; |
| 6214 | } |
| 6215 | |
| 6216 | int |
| 6217 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 6218 | { |
| 6219 | PyObject* tmp = NULL; |
| 6220 | identifier arg; |
| 6221 | expr_ty value; |
| 6222 | |
| 6223 | if (PyObject_HasAttrString(obj, "arg")) { |
| 6224 | int res; |
| 6225 | tmp = PyObject_GetAttrString(obj, "arg"); |
| 6226 | if (tmp == NULL) goto failed; |
| 6227 | res = obj2ast_identifier(tmp, &arg, arena); |
| 6228 | if (res != 0) goto failed; |
| 6229 | Py_XDECREF(tmp); |
| 6230 | tmp = NULL; |
| 6231 | } else { |
| 6232 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from keyword"); |
| 6233 | return 1; |
| 6234 | } |
| 6235 | if (PyObject_HasAttrString(obj, "value")) { |
| 6236 | int res; |
| 6237 | tmp = PyObject_GetAttrString(obj, "value"); |
| 6238 | if (tmp == NULL) goto failed; |
| 6239 | res = obj2ast_expr(tmp, &value, arena); |
| 6240 | if (res != 0) goto failed; |
| 6241 | Py_XDECREF(tmp); |
| 6242 | tmp = NULL; |
| 6243 | } else { |
| 6244 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 6245 | return 1; |
| 6246 | } |
| 6247 | *out = keyword(arg, value, arena); |
| 6248 | return 0; |
| 6249 | failed: |
| 6250 | Py_XDECREF(tmp); |
| 6251 | return 1; |
| 6252 | } |
| 6253 | |
| 6254 | int |
| 6255 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 6256 | { |
| 6257 | PyObject* tmp = NULL; |
| 6258 | identifier name; |
| 6259 | identifier asname; |
| 6260 | |
| 6261 | if (PyObject_HasAttrString(obj, "name")) { |
| 6262 | int res; |
| 6263 | tmp = PyObject_GetAttrString(obj, "name"); |
| 6264 | if (tmp == NULL) goto failed; |
| 6265 | res = obj2ast_identifier(tmp, &name, arena); |
| 6266 | if (res != 0) goto failed; |
| 6267 | Py_XDECREF(tmp); |
| 6268 | tmp = NULL; |
| 6269 | } else { |
| 6270 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 6271 | return 1; |
| 6272 | } |
| 6273 | if (PyObject_HasAttrString(obj, "asname")) { |
| 6274 | int res; |
| 6275 | tmp = PyObject_GetAttrString(obj, "asname"); |
| 6276 | if (tmp == NULL) goto failed; |
| 6277 | res = obj2ast_identifier(tmp, &asname, arena); |
| 6278 | if (res != 0) goto failed; |
| 6279 | Py_XDECREF(tmp); |
| 6280 | tmp = NULL; |
| 6281 | } else { |
| 6282 | asname = NULL; |
| 6283 | } |
| 6284 | *out = alias(name, asname, arena); |
| 6285 | return 0; |
| 6286 | failed: |
| 6287 | Py_XDECREF(tmp); |
| 6288 | return 1; |
| 6289 | } |
| 6290 | |
| 6291 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6292 | PyMODINIT_FUNC |
| 6293 | init_ast(void) |
| 6294 | { |
| 6295 | PyObject *m, *d; |
| 6296 | if (!init_types()) return; |
| 6297 | m = Py_InitModule3("_ast", NULL, NULL); |
| 6298 | if (!m) return; |
| 6299 | d = PyModule_GetDict(m); |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 6300 | if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6301 | if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) |
| 6302 | return; |
Barry Warsaw | cf0d8ab | 2011-05-23 15:22:56 -0400 | [diff] [blame^] | 6303 | if (PyModule_AddStringConstant(m, "__version__", "") < 0) |
Martin v. Löwis | ace990c | 2006-02-28 00:32:31 +0000 | [diff] [blame] | 6304 | return; |
Neal Norwitz | 19379f1 | 2006-04-03 04:50:58 +0000 | [diff] [blame] | 6305 | if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return; |
| 6306 | if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) |
| 6307 | return; |
| 6308 | if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) |
| 6309 | < 0) return; |
| 6310 | if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < |
| 6311 | 0) return; |
| 6312 | if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return; |
| 6313 | if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return; |
| 6314 | if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) |
| 6315 | < 0) return; |
| 6316 | if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) |
| 6317 | return; |
| 6318 | if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) |
| 6319 | return; |
| 6320 | if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) |
| 6321 | return; |
| 6322 | if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) |
| 6323 | return; |
| 6324 | if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < |
| 6325 | 0) return; |
| 6326 | if (PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return; |
| 6327 | if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return; |
| 6328 | if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return; |
| 6329 | if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return; |
| 6330 | if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return; |
| 6331 | if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return; |
| 6332 | if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) < |
| 6333 | 0) return; |
| 6334 | if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) < |
| 6335 | 0) return; |
| 6336 | if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) |
| 6337 | return; |
| 6338 | if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) |
| 6339 | return; |
| 6340 | if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < |
| 6341 | 0) return; |
| 6342 | if (PyDict_SetItemString(d, "Exec", (PyObject*)Exec_type) < 0) return; |
| 6343 | if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) |
| 6344 | return; |
| 6345 | if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return; |
| 6346 | if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return; |
| 6347 | if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return; |
| 6348 | if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) |
| 6349 | return; |
| 6350 | if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return; |
| 6351 | if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) |
| 6352 | return; |
| 6353 | if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return; |
| 6354 | if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) |
| 6355 | return; |
| 6356 | if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) |
| 6357 | return; |
| 6358 | if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return; |
| 6359 | if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return; |
| 6360 | if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) |
| 6361 | return; |
| 6362 | if (PyDict_SetItemString(d, "GeneratorExp", |
| 6363 | (PyObject*)GeneratorExp_type) < 0) return; |
| 6364 | if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return; |
| 6365 | if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) |
| 6366 | return; |
| 6367 | if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return; |
| 6368 | if (PyDict_SetItemString(d, "Repr", (PyObject*)Repr_type) < 0) return; |
| 6369 | if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return; |
| 6370 | if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return; |
| 6371 | if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < |
| 6372 | 0) return; |
| 6373 | if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < |
| 6374 | 0) return; |
| 6375 | if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return; |
| 6376 | if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return; |
| 6377 | if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return; |
| 6378 | if (PyDict_SetItemString(d, "expr_context", |
| 6379 | (PyObject*)expr_context_type) < 0) return; |
| 6380 | if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return; |
| 6381 | if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return; |
| 6382 | if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return; |
| 6383 | if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) |
| 6384 | return; |
| 6385 | if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) |
| 6386 | return; |
| 6387 | if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return; |
| 6388 | if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return; |
| 6389 | if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0) |
| 6390 | return; |
| 6391 | if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return; |
| 6392 | if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) |
| 6393 | return; |
| 6394 | if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return; |
| 6395 | if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) |
| 6396 | return; |
| 6397 | if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return; |
| 6398 | if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return; |
| 6399 | if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) |
| 6400 | return; |
| 6401 | if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return; |
| 6402 | if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return; |
| 6403 | if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return; |
| 6404 | if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return; |
| 6405 | if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return; |
| 6406 | if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return; |
| 6407 | if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) |
| 6408 | return; |
| 6409 | if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) |
| 6410 | return; |
| 6411 | if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return; |
| 6412 | if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) |
| 6413 | return; |
| 6414 | if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) |
| 6415 | return; |
| 6416 | if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) |
| 6417 | return; |
| 6418 | if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) |
| 6419 | return; |
| 6420 | if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) |
| 6421 | return; |
| 6422 | if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return; |
| 6423 | if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return; |
| 6424 | if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return; |
| 6425 | if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return; |
| 6426 | if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return; |
| 6427 | if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return; |
| 6428 | if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return; |
| 6429 | if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return; |
| 6430 | if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return; |
| 6431 | if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return; |
| 6432 | if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return; |
| 6433 | if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return; |
| 6434 | if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return; |
| 6435 | if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return; |
| 6436 | if (PyDict_SetItemString(d, "comprehension", |
| 6437 | (PyObject*)comprehension_type) < 0) return; |
| 6438 | if (PyDict_SetItemString(d, "excepthandler", |
| 6439 | (PyObject*)excepthandler_type) < 0) return; |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame] | 6440 | if (PyDict_SetItemString(d, "ExceptHandler", |
| 6441 | (PyObject*)ExceptHandler_type) < 0) return; |
Neal Norwitz | 19379f1 | 2006-04-03 04:50:58 +0000 | [diff] [blame] | 6442 | if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < |
| 6443 | 0) return; |
| 6444 | if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) |
| 6445 | return; |
| 6446 | if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6447 | } |
| 6448 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 6449 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 6450 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 6451 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 6452 | init_types(); |
| 6453 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 6454 | } |
| 6455 | |
Georg Brandl | f2bfd54 | 2008-03-29 13:24:23 +0000 | [diff] [blame] | 6456 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 6457 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 6458 | { |
| 6459 | mod_ty res; |
Georg Brandl | f2bfd54 | 2008-03-29 13:24:23 +0000 | [diff] [blame] | 6460 | PyObject *req_type[] = {(PyObject*)Module_type, (PyObject*)Expression_type, |
| 6461 | (PyObject*)Interactive_type}; |
| 6462 | char *req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 6463 | int isinstance; |
Georg Brandl | f2bfd54 | 2008-03-29 13:24:23 +0000 | [diff] [blame] | 6464 | assert(0 <= mode && mode <= 2); |
| 6465 | |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 6466 | init_types(); |
Georg Brandl | f2bfd54 | 2008-03-29 13:24:23 +0000 | [diff] [blame] | 6467 | |
Benjamin Peterson | 011e9f1 | 2009-12-13 00:59:01 +0000 | [diff] [blame] | 6468 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 6469 | if (isinstance == -1) |
| 6470 | return NULL; |
| 6471 | if (!isinstance) { |
Georg Brandl | f2bfd54 | 2008-03-29 13:24:23 +0000 | [diff] [blame] | 6472 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
| 6473 | req_name[mode], Py_TYPE(ast)->tp_name); |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 6474 | return NULL; |
| 6475 | } |
| 6476 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 6477 | return NULL; |
| 6478 | else |
| 6479 | return res; |
| 6480 | } |
| 6481 | |
| 6482 | int PyAST_Check(PyObject* obj) |
| 6483 | { |
| 6484 | init_types(); |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 6485 | return PyObject_IsInstance(obj, (PyObject*)&AST_type); |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 6486 | } |
| 6487 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 6488 | |