Brett Cannon | 0db62aa | 2007-02-12 03:51:02 +0000 | [diff] [blame] | 1 | /* File automatically generated by Parser/asdl_c.py. */ |
| 2 | |
| 3 | |
| 4 | /* |
Christian Heimes | 4034685 | 2008-02-23 17:52:07 +0000 | [diff] [blame] | 5 | __version__ 60978. |
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 | |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 15 | static PyTypeObject* AST_type; |
| 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 | |
| 372 | static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields) |
| 373 | { |
| 374 | PyObject *fnames, *result; |
| 375 | int i; |
| 376 | if (num_fields) { |
| 377 | fnames = PyTuple_New(num_fields); |
| 378 | if (!fnames) return NULL; |
| 379 | } else { |
| 380 | fnames = Py_None; |
| 381 | Py_INCREF(Py_None); |
| 382 | } |
| 383 | for(i=0; i < num_fields; i++) { |
| 384 | PyObject *field = PyString_FromString(fields[i]); |
| 385 | if (!field) { |
| 386 | Py_DECREF(fnames); |
| 387 | return NULL; |
| 388 | } |
| 389 | PyTuple_SET_ITEM(fnames, i, field); |
| 390 | } |
Thomas Wouters | 34aa7ba | 2006-02-28 19:02:24 +0000 | [diff] [blame] | 391 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 392 | type, base, "_fields", fnames, "__module__", "_ast"); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 393 | Py_DECREF(fnames); |
| 394 | return (PyTypeObject*)result; |
| 395 | } |
| 396 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 397 | static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) |
| 398 | { |
Neal Norwitz | 19379f1 | 2006-04-03 04:50:58 +0000 | [diff] [blame] | 399 | int i, result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 400 | PyObject *s, *l = PyList_New(num_fields); |
| 401 | if (!l) return 0; |
Neal Norwitz | 19379f1 | 2006-04-03 04:50:58 +0000 | [diff] [blame] | 402 | for(i = 0; i < num_fields; i++) { |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 403 | s = PyString_FromString(attrs[i]); |
| 404 | if (!s) { |
| 405 | Py_DECREF(l); |
| 406 | return 0; |
| 407 | } |
| 408 | PyList_SET_ITEM(l, i, s); |
| 409 | } |
Neal Norwitz | 19379f1 | 2006-04-03 04:50:58 +0000 | [diff] [blame] | 410 | result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0; |
| 411 | Py_DECREF(l); |
| 412 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 413 | } |
| 414 | |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 415 | /* Conversion AST -> Python */ |
| 416 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 417 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 418 | { |
| 419 | int i, n = asdl_seq_LEN(seq); |
| 420 | PyObject *result = PyList_New(n); |
| 421 | PyObject *value; |
| 422 | if (!result) |
| 423 | return NULL; |
| 424 | for (i = 0; i < n; i++) { |
| 425 | value = func(asdl_seq_GET(seq, i)); |
| 426 | if (!value) { |
| 427 | Py_DECREF(result); |
| 428 | return NULL; |
| 429 | } |
| 430 | PyList_SET_ITEM(result, i, value); |
| 431 | } |
| 432 | return result; |
| 433 | } |
| 434 | |
| 435 | static PyObject* ast2obj_object(void *o) |
| 436 | { |
| 437 | if (!o) |
| 438 | o = Py_None; |
| 439 | Py_INCREF((PyObject*)o); |
| 440 | return (PyObject*)o; |
| 441 | } |
| 442 | #define ast2obj_identifier ast2obj_object |
| 443 | #define ast2obj_string ast2obj_object |
| 444 | static PyObject* ast2obj_bool(bool b) |
| 445 | { |
| 446 | return PyBool_FromLong(b); |
| 447 | } |
| 448 | |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 449 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 450 | { |
| 451 | return PyInt_FromLong(b); |
| 452 | } |
| 453 | |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 454 | /* Conversion Python -> AST */ |
| 455 | |
| 456 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 457 | { |
| 458 | if (obj == Py_None) |
| 459 | obj = NULL; |
| 460 | if (obj) |
| 461 | PyArena_AddPyObject(arena, obj); |
| 462 | Py_XINCREF(obj); |
| 463 | *out = obj; |
| 464 | return 0; |
| 465 | } |
| 466 | |
| 467 | #define obj2ast_identifier obj2ast_object |
| 468 | #define obj2ast_string obj2ast_object |
| 469 | |
| 470 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 471 | { |
| 472 | int i; |
| 473 | if (!PyInt_Check(obj) && !PyLong_Check(obj)) { |
| 474 | PyObject *s = PyObject_Repr(obj); |
| 475 | if (s == NULL) return 1; |
| 476 | PyErr_Format(PyExc_ValueError, "invalid integer value: %.400s", |
| 477 | PyString_AS_STRING(s)); |
| 478 | Py_DECREF(s); |
| 479 | return 1; |
| 480 | } |
| 481 | |
| 482 | i = (int)PyLong_AsLong(obj); |
| 483 | if (i == -1 && PyErr_Occurred()) |
| 484 | return 1; |
| 485 | *out = i; |
| 486 | return 0; |
| 487 | } |
| 488 | |
| 489 | static int obj2ast_bool(PyObject* obj, bool* out, PyArena* arena) |
| 490 | { |
| 491 | if (!PyBool_Check(obj)) { |
| 492 | PyObject *s = PyObject_Repr(obj); |
| 493 | if (s == NULL) return 1; |
| 494 | PyErr_Format(PyExc_ValueError, "invalid boolean value: %.400s", |
| 495 | PyString_AS_STRING(s)); |
| 496 | Py_DECREF(s); |
| 497 | return 1; |
| 498 | } |
| 499 | |
| 500 | *out = (obj == Py_True); |
| 501 | return 0; |
| 502 | } |
| 503 | |
| 504 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 505 | static int init_types(void) |
| 506 | { |
Neal Norwitz | 19379f1 | 2006-04-03 04:50:58 +0000 | [diff] [blame] | 507 | static int initialized; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 508 | if (initialized) return 1; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 509 | AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0); |
| 510 | mod_type = make_type("mod", AST_type, NULL, 0); |
| 511 | if (!mod_type) return 0; |
| 512 | if (!add_attributes(mod_type, NULL, 0)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 513 | Module_type = make_type("Module", mod_type, Module_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 514 | if (!Module_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 515 | Interactive_type = make_type("Interactive", mod_type, |
| 516 | Interactive_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 517 | if (!Interactive_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 518 | Expression_type = make_type("Expression", mod_type, Expression_fields, |
| 519 | 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 520 | if (!Expression_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 521 | Suite_type = make_type("Suite", mod_type, Suite_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 522 | if (!Suite_type) return 0; |
| 523 | stmt_type = make_type("stmt", AST_type, NULL, 0); |
| 524 | if (!stmt_type) return 0; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 525 | if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 526 | FunctionDef_type = make_type("FunctionDef", stmt_type, |
| 527 | FunctionDef_fields, 4); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 528 | if (!FunctionDef_type) return 0; |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 529 | ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 4); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 530 | if (!ClassDef_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 531 | Return_type = make_type("Return", stmt_type, Return_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 532 | if (!Return_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 533 | Delete_type = make_type("Delete", stmt_type, Delete_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 534 | if (!Delete_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 535 | Assign_type = make_type("Assign", stmt_type, Assign_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 536 | if (!Assign_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 537 | AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 538 | if (!AugAssign_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 539 | Print_type = make_type("Print", stmt_type, Print_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 540 | if (!Print_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 541 | For_type = make_type("For", stmt_type, For_fields, 4); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 542 | if (!For_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 543 | While_type = make_type("While", stmt_type, While_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 544 | if (!While_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 545 | If_type = make_type("If", stmt_type, If_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 546 | if (!If_type) return 0; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 547 | With_type = make_type("With", stmt_type, With_fields, 3); |
| 548 | if (!With_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 549 | Raise_type = make_type("Raise", stmt_type, Raise_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 550 | if (!Raise_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 551 | TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 552 | if (!TryExcept_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 553 | TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields, |
| 554 | 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 555 | if (!TryFinally_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 556 | Assert_type = make_type("Assert", stmt_type, Assert_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 557 | if (!Assert_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 558 | Import_type = make_type("Import", stmt_type, Import_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 559 | if (!Import_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 560 | ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 561 | 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 562 | if (!ImportFrom_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 563 | Exec_type = make_type("Exec", stmt_type, Exec_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 564 | if (!Exec_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 565 | Global_type = make_type("Global", stmt_type, Global_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 566 | if (!Global_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 567 | Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 568 | if (!Expr_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 569 | Pass_type = make_type("Pass", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 570 | if (!Pass_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 571 | Break_type = make_type("Break", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 572 | if (!Break_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 573 | Continue_type = make_type("Continue", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 574 | if (!Continue_type) return 0; |
| 575 | expr_type = make_type("expr", AST_type, NULL, 0); |
| 576 | if (!expr_type) return 0; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 577 | if (!add_attributes(expr_type, expr_attributes, 2)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 578 | BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 579 | if (!BoolOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 580 | BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 581 | if (!BinOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 582 | UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 583 | if (!UnaryOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 584 | Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 585 | if (!Lambda_type) return 0; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 586 | IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 587 | if (!IfExp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 588 | Dict_type = make_type("Dict", expr_type, Dict_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 589 | if (!Dict_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 590 | ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 591 | if (!ListComp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 592 | GeneratorExp_type = make_type("GeneratorExp", expr_type, |
| 593 | GeneratorExp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 594 | if (!GeneratorExp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 595 | Yield_type = make_type("Yield", expr_type, Yield_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 596 | if (!Yield_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 597 | Compare_type = make_type("Compare", expr_type, Compare_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 598 | if (!Compare_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 599 | Call_type = make_type("Call", expr_type, Call_fields, 5); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 600 | if (!Call_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 601 | Repr_type = make_type("Repr", expr_type, Repr_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 602 | if (!Repr_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 603 | Num_type = make_type("Num", expr_type, Num_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 604 | if (!Num_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 605 | Str_type = make_type("Str", expr_type, Str_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 606 | if (!Str_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 607 | Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 608 | if (!Attribute_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 609 | Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 610 | if (!Subscript_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 611 | Name_type = make_type("Name", expr_type, Name_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 612 | if (!Name_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 613 | List_type = make_type("List", expr_type, List_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 614 | if (!List_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 615 | Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 616 | if (!Tuple_type) return 0; |
| 617 | expr_context_type = make_type("expr_context", AST_type, NULL, 0); |
| 618 | if (!expr_context_type) return 0; |
| 619 | if (!add_attributes(expr_context_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 620 | Load_type = make_type("Load", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 621 | if (!Load_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 622 | Load_singleton = PyType_GenericNew(Load_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 623 | if (!Load_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 624 | Store_type = make_type("Store", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 625 | if (!Store_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 626 | Store_singleton = PyType_GenericNew(Store_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 627 | if (!Store_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 628 | Del_type = make_type("Del", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 629 | if (!Del_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 630 | Del_singleton = PyType_GenericNew(Del_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 631 | if (!Del_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 632 | AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 633 | if (!AugLoad_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 634 | AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 635 | if (!AugLoad_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 636 | AugStore_type = make_type("AugStore", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 637 | if (!AugStore_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 638 | AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 639 | if (!AugStore_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 640 | Param_type = make_type("Param", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 641 | if (!Param_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 642 | Param_singleton = PyType_GenericNew(Param_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 643 | if (!Param_singleton) return 0; |
| 644 | slice_type = make_type("slice", AST_type, NULL, 0); |
| 645 | if (!slice_type) return 0; |
| 646 | if (!add_attributes(slice_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 647 | Ellipsis_type = make_type("Ellipsis", slice_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 648 | if (!Ellipsis_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 649 | Slice_type = make_type("Slice", slice_type, Slice_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 650 | if (!Slice_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 651 | ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 652 | if (!ExtSlice_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 653 | Index_type = make_type("Index", slice_type, Index_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 654 | if (!Index_type) return 0; |
| 655 | boolop_type = make_type("boolop", AST_type, NULL, 0); |
| 656 | if (!boolop_type) return 0; |
| 657 | if (!add_attributes(boolop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 658 | And_type = make_type("And", boolop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 659 | if (!And_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 660 | And_singleton = PyType_GenericNew(And_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 661 | if (!And_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 662 | Or_type = make_type("Or", boolop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 663 | if (!Or_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 664 | Or_singleton = PyType_GenericNew(Or_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 665 | if (!Or_singleton) return 0; |
| 666 | operator_type = make_type("operator", AST_type, NULL, 0); |
| 667 | if (!operator_type) return 0; |
| 668 | if (!add_attributes(operator_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 669 | Add_type = make_type("Add", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 670 | if (!Add_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 671 | Add_singleton = PyType_GenericNew(Add_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 672 | if (!Add_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 673 | Sub_type = make_type("Sub", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 674 | if (!Sub_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 675 | Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 676 | if (!Sub_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 677 | Mult_type = make_type("Mult", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 678 | if (!Mult_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 679 | Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 680 | if (!Mult_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 681 | Div_type = make_type("Div", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 682 | if (!Div_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 683 | Div_singleton = PyType_GenericNew(Div_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 684 | if (!Div_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 685 | Mod_type = make_type("Mod", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 686 | if (!Mod_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 687 | Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 688 | if (!Mod_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 689 | Pow_type = make_type("Pow", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 690 | if (!Pow_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 691 | Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 692 | if (!Pow_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 693 | LShift_type = make_type("LShift", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 694 | if (!LShift_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 695 | LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 696 | if (!LShift_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 697 | RShift_type = make_type("RShift", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 698 | if (!RShift_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 699 | RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 700 | if (!RShift_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 701 | BitOr_type = make_type("BitOr", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 702 | if (!BitOr_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 703 | BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 704 | if (!BitOr_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 705 | BitXor_type = make_type("BitXor", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 706 | if (!BitXor_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 707 | BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 708 | if (!BitXor_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 709 | BitAnd_type = make_type("BitAnd", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 710 | if (!BitAnd_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 711 | BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 712 | if (!BitAnd_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 713 | FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 714 | if (!FloorDiv_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 715 | FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 716 | if (!FloorDiv_singleton) return 0; |
| 717 | unaryop_type = make_type("unaryop", AST_type, NULL, 0); |
| 718 | if (!unaryop_type) return 0; |
| 719 | if (!add_attributes(unaryop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 720 | Invert_type = make_type("Invert", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 721 | if (!Invert_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 722 | Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 723 | if (!Invert_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 724 | Not_type = make_type("Not", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 725 | if (!Not_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 726 | Not_singleton = PyType_GenericNew(Not_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 727 | if (!Not_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 728 | UAdd_type = make_type("UAdd", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 729 | if (!UAdd_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 730 | UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 731 | if (!UAdd_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 732 | USub_type = make_type("USub", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 733 | if (!USub_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 734 | USub_singleton = PyType_GenericNew(USub_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 735 | if (!USub_singleton) return 0; |
| 736 | cmpop_type = make_type("cmpop", AST_type, NULL, 0); |
| 737 | if (!cmpop_type) return 0; |
| 738 | if (!add_attributes(cmpop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 739 | Eq_type = make_type("Eq", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 740 | if (!Eq_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 741 | Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 742 | if (!Eq_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 743 | NotEq_type = make_type("NotEq", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 744 | if (!NotEq_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 745 | NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 746 | if (!NotEq_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 747 | Lt_type = make_type("Lt", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 748 | if (!Lt_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 749 | Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 750 | if (!Lt_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 751 | LtE_type = make_type("LtE", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 752 | if (!LtE_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 753 | LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 754 | if (!LtE_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 755 | Gt_type = make_type("Gt", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 756 | if (!Gt_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 757 | Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 758 | if (!Gt_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 759 | GtE_type = make_type("GtE", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 760 | if (!GtE_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 761 | GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 762 | if (!GtE_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 763 | Is_type = make_type("Is", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 764 | if (!Is_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 765 | Is_singleton = PyType_GenericNew(Is_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 766 | if (!Is_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 767 | IsNot_type = make_type("IsNot", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 768 | if (!IsNot_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 769 | IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 770 | if (!IsNot_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 771 | In_type = make_type("In", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 772 | if (!In_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 773 | In_singleton = PyType_GenericNew(In_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 774 | if (!In_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 775 | NotIn_type = make_type("NotIn", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 776 | if (!NotIn_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 777 | NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 778 | if (!NotIn_singleton) return 0; |
| 779 | comprehension_type = make_type("comprehension", AST_type, |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 780 | comprehension_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 781 | if (!comprehension_type) return 0; |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame^] | 782 | excepthandler_type = make_type("excepthandler", AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 783 | if (!excepthandler_type) return 0; |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame^] | 784 | if (!add_attributes(excepthandler_type, excepthandler_attributes, 2)) |
| 785 | return 0; |
| 786 | ExceptHandler_type = make_type("ExceptHandler", excepthandler_type, |
| 787 | ExceptHandler_fields, 3); |
| 788 | if (!ExceptHandler_type) return 0; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 789 | arguments_type = make_type("arguments", AST_type, arguments_fields, 4); |
| 790 | if (!arguments_type) return 0; |
| 791 | keyword_type = make_type("keyword", AST_type, keyword_fields, 2); |
| 792 | if (!keyword_type) return 0; |
| 793 | alias_type = make_type("alias", AST_type, alias_fields, 2); |
| 794 | if (!alias_type) return 0; |
| 795 | initialized = 1; |
| 796 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 797 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 798 | |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 799 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 800 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 801 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 802 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 803 | arena); |
| 804 | static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena); |
| 805 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 806 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 807 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 808 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 809 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 810 | arena); |
| 811 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 812 | arena); |
| 813 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 814 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 815 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
| 816 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 817 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 818 | Module(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 819 | { |
| 820 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 821 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 822 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 823 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 824 | p->kind = Module_kind; |
| 825 | p->v.Module.body = body; |
| 826 | return p; |
| 827 | } |
| 828 | |
| 829 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 830 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 831 | { |
| 832 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 833 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 834 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 835 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 836 | p->kind = Interactive_kind; |
| 837 | p->v.Interactive.body = body; |
| 838 | return p; |
| 839 | } |
| 840 | |
| 841 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 842 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 843 | { |
| 844 | mod_ty p; |
| 845 | if (!body) { |
| 846 | PyErr_SetString(PyExc_ValueError, |
| 847 | "field body is required for Expression"); |
| 848 | return NULL; |
| 849 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 850 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 851 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 852 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 853 | p->kind = Expression_kind; |
| 854 | p->v.Expression.body = body; |
| 855 | return p; |
| 856 | } |
| 857 | |
| 858 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 859 | Suite(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 860 | { |
| 861 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 862 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 863 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 864 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 865 | p->kind = Suite_kind; |
| 866 | p->v.Suite.body = body; |
| 867 | return p; |
| 868 | } |
| 869 | |
| 870 | stmt_ty |
| 871 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 872 | decorator_list, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 873 | { |
| 874 | stmt_ty p; |
| 875 | if (!name) { |
| 876 | PyErr_SetString(PyExc_ValueError, |
| 877 | "field name is required for FunctionDef"); |
| 878 | return NULL; |
| 879 | } |
| 880 | if (!args) { |
| 881 | PyErr_SetString(PyExc_ValueError, |
| 882 | "field args is required for FunctionDef"); |
| 883 | return NULL; |
| 884 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 885 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 886 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 887 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 888 | p->kind = FunctionDef_kind; |
| 889 | p->v.FunctionDef.name = name; |
| 890 | p->v.FunctionDef.args = args; |
| 891 | p->v.FunctionDef.body = body; |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 892 | p->v.FunctionDef.decorator_list = decorator_list; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 893 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 894 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 895 | return p; |
| 896 | } |
| 897 | |
| 898 | stmt_ty |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 899 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, asdl_seq * |
| 900 | decorator_list, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 901 | { |
| 902 | stmt_ty p; |
| 903 | if (!name) { |
| 904 | PyErr_SetString(PyExc_ValueError, |
| 905 | "field name is required for ClassDef"); |
| 906 | return NULL; |
| 907 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 908 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 909 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 910 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 911 | p->kind = ClassDef_kind; |
| 912 | p->v.ClassDef.name = name; |
| 913 | p->v.ClassDef.bases = bases; |
| 914 | p->v.ClassDef.body = body; |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 915 | p->v.ClassDef.decorator_list = decorator_list; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 916 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 917 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 918 | return p; |
| 919 | } |
| 920 | |
| 921 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 922 | Return(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 923 | { |
| 924 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 925 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 926 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 927 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 928 | p->kind = Return_kind; |
| 929 | p->v.Return.value = value; |
| 930 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 931 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 932 | return p; |
| 933 | } |
| 934 | |
| 935 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 936 | Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 937 | { |
| 938 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 939 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 940 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 941 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 942 | p->kind = Delete_kind; |
| 943 | p->v.Delete.targets = targets; |
| 944 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 945 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 946 | return p; |
| 947 | } |
| 948 | |
| 949 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 950 | Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena |
| 951 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 952 | { |
| 953 | stmt_ty p; |
| 954 | if (!value) { |
| 955 | PyErr_SetString(PyExc_ValueError, |
| 956 | "field value is required for Assign"); |
| 957 | return NULL; |
| 958 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 959 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 960 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 961 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 962 | p->kind = Assign_kind; |
| 963 | p->v.Assign.targets = targets; |
| 964 | p->v.Assign.value = value; |
| 965 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 966 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 967 | return p; |
| 968 | } |
| 969 | |
| 970 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 971 | AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int |
| 972 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 973 | { |
| 974 | stmt_ty p; |
| 975 | if (!target) { |
| 976 | PyErr_SetString(PyExc_ValueError, |
| 977 | "field target is required for AugAssign"); |
| 978 | return NULL; |
| 979 | } |
| 980 | if (!op) { |
| 981 | PyErr_SetString(PyExc_ValueError, |
| 982 | "field op is required for AugAssign"); |
| 983 | return NULL; |
| 984 | } |
| 985 | if (!value) { |
| 986 | PyErr_SetString(PyExc_ValueError, |
| 987 | "field value is required for AugAssign"); |
| 988 | return NULL; |
| 989 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 990 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 991 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 992 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 993 | p->kind = AugAssign_kind; |
| 994 | p->v.AugAssign.target = target; |
| 995 | p->v.AugAssign.op = op; |
| 996 | p->v.AugAssign.value = value; |
| 997 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 998 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 999 | return p; |
| 1000 | } |
| 1001 | |
| 1002 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1003 | Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int col_offset, |
| 1004 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1005 | { |
| 1006 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1007 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1008 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1009 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1010 | p->kind = Print_kind; |
| 1011 | p->v.Print.dest = dest; |
| 1012 | p->v.Print.values = values; |
| 1013 | p->v.Print.nl = nl; |
| 1014 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1015 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1016 | return p; |
| 1017 | } |
| 1018 | |
| 1019 | stmt_ty |
| 1020 | 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] | 1021 | lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1022 | { |
| 1023 | stmt_ty p; |
| 1024 | if (!target) { |
| 1025 | PyErr_SetString(PyExc_ValueError, |
| 1026 | "field target is required for For"); |
| 1027 | return NULL; |
| 1028 | } |
| 1029 | if (!iter) { |
| 1030 | PyErr_SetString(PyExc_ValueError, |
| 1031 | "field iter is required for For"); |
| 1032 | return NULL; |
| 1033 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1034 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1035 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1036 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1037 | p->kind = For_kind; |
| 1038 | p->v.For.target = target; |
| 1039 | p->v.For.iter = iter; |
| 1040 | p->v.For.body = body; |
| 1041 | p->v.For.orelse = orelse; |
| 1042 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1043 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1044 | return p; |
| 1045 | } |
| 1046 | |
| 1047 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1048 | While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1049 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1050 | { |
| 1051 | stmt_ty p; |
| 1052 | if (!test) { |
| 1053 | PyErr_SetString(PyExc_ValueError, |
| 1054 | "field test is required for While"); |
| 1055 | return NULL; |
| 1056 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1057 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1058 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1059 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1060 | p->kind = While_kind; |
| 1061 | p->v.While.test = test; |
| 1062 | p->v.While.body = body; |
| 1063 | p->v.While.orelse = orelse; |
| 1064 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1065 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1066 | return p; |
| 1067 | } |
| 1068 | |
| 1069 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1070 | If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1071 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1072 | { |
| 1073 | stmt_ty p; |
| 1074 | if (!test) { |
| 1075 | PyErr_SetString(PyExc_ValueError, |
| 1076 | "field test is required for If"); |
| 1077 | return NULL; |
| 1078 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1079 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1080 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1081 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1082 | p->kind = If_kind; |
| 1083 | p->v.If.test = test; |
| 1084 | p->v.If.body = body; |
| 1085 | p->v.If.orelse = orelse; |
| 1086 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1087 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1088 | return p; |
| 1089 | } |
| 1090 | |
| 1091 | stmt_ty |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1092 | 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] | 1093 | int col_offset, PyArena *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1094 | { |
| 1095 | stmt_ty p; |
| 1096 | if (!context_expr) { |
| 1097 | PyErr_SetString(PyExc_ValueError, |
| 1098 | "field context_expr is required for With"); |
| 1099 | return NULL; |
| 1100 | } |
| 1101 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1102 | if (!p) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1103 | return NULL; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1104 | p->kind = With_kind; |
| 1105 | p->v.With.context_expr = context_expr; |
| 1106 | p->v.With.optional_vars = optional_vars; |
| 1107 | p->v.With.body = body; |
| 1108 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1109 | p->col_offset = col_offset; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1110 | return p; |
| 1111 | } |
| 1112 | |
| 1113 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1114 | Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset, |
| 1115 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1116 | { |
| 1117 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1118 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1119 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1120 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1121 | p->kind = Raise_kind; |
| 1122 | p->v.Raise.type = type; |
| 1123 | p->v.Raise.inst = inst; |
| 1124 | p->v.Raise.tback = tback; |
| 1125 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1126 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1127 | return p; |
| 1128 | } |
| 1129 | |
| 1130 | stmt_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1131 | 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] | 1132 | int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1133 | { |
| 1134 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1135 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1136 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1137 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1138 | p->kind = TryExcept_kind; |
| 1139 | p->v.TryExcept.body = body; |
| 1140 | p->v.TryExcept.handlers = handlers; |
| 1141 | p->v.TryExcept.orelse = orelse; |
| 1142 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1143 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1144 | return p; |
| 1145 | } |
| 1146 | |
| 1147 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1148 | TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset, |
| 1149 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1150 | { |
| 1151 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1152 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1153 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1154 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1155 | p->kind = TryFinally_kind; |
| 1156 | p->v.TryFinally.body = body; |
| 1157 | p->v.TryFinally.finalbody = finalbody; |
| 1158 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1159 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1160 | return p; |
| 1161 | } |
| 1162 | |
| 1163 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1164 | 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] | 1165 | { |
| 1166 | stmt_ty p; |
| 1167 | if (!test) { |
| 1168 | PyErr_SetString(PyExc_ValueError, |
| 1169 | "field test is required for Assert"); |
| 1170 | return NULL; |
| 1171 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1172 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1173 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1174 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1175 | p->kind = Assert_kind; |
| 1176 | p->v.Assert.test = test; |
| 1177 | p->v.Assert.msg = msg; |
| 1178 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1179 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1180 | return p; |
| 1181 | } |
| 1182 | |
| 1183 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1184 | Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1185 | { |
| 1186 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1187 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1188 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1189 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1190 | p->kind = Import_kind; |
| 1191 | p->v.Import.names = names; |
| 1192 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1193 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1194 | return p; |
| 1195 | } |
| 1196 | |
| 1197 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1198 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
| 1199 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1200 | { |
| 1201 | stmt_ty p; |
| 1202 | if (!module) { |
| 1203 | PyErr_SetString(PyExc_ValueError, |
| 1204 | "field module is required for ImportFrom"); |
| 1205 | return NULL; |
| 1206 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1207 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1208 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1209 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1210 | p->kind = ImportFrom_kind; |
| 1211 | p->v.ImportFrom.module = module; |
| 1212 | p->v.ImportFrom.names = names; |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 1213 | p->v.ImportFrom.level = level; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1214 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1215 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1216 | return p; |
| 1217 | } |
| 1218 | |
| 1219 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1220 | Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, int col_offset, |
| 1221 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1222 | { |
| 1223 | stmt_ty p; |
| 1224 | if (!body) { |
| 1225 | PyErr_SetString(PyExc_ValueError, |
| 1226 | "field body is required for Exec"); |
| 1227 | return NULL; |
| 1228 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1229 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1230 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1231 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1232 | p->kind = Exec_kind; |
| 1233 | p->v.Exec.body = body; |
| 1234 | p->v.Exec.globals = globals; |
| 1235 | p->v.Exec.locals = locals; |
| 1236 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1237 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1238 | return p; |
| 1239 | } |
| 1240 | |
| 1241 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1242 | Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1243 | { |
| 1244 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1245 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1246 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1247 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1248 | p->kind = Global_kind; |
| 1249 | p->v.Global.names = names; |
| 1250 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1251 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1252 | return p; |
| 1253 | } |
| 1254 | |
| 1255 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1256 | Expr(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1257 | { |
| 1258 | stmt_ty p; |
| 1259 | if (!value) { |
| 1260 | PyErr_SetString(PyExc_ValueError, |
| 1261 | "field value is required for Expr"); |
| 1262 | return NULL; |
| 1263 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1264 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1265 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1266 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1267 | p->kind = Expr_kind; |
| 1268 | p->v.Expr.value = value; |
| 1269 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1270 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1271 | return p; |
| 1272 | } |
| 1273 | |
| 1274 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1275 | Pass(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1276 | { |
| 1277 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1278 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1279 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1280 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1281 | p->kind = Pass_kind; |
| 1282 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1283 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1284 | return p; |
| 1285 | } |
| 1286 | |
| 1287 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1288 | Break(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1289 | { |
| 1290 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1291 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1292 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1293 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1294 | p->kind = Break_kind; |
| 1295 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1296 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1297 | return p; |
| 1298 | } |
| 1299 | |
| 1300 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1301 | Continue(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1302 | { |
| 1303 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1304 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1305 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1306 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1307 | p->kind = Continue_kind; |
| 1308 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1309 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1310 | return p; |
| 1311 | } |
| 1312 | |
| 1313 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1314 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1315 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1316 | { |
| 1317 | expr_ty p; |
| 1318 | if (!op) { |
| 1319 | PyErr_SetString(PyExc_ValueError, |
| 1320 | "field op is required for BoolOp"); |
| 1321 | return NULL; |
| 1322 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1323 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1324 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1325 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1326 | p->kind = BoolOp_kind; |
| 1327 | p->v.BoolOp.op = op; |
| 1328 | p->v.BoolOp.values = values; |
| 1329 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1330 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1331 | return p; |
| 1332 | } |
| 1333 | |
| 1334 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1335 | BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset, |
| 1336 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1337 | { |
| 1338 | expr_ty p; |
| 1339 | if (!left) { |
| 1340 | PyErr_SetString(PyExc_ValueError, |
| 1341 | "field left is required for BinOp"); |
| 1342 | return NULL; |
| 1343 | } |
| 1344 | if (!op) { |
| 1345 | PyErr_SetString(PyExc_ValueError, |
| 1346 | "field op is required for BinOp"); |
| 1347 | return NULL; |
| 1348 | } |
| 1349 | if (!right) { |
| 1350 | PyErr_SetString(PyExc_ValueError, |
| 1351 | "field right is required for BinOp"); |
| 1352 | return NULL; |
| 1353 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1354 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1355 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1356 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1357 | p->kind = BinOp_kind; |
| 1358 | p->v.BinOp.left = left; |
| 1359 | p->v.BinOp.op = op; |
| 1360 | p->v.BinOp.right = right; |
| 1361 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1362 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1363 | return p; |
| 1364 | } |
| 1365 | |
| 1366 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1367 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena |
| 1368 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1369 | { |
| 1370 | expr_ty p; |
| 1371 | if (!op) { |
| 1372 | PyErr_SetString(PyExc_ValueError, |
| 1373 | "field op is required for UnaryOp"); |
| 1374 | return NULL; |
| 1375 | } |
| 1376 | if (!operand) { |
| 1377 | PyErr_SetString(PyExc_ValueError, |
| 1378 | "field operand is required for UnaryOp"); |
| 1379 | return NULL; |
| 1380 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1381 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1382 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1383 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1384 | p->kind = UnaryOp_kind; |
| 1385 | p->v.UnaryOp.op = op; |
| 1386 | p->v.UnaryOp.operand = operand; |
| 1387 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1388 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1389 | return p; |
| 1390 | } |
| 1391 | |
| 1392 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1393 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena |
| 1394 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1395 | { |
| 1396 | expr_ty p; |
| 1397 | if (!args) { |
| 1398 | PyErr_SetString(PyExc_ValueError, |
| 1399 | "field args is required for Lambda"); |
| 1400 | return NULL; |
| 1401 | } |
| 1402 | if (!body) { |
| 1403 | PyErr_SetString(PyExc_ValueError, |
| 1404 | "field body is required for Lambda"); |
| 1405 | return NULL; |
| 1406 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1407 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1408 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1409 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1410 | p->kind = Lambda_kind; |
| 1411 | p->v.Lambda.args = args; |
| 1412 | p->v.Lambda.body = body; |
| 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 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1419 | IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset, |
| 1420 | PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1421 | { |
| 1422 | expr_ty p; |
| 1423 | if (!test) { |
| 1424 | PyErr_SetString(PyExc_ValueError, |
| 1425 | "field test is required for IfExp"); |
| 1426 | return NULL; |
| 1427 | } |
| 1428 | if (!body) { |
| 1429 | PyErr_SetString(PyExc_ValueError, |
| 1430 | "field body is required for IfExp"); |
| 1431 | return NULL; |
| 1432 | } |
| 1433 | if (!orelse) { |
| 1434 | PyErr_SetString(PyExc_ValueError, |
| 1435 | "field orelse is required for IfExp"); |
| 1436 | return NULL; |
| 1437 | } |
| 1438 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1439 | if (!p) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1440 | return NULL; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1441 | p->kind = IfExp_kind; |
| 1442 | p->v.IfExp.test = test; |
| 1443 | p->v.IfExp.body = body; |
| 1444 | p->v.IfExp.orelse = orelse; |
| 1445 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1446 | p->col_offset = col_offset; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1447 | return p; |
| 1448 | } |
| 1449 | |
| 1450 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1451 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1452 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1453 | { |
| 1454 | expr_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1455 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1456 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1457 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1458 | p->kind = Dict_kind; |
| 1459 | p->v.Dict.keys = keys; |
| 1460 | p->v.Dict.values = values; |
| 1461 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1462 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1463 | return p; |
| 1464 | } |
| 1465 | |
| 1466 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1467 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1468 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1469 | { |
| 1470 | expr_ty p; |
| 1471 | if (!elt) { |
| 1472 | PyErr_SetString(PyExc_ValueError, |
| 1473 | "field elt is required for ListComp"); |
| 1474 | return NULL; |
| 1475 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1476 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1477 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1478 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1479 | p->kind = ListComp_kind; |
| 1480 | p->v.ListComp.elt = elt; |
| 1481 | p->v.ListComp.generators = generators; |
| 1482 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1483 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1484 | return p; |
| 1485 | } |
| 1486 | |
| 1487 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1488 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1489 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1490 | { |
| 1491 | expr_ty p; |
| 1492 | if (!elt) { |
| 1493 | PyErr_SetString(PyExc_ValueError, |
| 1494 | "field elt is required for GeneratorExp"); |
| 1495 | return NULL; |
| 1496 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1497 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1498 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1499 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1500 | p->kind = GeneratorExp_kind; |
| 1501 | p->v.GeneratorExp.elt = elt; |
| 1502 | p->v.GeneratorExp.generators = generators; |
| 1503 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1504 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1505 | return p; |
| 1506 | } |
| 1507 | |
| 1508 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1509 | Yield(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1510 | { |
| 1511 | expr_ty p; |
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 = Yield_kind; |
| 1516 | p->v.Yield.value = value; |
| 1517 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1518 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1519 | return p; |
| 1520 | } |
| 1521 | |
| 1522 | expr_ty |
Martin v. Löwis | 0cc56e5 | 2006-04-13 12:29:43 +0000 | [diff] [blame] | 1523 | Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno, |
| 1524 | int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1525 | { |
| 1526 | expr_ty p; |
| 1527 | if (!left) { |
| 1528 | PyErr_SetString(PyExc_ValueError, |
| 1529 | "field left is required for Compare"); |
| 1530 | return NULL; |
| 1531 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1532 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1533 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1534 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1535 | p->kind = Compare_kind; |
| 1536 | p->v.Compare.left = left; |
| 1537 | p->v.Compare.ops = ops; |
| 1538 | p->v.Compare.comparators = comparators; |
| 1539 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1540 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1541 | return p; |
| 1542 | } |
| 1543 | |
| 1544 | expr_ty |
| 1545 | 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] | 1546 | expr_ty kwargs, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1547 | { |
| 1548 | expr_ty p; |
| 1549 | if (!func) { |
| 1550 | PyErr_SetString(PyExc_ValueError, |
| 1551 | "field func is required for Call"); |
| 1552 | return NULL; |
| 1553 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1554 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1555 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1556 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1557 | p->kind = Call_kind; |
| 1558 | p->v.Call.func = func; |
| 1559 | p->v.Call.args = args; |
| 1560 | p->v.Call.keywords = keywords; |
| 1561 | p->v.Call.starargs = starargs; |
| 1562 | p->v.Call.kwargs = kwargs; |
| 1563 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1564 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1565 | return p; |
| 1566 | } |
| 1567 | |
| 1568 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1569 | Repr(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1570 | { |
| 1571 | expr_ty p; |
| 1572 | if (!value) { |
| 1573 | PyErr_SetString(PyExc_ValueError, |
| 1574 | "field value is required for Repr"); |
| 1575 | return NULL; |
| 1576 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1577 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1578 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1579 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1580 | p->kind = Repr_kind; |
| 1581 | p->v.Repr.value = value; |
| 1582 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1583 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1584 | return p; |
| 1585 | } |
| 1586 | |
| 1587 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1588 | Num(object n, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1589 | { |
| 1590 | expr_ty p; |
| 1591 | if (!n) { |
| 1592 | PyErr_SetString(PyExc_ValueError, |
| 1593 | "field n is required for Num"); |
| 1594 | return NULL; |
| 1595 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1596 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1597 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1598 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1599 | p->kind = Num_kind; |
| 1600 | p->v.Num.n = n; |
| 1601 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1602 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1603 | return p; |
| 1604 | } |
| 1605 | |
| 1606 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1607 | Str(string s, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1608 | { |
| 1609 | expr_ty p; |
| 1610 | if (!s) { |
| 1611 | PyErr_SetString(PyExc_ValueError, |
| 1612 | "field s is required for Str"); |
| 1613 | return NULL; |
| 1614 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1615 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1616 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1617 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1618 | p->kind = Str_kind; |
| 1619 | p->v.Str.s = s; |
| 1620 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1621 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1622 | return p; |
| 1623 | } |
| 1624 | |
| 1625 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1626 | Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int |
| 1627 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1628 | { |
| 1629 | expr_ty p; |
| 1630 | if (!value) { |
| 1631 | PyErr_SetString(PyExc_ValueError, |
| 1632 | "field value is required for Attribute"); |
| 1633 | return NULL; |
| 1634 | } |
| 1635 | if (!attr) { |
| 1636 | PyErr_SetString(PyExc_ValueError, |
| 1637 | "field attr is required for Attribute"); |
| 1638 | return NULL; |
| 1639 | } |
| 1640 | if (!ctx) { |
| 1641 | PyErr_SetString(PyExc_ValueError, |
| 1642 | "field ctx is required for Attribute"); |
| 1643 | return NULL; |
| 1644 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1645 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1646 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1647 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1648 | p->kind = Attribute_kind; |
| 1649 | p->v.Attribute.value = value; |
| 1650 | p->v.Attribute.attr = attr; |
| 1651 | p->v.Attribute.ctx = ctx; |
| 1652 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1653 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1654 | return p; |
| 1655 | } |
| 1656 | |
| 1657 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1658 | Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int |
| 1659 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1660 | { |
| 1661 | expr_ty p; |
| 1662 | if (!value) { |
| 1663 | PyErr_SetString(PyExc_ValueError, |
| 1664 | "field value is required for Subscript"); |
| 1665 | return NULL; |
| 1666 | } |
| 1667 | if (!slice) { |
| 1668 | PyErr_SetString(PyExc_ValueError, |
| 1669 | "field slice is required for Subscript"); |
| 1670 | return NULL; |
| 1671 | } |
| 1672 | if (!ctx) { |
| 1673 | PyErr_SetString(PyExc_ValueError, |
| 1674 | "field ctx is required for Subscript"); |
| 1675 | return NULL; |
| 1676 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1677 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1678 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1679 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1680 | p->kind = Subscript_kind; |
| 1681 | p->v.Subscript.value = value; |
| 1682 | p->v.Subscript.slice = slice; |
| 1683 | p->v.Subscript.ctx = ctx; |
| 1684 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1685 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1686 | return p; |
| 1687 | } |
| 1688 | |
| 1689 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1690 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1691 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1692 | { |
| 1693 | expr_ty p; |
| 1694 | if (!id) { |
| 1695 | PyErr_SetString(PyExc_ValueError, |
| 1696 | "field id is required for Name"); |
| 1697 | return NULL; |
| 1698 | } |
| 1699 | if (!ctx) { |
| 1700 | PyErr_SetString(PyExc_ValueError, |
| 1701 | "field ctx is required for Name"); |
| 1702 | return NULL; |
| 1703 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1704 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1705 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1706 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1707 | p->kind = Name_kind; |
| 1708 | p->v.Name.id = id; |
| 1709 | p->v.Name.ctx = ctx; |
| 1710 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1711 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1712 | return p; |
| 1713 | } |
| 1714 | |
| 1715 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1716 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1717 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1718 | { |
| 1719 | expr_ty p; |
| 1720 | if (!ctx) { |
| 1721 | PyErr_SetString(PyExc_ValueError, |
| 1722 | "field ctx is required for List"); |
| 1723 | return NULL; |
| 1724 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1725 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1726 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1727 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1728 | p->kind = List_kind; |
| 1729 | p->v.List.elts = elts; |
| 1730 | p->v.List.ctx = ctx; |
| 1731 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1732 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1733 | return p; |
| 1734 | } |
| 1735 | |
| 1736 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1737 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1738 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1739 | { |
| 1740 | expr_ty p; |
| 1741 | if (!ctx) { |
| 1742 | PyErr_SetString(PyExc_ValueError, |
| 1743 | "field ctx is required for Tuple"); |
| 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 = Tuple_kind; |
| 1750 | p->v.Tuple.elts = elts; |
| 1751 | p->v.Tuple.ctx = ctx; |
| 1752 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1753 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1754 | return p; |
| 1755 | } |
| 1756 | |
| 1757 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1758 | Ellipsis(PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1759 | { |
| 1760 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1761 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1762 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1763 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1764 | p->kind = Ellipsis_kind; |
| 1765 | return p; |
| 1766 | } |
| 1767 | |
| 1768 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1769 | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1770 | { |
| 1771 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1772 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1773 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1774 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1775 | p->kind = Slice_kind; |
| 1776 | p->v.Slice.lower = lower; |
| 1777 | p->v.Slice.upper = upper; |
| 1778 | p->v.Slice.step = step; |
| 1779 | return p; |
| 1780 | } |
| 1781 | |
| 1782 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1783 | ExtSlice(asdl_seq * dims, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1784 | { |
| 1785 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1786 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1787 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1788 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1789 | p->kind = ExtSlice_kind; |
| 1790 | p->v.ExtSlice.dims = dims; |
| 1791 | return p; |
| 1792 | } |
| 1793 | |
| 1794 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1795 | Index(expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1796 | { |
| 1797 | slice_ty p; |
| 1798 | if (!value) { |
| 1799 | PyErr_SetString(PyExc_ValueError, |
| 1800 | "field value is required for Index"); |
| 1801 | return NULL; |
| 1802 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1803 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1804 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1805 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1806 | p->kind = Index_kind; |
| 1807 | p->v.Index.value = value; |
| 1808 | return p; |
| 1809 | } |
| 1810 | |
| 1811 | comprehension_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1812 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1813 | { |
| 1814 | comprehension_ty p; |
| 1815 | if (!target) { |
| 1816 | PyErr_SetString(PyExc_ValueError, |
| 1817 | "field target is required for comprehension"); |
| 1818 | return NULL; |
| 1819 | } |
| 1820 | if (!iter) { |
| 1821 | PyErr_SetString(PyExc_ValueError, |
| 1822 | "field iter is required for comprehension"); |
| 1823 | return NULL; |
| 1824 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1825 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1826 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1827 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1828 | p->target = target; |
| 1829 | p->iter = iter; |
| 1830 | p->ifs = ifs; |
| 1831 | return p; |
| 1832 | } |
| 1833 | |
| 1834 | excepthandler_ty |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame^] | 1835 | 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] | 1836 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1837 | { |
| 1838 | excepthandler_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1839 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1840 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1841 | return NULL; |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame^] | 1842 | p->kind = ExceptHandler_kind; |
| 1843 | p->v.ExceptHandler.type = type; |
| 1844 | p->v.ExceptHandler.name = name; |
| 1845 | p->v.ExceptHandler.body = body; |
Jeremy Hylton | 2f327c1 | 2006-04-04 04:00:23 +0000 | [diff] [blame] | 1846 | p->lineno = lineno; |
| 1847 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1848 | return p; |
| 1849 | } |
| 1850 | |
| 1851 | arguments_ty |
| 1852 | arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq * |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1853 | defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1854 | { |
| 1855 | arguments_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1856 | p = (arguments_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->args = args; |
| 1860 | p->vararg = vararg; |
| 1861 | p->kwarg = kwarg; |
| 1862 | p->defaults = defaults; |
| 1863 | return p; |
| 1864 | } |
| 1865 | |
| 1866 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1867 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1868 | { |
| 1869 | keyword_ty p; |
| 1870 | if (!arg) { |
| 1871 | PyErr_SetString(PyExc_ValueError, |
| 1872 | "field arg is required for keyword"); |
| 1873 | return NULL; |
| 1874 | } |
| 1875 | if (!value) { |
| 1876 | PyErr_SetString(PyExc_ValueError, |
| 1877 | "field value is required for keyword"); |
| 1878 | return NULL; |
| 1879 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1880 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1881 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1882 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1883 | p->arg = arg; |
| 1884 | p->value = value; |
| 1885 | return p; |
| 1886 | } |
| 1887 | |
| 1888 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1889 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1890 | { |
| 1891 | alias_ty p; |
| 1892 | if (!name) { |
| 1893 | PyErr_SetString(PyExc_ValueError, |
| 1894 | "field name is required for alias"); |
| 1895 | return NULL; |
| 1896 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1897 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1898 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1899 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1900 | p->name = name; |
| 1901 | p->asname = asname; |
| 1902 | return p; |
| 1903 | } |
| 1904 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 1905 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1906 | PyObject* |
| 1907 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 1908 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1909 | mod_ty o = (mod_ty)_o; |
| 1910 | PyObject *result = NULL, *value = NULL; |
| 1911 | if (!o) { |
| 1912 | Py_INCREF(Py_None); |
| 1913 | return Py_None; |
| 1914 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 1915 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1916 | switch (o->kind) { |
| 1917 | case Module_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1918 | result = PyType_GenericNew(Module_type, NULL, NULL); |
| 1919 | if (!result) goto failed; |
| 1920 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 1921 | if (!value) goto failed; |
| 1922 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 1923 | goto failed; |
| 1924 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1925 | break; |
| 1926 | case Interactive_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1927 | result = PyType_GenericNew(Interactive_type, NULL, NULL); |
| 1928 | if (!result) goto failed; |
| 1929 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 1930 | if (!value) goto failed; |
| 1931 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 1932 | goto failed; |
| 1933 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1934 | break; |
| 1935 | case Expression_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1936 | result = PyType_GenericNew(Expression_type, NULL, NULL); |
| 1937 | if (!result) goto failed; |
| 1938 | value = ast2obj_expr(o->v.Expression.body); |
| 1939 | if (!value) goto failed; |
| 1940 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 1941 | goto failed; |
| 1942 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1943 | break; |
| 1944 | case Suite_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1945 | result = PyType_GenericNew(Suite_type, NULL, NULL); |
| 1946 | if (!result) goto failed; |
| 1947 | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
| 1948 | if (!value) goto failed; |
| 1949 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 1950 | goto failed; |
| 1951 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1952 | break; |
| 1953 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1954 | return result; |
| 1955 | failed: |
| 1956 | Py_XDECREF(value); |
| 1957 | Py_XDECREF(result); |
| 1958 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1959 | } |
| 1960 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1961 | PyObject* |
| 1962 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1963 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1964 | stmt_ty o = (stmt_ty)_o; |
| 1965 | PyObject *result = NULL, *value = NULL; |
| 1966 | if (!o) { |
| 1967 | Py_INCREF(Py_None); |
| 1968 | return Py_None; |
| 1969 | } |
| 1970 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1971 | switch (o->kind) { |
| 1972 | case FunctionDef_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1973 | result = PyType_GenericNew(FunctionDef_type, NULL, NULL); |
| 1974 | if (!result) goto failed; |
| 1975 | value = ast2obj_identifier(o->v.FunctionDef.name); |
| 1976 | if (!value) goto failed; |
| 1977 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 1978 | goto failed; |
| 1979 | Py_DECREF(value); |
| 1980 | value = ast2obj_arguments(o->v.FunctionDef.args); |
| 1981 | if (!value) goto failed; |
| 1982 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 1983 | goto failed; |
| 1984 | Py_DECREF(value); |
| 1985 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 1986 | if (!value) goto failed; |
| 1987 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 1988 | goto failed; |
| 1989 | Py_DECREF(value); |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 1990 | value = ast2obj_list(o->v.FunctionDef.decorator_list, |
| 1991 | ast2obj_expr); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1992 | if (!value) goto failed; |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 1993 | if (PyObject_SetAttrString(result, "decorator_list", value) == |
| 1994 | -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1995 | goto failed; |
| 1996 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1997 | break; |
| 1998 | case ClassDef_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1999 | result = PyType_GenericNew(ClassDef_type, NULL, NULL); |
| 2000 | if (!result) goto failed; |
| 2001 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 2002 | if (!value) goto failed; |
| 2003 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 2004 | goto failed; |
| 2005 | Py_DECREF(value); |
| 2006 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 2007 | if (!value) goto failed; |
| 2008 | if (PyObject_SetAttrString(result, "bases", value) == -1) |
| 2009 | goto failed; |
| 2010 | Py_DECREF(value); |
| 2011 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 2012 | if (!value) goto failed; |
| 2013 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2014 | goto failed; |
| 2015 | Py_DECREF(value); |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 2016 | value = ast2obj_list(o->v.ClassDef.decorator_list, |
| 2017 | ast2obj_expr); |
| 2018 | if (!value) goto failed; |
| 2019 | if (PyObject_SetAttrString(result, "decorator_list", value) == |
| 2020 | -1) |
| 2021 | goto failed; |
| 2022 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2023 | break; |
| 2024 | case Return_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2025 | result = PyType_GenericNew(Return_type, NULL, NULL); |
| 2026 | if (!result) goto failed; |
| 2027 | value = ast2obj_expr(o->v.Return.value); |
| 2028 | if (!value) goto failed; |
| 2029 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2030 | goto failed; |
| 2031 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2032 | break; |
| 2033 | case Delete_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2034 | result = PyType_GenericNew(Delete_type, NULL, NULL); |
| 2035 | if (!result) goto failed; |
| 2036 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 2037 | if (!value) goto failed; |
| 2038 | if (PyObject_SetAttrString(result, "targets", value) == -1) |
| 2039 | goto failed; |
| 2040 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2041 | break; |
| 2042 | case Assign_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2043 | result = PyType_GenericNew(Assign_type, NULL, NULL); |
| 2044 | if (!result) goto failed; |
| 2045 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 2046 | if (!value) goto failed; |
| 2047 | if (PyObject_SetAttrString(result, "targets", value) == -1) |
| 2048 | goto failed; |
| 2049 | Py_DECREF(value); |
| 2050 | value = ast2obj_expr(o->v.Assign.value); |
| 2051 | if (!value) goto failed; |
| 2052 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2053 | goto failed; |
| 2054 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2055 | break; |
| 2056 | case AugAssign_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2057 | result = PyType_GenericNew(AugAssign_type, NULL, NULL); |
| 2058 | if (!result) goto failed; |
| 2059 | value = ast2obj_expr(o->v.AugAssign.target); |
| 2060 | if (!value) goto failed; |
| 2061 | if (PyObject_SetAttrString(result, "target", value) == -1) |
| 2062 | goto failed; |
| 2063 | Py_DECREF(value); |
| 2064 | value = ast2obj_operator(o->v.AugAssign.op); |
| 2065 | if (!value) goto failed; |
| 2066 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2067 | goto failed; |
| 2068 | Py_DECREF(value); |
| 2069 | value = ast2obj_expr(o->v.AugAssign.value); |
| 2070 | if (!value) goto failed; |
| 2071 | if (PyObject_SetAttrString(result, "value", 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 Print_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2076 | result = PyType_GenericNew(Print_type, NULL, NULL); |
| 2077 | if (!result) goto failed; |
| 2078 | value = ast2obj_expr(o->v.Print.dest); |
| 2079 | if (!value) goto failed; |
| 2080 | if (PyObject_SetAttrString(result, "dest", value) == -1) |
| 2081 | goto failed; |
| 2082 | Py_DECREF(value); |
| 2083 | value = ast2obj_list(o->v.Print.values, ast2obj_expr); |
| 2084 | if (!value) goto failed; |
| 2085 | if (PyObject_SetAttrString(result, "values", value) == -1) |
| 2086 | goto failed; |
| 2087 | Py_DECREF(value); |
| 2088 | value = ast2obj_bool(o->v.Print.nl); |
| 2089 | if (!value) goto failed; |
| 2090 | if (PyObject_SetAttrString(result, "nl", value) == -1) |
| 2091 | goto failed; |
| 2092 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2093 | break; |
| 2094 | case For_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2095 | result = PyType_GenericNew(For_type, NULL, NULL); |
| 2096 | if (!result) goto failed; |
| 2097 | value = ast2obj_expr(o->v.For.target); |
| 2098 | if (!value) goto failed; |
| 2099 | if (PyObject_SetAttrString(result, "target", value) == -1) |
| 2100 | goto failed; |
| 2101 | Py_DECREF(value); |
| 2102 | value = ast2obj_expr(o->v.For.iter); |
| 2103 | if (!value) goto failed; |
| 2104 | if (PyObject_SetAttrString(result, "iter", value) == -1) |
| 2105 | goto failed; |
| 2106 | Py_DECREF(value); |
| 2107 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 2108 | if (!value) goto failed; |
| 2109 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2110 | goto failed; |
| 2111 | Py_DECREF(value); |
| 2112 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 2113 | if (!value) goto failed; |
| 2114 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2115 | goto failed; |
| 2116 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2117 | break; |
| 2118 | case While_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2119 | result = PyType_GenericNew(While_type, NULL, NULL); |
| 2120 | if (!result) goto failed; |
| 2121 | value = ast2obj_expr(o->v.While.test); |
| 2122 | if (!value) goto failed; |
| 2123 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2124 | goto failed; |
| 2125 | Py_DECREF(value); |
| 2126 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 2127 | if (!value) goto failed; |
| 2128 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2129 | goto failed; |
| 2130 | Py_DECREF(value); |
| 2131 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 2132 | if (!value) goto failed; |
| 2133 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2134 | goto failed; |
| 2135 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2136 | break; |
| 2137 | case If_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2138 | result = PyType_GenericNew(If_type, NULL, NULL); |
| 2139 | if (!result) goto failed; |
| 2140 | value = ast2obj_expr(o->v.If.test); |
| 2141 | if (!value) goto failed; |
| 2142 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2143 | goto failed; |
| 2144 | Py_DECREF(value); |
| 2145 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 2146 | if (!value) goto failed; |
| 2147 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2148 | goto failed; |
| 2149 | Py_DECREF(value); |
| 2150 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 2151 | if (!value) goto failed; |
| 2152 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2153 | goto failed; |
| 2154 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2155 | break; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2156 | case With_kind: |
| 2157 | result = PyType_GenericNew(With_type, NULL, NULL); |
| 2158 | if (!result) goto failed; |
| 2159 | value = ast2obj_expr(o->v.With.context_expr); |
| 2160 | if (!value) goto failed; |
| 2161 | if (PyObject_SetAttrString(result, "context_expr", value) == -1) |
| 2162 | goto failed; |
| 2163 | Py_DECREF(value); |
| 2164 | value = ast2obj_expr(o->v.With.optional_vars); |
| 2165 | if (!value) goto failed; |
| 2166 | if (PyObject_SetAttrString(result, "optional_vars", value) == |
| 2167 | -1) |
| 2168 | goto failed; |
| 2169 | Py_DECREF(value); |
| 2170 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 2171 | if (!value) goto failed; |
| 2172 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2173 | goto failed; |
| 2174 | Py_DECREF(value); |
| 2175 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2176 | case Raise_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2177 | result = PyType_GenericNew(Raise_type, NULL, NULL); |
| 2178 | if (!result) goto failed; |
| 2179 | value = ast2obj_expr(o->v.Raise.type); |
| 2180 | if (!value) goto failed; |
| 2181 | if (PyObject_SetAttrString(result, "type", value) == -1) |
| 2182 | goto failed; |
| 2183 | Py_DECREF(value); |
| 2184 | value = ast2obj_expr(o->v.Raise.inst); |
| 2185 | if (!value) goto failed; |
| 2186 | if (PyObject_SetAttrString(result, "inst", value) == -1) |
| 2187 | goto failed; |
| 2188 | Py_DECREF(value); |
| 2189 | value = ast2obj_expr(o->v.Raise.tback); |
| 2190 | if (!value) goto failed; |
| 2191 | if (PyObject_SetAttrString(result, "tback", value) == -1) |
| 2192 | goto failed; |
| 2193 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2194 | break; |
| 2195 | case TryExcept_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2196 | result = PyType_GenericNew(TryExcept_type, NULL, NULL); |
| 2197 | if (!result) goto failed; |
| 2198 | value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt); |
| 2199 | if (!value) goto failed; |
| 2200 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2201 | goto failed; |
| 2202 | Py_DECREF(value); |
| 2203 | value = ast2obj_list(o->v.TryExcept.handlers, |
| 2204 | ast2obj_excepthandler); |
| 2205 | if (!value) goto failed; |
| 2206 | if (PyObject_SetAttrString(result, "handlers", value) == -1) |
| 2207 | goto failed; |
| 2208 | Py_DECREF(value); |
| 2209 | value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt); |
| 2210 | if (!value) goto failed; |
| 2211 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2212 | goto failed; |
| 2213 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2214 | break; |
| 2215 | case TryFinally_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2216 | result = PyType_GenericNew(TryFinally_type, NULL, NULL); |
| 2217 | if (!result) goto failed; |
| 2218 | value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt); |
| 2219 | if (!value) goto failed; |
| 2220 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2221 | goto failed; |
| 2222 | Py_DECREF(value); |
| 2223 | value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt); |
| 2224 | if (!value) goto failed; |
| 2225 | if (PyObject_SetAttrString(result, "finalbody", value) == -1) |
| 2226 | goto failed; |
| 2227 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2228 | break; |
| 2229 | case Assert_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2230 | result = PyType_GenericNew(Assert_type, NULL, NULL); |
| 2231 | if (!result) goto failed; |
| 2232 | value = ast2obj_expr(o->v.Assert.test); |
| 2233 | if (!value) goto failed; |
| 2234 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2235 | goto failed; |
| 2236 | Py_DECREF(value); |
| 2237 | value = ast2obj_expr(o->v.Assert.msg); |
| 2238 | if (!value) goto failed; |
| 2239 | if (PyObject_SetAttrString(result, "msg", value) == -1) |
| 2240 | goto failed; |
| 2241 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2242 | break; |
| 2243 | case Import_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2244 | result = PyType_GenericNew(Import_type, NULL, NULL); |
| 2245 | if (!result) goto failed; |
| 2246 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 2247 | if (!value) goto failed; |
| 2248 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2249 | goto failed; |
| 2250 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2251 | break; |
| 2252 | case ImportFrom_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2253 | result = PyType_GenericNew(ImportFrom_type, NULL, NULL); |
| 2254 | if (!result) goto failed; |
| 2255 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 2256 | if (!value) goto failed; |
| 2257 | if (PyObject_SetAttrString(result, "module", value) == -1) |
| 2258 | goto failed; |
| 2259 | Py_DECREF(value); |
| 2260 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 2261 | if (!value) goto failed; |
| 2262 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2263 | goto failed; |
| 2264 | Py_DECREF(value); |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 2265 | value = ast2obj_int(o->v.ImportFrom.level); |
| 2266 | if (!value) goto failed; |
| 2267 | if (PyObject_SetAttrString(result, "level", value) == -1) |
| 2268 | goto failed; |
| 2269 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2270 | break; |
| 2271 | case Exec_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2272 | result = PyType_GenericNew(Exec_type, NULL, NULL); |
| 2273 | if (!result) goto failed; |
| 2274 | value = ast2obj_expr(o->v.Exec.body); |
| 2275 | if (!value) goto failed; |
| 2276 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2277 | goto failed; |
| 2278 | Py_DECREF(value); |
| 2279 | value = ast2obj_expr(o->v.Exec.globals); |
| 2280 | if (!value) goto failed; |
| 2281 | if (PyObject_SetAttrString(result, "globals", value) == -1) |
| 2282 | goto failed; |
| 2283 | Py_DECREF(value); |
| 2284 | value = ast2obj_expr(o->v.Exec.locals); |
| 2285 | if (!value) goto failed; |
| 2286 | if (PyObject_SetAttrString(result, "locals", value) == -1) |
| 2287 | goto failed; |
| 2288 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2289 | break; |
| 2290 | case Global_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2291 | result = PyType_GenericNew(Global_type, NULL, NULL); |
| 2292 | if (!result) goto failed; |
| 2293 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 2294 | if (!value) goto failed; |
| 2295 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2296 | goto failed; |
| 2297 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2298 | break; |
| 2299 | case Expr_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2300 | result = PyType_GenericNew(Expr_type, NULL, NULL); |
| 2301 | if (!result) goto failed; |
| 2302 | value = ast2obj_expr(o->v.Expr.value); |
| 2303 | if (!value) goto failed; |
| 2304 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2305 | goto failed; |
| 2306 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2307 | break; |
| 2308 | case Pass_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2309 | result = PyType_GenericNew(Pass_type, NULL, NULL); |
| 2310 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2311 | break; |
| 2312 | case Break_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2313 | result = PyType_GenericNew(Break_type, NULL, NULL); |
| 2314 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2315 | break; |
| 2316 | case Continue_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2317 | result = PyType_GenericNew(Continue_type, NULL, NULL); |
| 2318 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2319 | break; |
| 2320 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2321 | value = ast2obj_int(o->lineno); |
| 2322 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2323 | if (PyObject_SetAttrString(result, "lineno", value) < 0) |
| 2324 | goto failed; |
| 2325 | Py_DECREF(value); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2326 | value = ast2obj_int(o->col_offset); |
| 2327 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2328 | if (PyObject_SetAttrString(result, "col_offset", value) < 0) |
| 2329 | goto failed; |
| 2330 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2331 | return result; |
| 2332 | failed: |
| 2333 | Py_XDECREF(value); |
| 2334 | Py_XDECREF(result); |
| 2335 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2336 | } |
| 2337 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2338 | PyObject* |
| 2339 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2340 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2341 | expr_ty o = (expr_ty)_o; |
| 2342 | PyObject *result = NULL, *value = NULL; |
| 2343 | if (!o) { |
| 2344 | Py_INCREF(Py_None); |
| 2345 | return Py_None; |
| 2346 | } |
| 2347 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2348 | switch (o->kind) { |
| 2349 | case BoolOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2350 | result = PyType_GenericNew(BoolOp_type, NULL, NULL); |
| 2351 | if (!result) goto failed; |
| 2352 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 2353 | if (!value) goto failed; |
| 2354 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2355 | goto failed; |
| 2356 | Py_DECREF(value); |
| 2357 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 2358 | if (!value) goto failed; |
| 2359 | if (PyObject_SetAttrString(result, "values", value) == -1) |
| 2360 | goto failed; |
| 2361 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2362 | break; |
| 2363 | case BinOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2364 | result = PyType_GenericNew(BinOp_type, NULL, NULL); |
| 2365 | if (!result) goto failed; |
| 2366 | value = ast2obj_expr(o->v.BinOp.left); |
| 2367 | if (!value) goto failed; |
| 2368 | if (PyObject_SetAttrString(result, "left", value) == -1) |
| 2369 | goto failed; |
| 2370 | Py_DECREF(value); |
| 2371 | value = ast2obj_operator(o->v.BinOp.op); |
| 2372 | if (!value) goto failed; |
| 2373 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2374 | goto failed; |
| 2375 | Py_DECREF(value); |
| 2376 | value = ast2obj_expr(o->v.BinOp.right); |
| 2377 | if (!value) goto failed; |
| 2378 | if (PyObject_SetAttrString(result, "right", value) == -1) |
| 2379 | goto failed; |
| 2380 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2381 | break; |
| 2382 | case UnaryOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2383 | result = PyType_GenericNew(UnaryOp_type, NULL, NULL); |
| 2384 | if (!result) goto failed; |
| 2385 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 2386 | if (!value) goto failed; |
| 2387 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2388 | goto failed; |
| 2389 | Py_DECREF(value); |
| 2390 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 2391 | if (!value) goto failed; |
| 2392 | if (PyObject_SetAttrString(result, "operand", value) == -1) |
| 2393 | goto failed; |
| 2394 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2395 | break; |
| 2396 | case Lambda_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2397 | result = PyType_GenericNew(Lambda_type, NULL, NULL); |
| 2398 | if (!result) goto failed; |
| 2399 | value = ast2obj_arguments(o->v.Lambda.args); |
| 2400 | if (!value) goto failed; |
| 2401 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 2402 | goto failed; |
| 2403 | Py_DECREF(value); |
| 2404 | value = ast2obj_expr(o->v.Lambda.body); |
| 2405 | if (!value) goto failed; |
| 2406 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2407 | goto failed; |
| 2408 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2409 | break; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2410 | case IfExp_kind: |
| 2411 | result = PyType_GenericNew(IfExp_type, NULL, NULL); |
| 2412 | if (!result) goto failed; |
| 2413 | value = ast2obj_expr(o->v.IfExp.test); |
| 2414 | if (!value) goto failed; |
| 2415 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2416 | goto failed; |
| 2417 | Py_DECREF(value); |
| 2418 | value = ast2obj_expr(o->v.IfExp.body); |
| 2419 | if (!value) goto failed; |
| 2420 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2421 | goto failed; |
| 2422 | Py_DECREF(value); |
| 2423 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 2424 | if (!value) goto failed; |
| 2425 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2426 | goto failed; |
| 2427 | Py_DECREF(value); |
| 2428 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2429 | case Dict_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2430 | result = PyType_GenericNew(Dict_type, NULL, NULL); |
| 2431 | if (!result) goto failed; |
| 2432 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 2433 | if (!value) goto failed; |
| 2434 | if (PyObject_SetAttrString(result, "keys", value) == -1) |
| 2435 | goto failed; |
| 2436 | Py_DECREF(value); |
| 2437 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 2438 | if (!value) goto failed; |
| 2439 | if (PyObject_SetAttrString(result, "values", value) == -1) |
| 2440 | goto failed; |
| 2441 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2442 | break; |
| 2443 | case ListComp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2444 | result = PyType_GenericNew(ListComp_type, NULL, NULL); |
| 2445 | if (!result) goto failed; |
| 2446 | value = ast2obj_expr(o->v.ListComp.elt); |
| 2447 | if (!value) goto failed; |
| 2448 | if (PyObject_SetAttrString(result, "elt", value) == -1) |
| 2449 | goto failed; |
| 2450 | Py_DECREF(value); |
| 2451 | value = ast2obj_list(o->v.ListComp.generators, |
| 2452 | ast2obj_comprehension); |
| 2453 | if (!value) goto failed; |
| 2454 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2455 | goto failed; |
| 2456 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2457 | break; |
| 2458 | case GeneratorExp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2459 | result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); |
| 2460 | if (!result) goto failed; |
| 2461 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 2462 | if (!value) goto failed; |
| 2463 | if (PyObject_SetAttrString(result, "elt", value) == -1) |
| 2464 | goto failed; |
| 2465 | Py_DECREF(value); |
| 2466 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 2467 | ast2obj_comprehension); |
| 2468 | if (!value) goto failed; |
| 2469 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2470 | goto failed; |
| 2471 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2472 | break; |
| 2473 | case Yield_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2474 | result = PyType_GenericNew(Yield_type, NULL, NULL); |
| 2475 | if (!result) goto failed; |
| 2476 | value = ast2obj_expr(o->v.Yield.value); |
| 2477 | if (!value) goto failed; |
| 2478 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2479 | goto failed; |
| 2480 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2481 | break; |
| 2482 | case Compare_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2483 | result = PyType_GenericNew(Compare_type, NULL, NULL); |
| 2484 | if (!result) goto failed; |
| 2485 | value = ast2obj_expr(o->v.Compare.left); |
| 2486 | if (!value) goto failed; |
| 2487 | if (PyObject_SetAttrString(result, "left", value) == -1) |
| 2488 | goto failed; |
| 2489 | Py_DECREF(value); |
Martin v. Löwis | ce1d5d2 | 2006-02-26 20:51:25 +0000 | [diff] [blame] | 2490 | { |
| 2491 | int i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 2492 | value = PyList_New(n); |
| 2493 | if (!value) goto failed; |
| 2494 | for(i = 0; i < n; i++) |
Martin v. Löwis | 0cc56e5 | 2006-04-13 12:29:43 +0000 | [diff] [blame] | 2495 | 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] | 2496 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2497 | if (!value) goto failed; |
| 2498 | if (PyObject_SetAttrString(result, "ops", value) == -1) |
| 2499 | goto failed; |
| 2500 | Py_DECREF(value); |
| 2501 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
| 2502 | if (!value) goto failed; |
| 2503 | if (PyObject_SetAttrString(result, "comparators", value) == -1) |
| 2504 | goto failed; |
| 2505 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2506 | break; |
| 2507 | case Call_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2508 | result = PyType_GenericNew(Call_type, NULL, NULL); |
| 2509 | if (!result) goto failed; |
| 2510 | value = ast2obj_expr(o->v.Call.func); |
| 2511 | if (!value) goto failed; |
| 2512 | if (PyObject_SetAttrString(result, "func", value) == -1) |
| 2513 | goto failed; |
| 2514 | Py_DECREF(value); |
| 2515 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 2516 | if (!value) goto failed; |
| 2517 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 2518 | goto failed; |
| 2519 | Py_DECREF(value); |
| 2520 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 2521 | if (!value) goto failed; |
| 2522 | if (PyObject_SetAttrString(result, "keywords", value) == -1) |
| 2523 | goto failed; |
| 2524 | Py_DECREF(value); |
| 2525 | value = ast2obj_expr(o->v.Call.starargs); |
| 2526 | if (!value) goto failed; |
| 2527 | if (PyObject_SetAttrString(result, "starargs", value) == -1) |
| 2528 | goto failed; |
| 2529 | Py_DECREF(value); |
| 2530 | value = ast2obj_expr(o->v.Call.kwargs); |
| 2531 | if (!value) goto failed; |
| 2532 | if (PyObject_SetAttrString(result, "kwargs", value) == -1) |
| 2533 | goto failed; |
| 2534 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2535 | break; |
| 2536 | case Repr_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2537 | result = PyType_GenericNew(Repr_type, NULL, NULL); |
| 2538 | if (!result) goto failed; |
| 2539 | value = ast2obj_expr(o->v.Repr.value); |
| 2540 | if (!value) goto failed; |
| 2541 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2542 | goto failed; |
| 2543 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2544 | break; |
| 2545 | case Num_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2546 | result = PyType_GenericNew(Num_type, NULL, NULL); |
| 2547 | if (!result) goto failed; |
| 2548 | value = ast2obj_object(o->v.Num.n); |
| 2549 | if (!value) goto failed; |
| 2550 | if (PyObject_SetAttrString(result, "n", value) == -1) |
| 2551 | goto failed; |
| 2552 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2553 | break; |
| 2554 | case Str_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2555 | result = PyType_GenericNew(Str_type, NULL, NULL); |
| 2556 | if (!result) goto failed; |
| 2557 | value = ast2obj_string(o->v.Str.s); |
| 2558 | if (!value) goto failed; |
| 2559 | if (PyObject_SetAttrString(result, "s", value) == -1) |
| 2560 | goto failed; |
| 2561 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2562 | break; |
| 2563 | case Attribute_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2564 | result = PyType_GenericNew(Attribute_type, NULL, NULL); |
| 2565 | if (!result) goto failed; |
| 2566 | value = ast2obj_expr(o->v.Attribute.value); |
| 2567 | if (!value) goto failed; |
| 2568 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2569 | goto failed; |
| 2570 | Py_DECREF(value); |
| 2571 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 2572 | if (!value) goto failed; |
| 2573 | if (PyObject_SetAttrString(result, "attr", value) == -1) |
| 2574 | goto failed; |
| 2575 | Py_DECREF(value); |
| 2576 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 2577 | if (!value) goto failed; |
| 2578 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2579 | goto failed; |
| 2580 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2581 | break; |
| 2582 | case Subscript_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2583 | result = PyType_GenericNew(Subscript_type, NULL, NULL); |
| 2584 | if (!result) goto failed; |
| 2585 | value = ast2obj_expr(o->v.Subscript.value); |
| 2586 | if (!value) goto failed; |
| 2587 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2588 | goto failed; |
| 2589 | Py_DECREF(value); |
| 2590 | value = ast2obj_slice(o->v.Subscript.slice); |
| 2591 | if (!value) goto failed; |
| 2592 | if (PyObject_SetAttrString(result, "slice", value) == -1) |
| 2593 | goto failed; |
| 2594 | Py_DECREF(value); |
| 2595 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 2596 | if (!value) goto failed; |
| 2597 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2598 | goto failed; |
| 2599 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2600 | break; |
| 2601 | case Name_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2602 | result = PyType_GenericNew(Name_type, NULL, NULL); |
| 2603 | if (!result) goto failed; |
| 2604 | value = ast2obj_identifier(o->v.Name.id); |
| 2605 | if (!value) goto failed; |
| 2606 | if (PyObject_SetAttrString(result, "id", value) == -1) |
| 2607 | goto failed; |
| 2608 | Py_DECREF(value); |
| 2609 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 2610 | if (!value) goto failed; |
| 2611 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2612 | goto failed; |
| 2613 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2614 | break; |
| 2615 | case List_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2616 | result = PyType_GenericNew(List_type, NULL, NULL); |
| 2617 | if (!result) goto failed; |
| 2618 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 2619 | if (!value) goto failed; |
| 2620 | if (PyObject_SetAttrString(result, "elts", value) == -1) |
| 2621 | goto failed; |
| 2622 | Py_DECREF(value); |
| 2623 | value = ast2obj_expr_context(o->v.List.ctx); |
| 2624 | if (!value) goto failed; |
| 2625 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2626 | goto failed; |
| 2627 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2628 | break; |
| 2629 | case Tuple_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2630 | result = PyType_GenericNew(Tuple_type, NULL, NULL); |
| 2631 | if (!result) goto failed; |
| 2632 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 2633 | if (!value) goto failed; |
| 2634 | if (PyObject_SetAttrString(result, "elts", value) == -1) |
| 2635 | goto failed; |
| 2636 | Py_DECREF(value); |
| 2637 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 2638 | if (!value) goto failed; |
| 2639 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2640 | goto failed; |
| 2641 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2642 | break; |
| 2643 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2644 | value = ast2obj_int(o->lineno); |
| 2645 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2646 | if (PyObject_SetAttrString(result, "lineno", value) < 0) |
| 2647 | goto failed; |
| 2648 | Py_DECREF(value); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2649 | value = ast2obj_int(o->col_offset); |
| 2650 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2651 | if (PyObject_SetAttrString(result, "col_offset", value) < 0) |
| 2652 | goto failed; |
| 2653 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2654 | return result; |
| 2655 | failed: |
| 2656 | Py_XDECREF(value); |
| 2657 | Py_XDECREF(result); |
| 2658 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2659 | } |
| 2660 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2661 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2662 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2663 | switch(o) { |
| 2664 | case Load: |
| 2665 | Py_INCREF(Load_singleton); |
| 2666 | return Load_singleton; |
| 2667 | case Store: |
| 2668 | Py_INCREF(Store_singleton); |
| 2669 | return Store_singleton; |
| 2670 | case Del: |
| 2671 | Py_INCREF(Del_singleton); |
| 2672 | return Del_singleton; |
| 2673 | case AugLoad: |
| 2674 | Py_INCREF(AugLoad_singleton); |
| 2675 | return AugLoad_singleton; |
| 2676 | case AugStore: |
| 2677 | Py_INCREF(AugStore_singleton); |
| 2678 | return AugStore_singleton; |
| 2679 | case Param: |
| 2680 | Py_INCREF(Param_singleton); |
| 2681 | return Param_singleton; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 2682 | default: |
| 2683 | /* should never happen, but just in case ... */ |
| 2684 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 2685 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2686 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2687 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2688 | PyObject* |
| 2689 | ast2obj_slice(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2690 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2691 | slice_ty o = (slice_ty)_o; |
| 2692 | PyObject *result = NULL, *value = NULL; |
| 2693 | if (!o) { |
| 2694 | Py_INCREF(Py_None); |
| 2695 | return Py_None; |
| 2696 | } |
| 2697 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2698 | switch (o->kind) { |
| 2699 | case Ellipsis_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2700 | result = PyType_GenericNew(Ellipsis_type, NULL, NULL); |
| 2701 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2702 | break; |
| 2703 | case Slice_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2704 | result = PyType_GenericNew(Slice_type, NULL, NULL); |
| 2705 | if (!result) goto failed; |
| 2706 | value = ast2obj_expr(o->v.Slice.lower); |
| 2707 | if (!value) goto failed; |
| 2708 | if (PyObject_SetAttrString(result, "lower", value) == -1) |
| 2709 | goto failed; |
| 2710 | Py_DECREF(value); |
| 2711 | value = ast2obj_expr(o->v.Slice.upper); |
| 2712 | if (!value) goto failed; |
| 2713 | if (PyObject_SetAttrString(result, "upper", value) == -1) |
| 2714 | goto failed; |
| 2715 | Py_DECREF(value); |
| 2716 | value = ast2obj_expr(o->v.Slice.step); |
| 2717 | if (!value) goto failed; |
| 2718 | if (PyObject_SetAttrString(result, "step", value) == -1) |
| 2719 | goto failed; |
| 2720 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2721 | break; |
| 2722 | case ExtSlice_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2723 | result = PyType_GenericNew(ExtSlice_type, NULL, NULL); |
| 2724 | if (!result) goto failed; |
| 2725 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 2726 | if (!value) goto failed; |
| 2727 | if (PyObject_SetAttrString(result, "dims", value) == -1) |
| 2728 | goto failed; |
| 2729 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2730 | break; |
| 2731 | case Index_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2732 | result = PyType_GenericNew(Index_type, NULL, NULL); |
| 2733 | if (!result) goto failed; |
| 2734 | value = ast2obj_expr(o->v.Index.value); |
| 2735 | if (!value) goto failed; |
| 2736 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2737 | goto failed; |
| 2738 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2739 | break; |
| 2740 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2741 | return result; |
| 2742 | failed: |
| 2743 | Py_XDECREF(value); |
| 2744 | Py_XDECREF(result); |
| 2745 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2746 | } |
| 2747 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2748 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2749 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2750 | switch(o) { |
| 2751 | case And: |
| 2752 | Py_INCREF(And_singleton); |
| 2753 | return And_singleton; |
| 2754 | case Or: |
| 2755 | Py_INCREF(Or_singleton); |
| 2756 | return Or_singleton; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 2757 | default: |
| 2758 | /* should never happen, but just in case ... */ |
| 2759 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 2760 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2761 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2762 | } |
| 2763 | PyObject* ast2obj_operator(operator_ty o) |
| 2764 | { |
| 2765 | switch(o) { |
| 2766 | case Add: |
| 2767 | Py_INCREF(Add_singleton); |
| 2768 | return Add_singleton; |
| 2769 | case Sub: |
| 2770 | Py_INCREF(Sub_singleton); |
| 2771 | return Sub_singleton; |
| 2772 | case Mult: |
| 2773 | Py_INCREF(Mult_singleton); |
| 2774 | return Mult_singleton; |
| 2775 | case Div: |
| 2776 | Py_INCREF(Div_singleton); |
| 2777 | return Div_singleton; |
| 2778 | case Mod: |
| 2779 | Py_INCREF(Mod_singleton); |
| 2780 | return Mod_singleton; |
| 2781 | case Pow: |
| 2782 | Py_INCREF(Pow_singleton); |
| 2783 | return Pow_singleton; |
| 2784 | case LShift: |
| 2785 | Py_INCREF(LShift_singleton); |
| 2786 | return LShift_singleton; |
| 2787 | case RShift: |
| 2788 | Py_INCREF(RShift_singleton); |
| 2789 | return RShift_singleton; |
| 2790 | case BitOr: |
| 2791 | Py_INCREF(BitOr_singleton); |
| 2792 | return BitOr_singleton; |
| 2793 | case BitXor: |
| 2794 | Py_INCREF(BitXor_singleton); |
| 2795 | return BitXor_singleton; |
| 2796 | case BitAnd: |
| 2797 | Py_INCREF(BitAnd_singleton); |
| 2798 | return BitAnd_singleton; |
| 2799 | case FloorDiv: |
| 2800 | Py_INCREF(FloorDiv_singleton); |
| 2801 | return FloorDiv_singleton; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 2802 | default: |
| 2803 | /* should never happen, but just in case ... */ |
| 2804 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 2805 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2806 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2807 | } |
| 2808 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 2809 | { |
| 2810 | switch(o) { |
| 2811 | case Invert: |
| 2812 | Py_INCREF(Invert_singleton); |
| 2813 | return Invert_singleton; |
| 2814 | case Not: |
| 2815 | Py_INCREF(Not_singleton); |
| 2816 | return Not_singleton; |
| 2817 | case UAdd: |
| 2818 | Py_INCREF(UAdd_singleton); |
| 2819 | return UAdd_singleton; |
| 2820 | case USub: |
| 2821 | Py_INCREF(USub_singleton); |
| 2822 | return USub_singleton; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 2823 | default: |
| 2824 | /* should never happen, but just in case ... */ |
| 2825 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 2826 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2827 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2828 | } |
| 2829 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 2830 | { |
| 2831 | switch(o) { |
| 2832 | case Eq: |
| 2833 | Py_INCREF(Eq_singleton); |
| 2834 | return Eq_singleton; |
| 2835 | case NotEq: |
| 2836 | Py_INCREF(NotEq_singleton); |
| 2837 | return NotEq_singleton; |
| 2838 | case Lt: |
| 2839 | Py_INCREF(Lt_singleton); |
| 2840 | return Lt_singleton; |
| 2841 | case LtE: |
| 2842 | Py_INCREF(LtE_singleton); |
| 2843 | return LtE_singleton; |
| 2844 | case Gt: |
| 2845 | Py_INCREF(Gt_singleton); |
| 2846 | return Gt_singleton; |
| 2847 | case GtE: |
| 2848 | Py_INCREF(GtE_singleton); |
| 2849 | return GtE_singleton; |
| 2850 | case Is: |
| 2851 | Py_INCREF(Is_singleton); |
| 2852 | return Is_singleton; |
| 2853 | case IsNot: |
| 2854 | Py_INCREF(IsNot_singleton); |
| 2855 | return IsNot_singleton; |
| 2856 | case In: |
| 2857 | Py_INCREF(In_singleton); |
| 2858 | return In_singleton; |
| 2859 | case NotIn: |
| 2860 | Py_INCREF(NotIn_singleton); |
| 2861 | return NotIn_singleton; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 2862 | default: |
| 2863 | /* should never happen, but just in case ... */ |
| 2864 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 2865 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2866 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2867 | } |
| 2868 | PyObject* |
| 2869 | ast2obj_comprehension(void* _o) |
| 2870 | { |
| 2871 | comprehension_ty o = (comprehension_ty)_o; |
| 2872 | PyObject *result = NULL, *value = NULL; |
| 2873 | if (!o) { |
| 2874 | Py_INCREF(Py_None); |
| 2875 | return Py_None; |
| 2876 | } |
| 2877 | |
| 2878 | result = PyType_GenericNew(comprehension_type, NULL, NULL); |
| 2879 | if (!result) return NULL; |
| 2880 | value = ast2obj_expr(o->target); |
| 2881 | if (!value) goto failed; |
| 2882 | if (PyObject_SetAttrString(result, "target", value) == -1) |
| 2883 | goto failed; |
| 2884 | Py_DECREF(value); |
| 2885 | value = ast2obj_expr(o->iter); |
| 2886 | if (!value) goto failed; |
| 2887 | if (PyObject_SetAttrString(result, "iter", value) == -1) |
| 2888 | goto failed; |
| 2889 | Py_DECREF(value); |
| 2890 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 2891 | if (!value) goto failed; |
| 2892 | if (PyObject_SetAttrString(result, "ifs", value) == -1) |
| 2893 | goto failed; |
| 2894 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2895 | return result; |
| 2896 | failed: |
| 2897 | Py_XDECREF(value); |
| 2898 | Py_XDECREF(result); |
| 2899 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2900 | } |
| 2901 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2902 | PyObject* |
| 2903 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2904 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2905 | excepthandler_ty o = (excepthandler_ty)_o; |
| 2906 | PyObject *result = NULL, *value = NULL; |
| 2907 | if (!o) { |
| 2908 | Py_INCREF(Py_None); |
| 2909 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2910 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2911 | |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame^] | 2912 | switch (o->kind) { |
| 2913 | case ExceptHandler_kind: |
| 2914 | result = PyType_GenericNew(ExceptHandler_type, NULL, NULL); |
| 2915 | if (!result) goto failed; |
| 2916 | value = ast2obj_expr(o->v.ExceptHandler.type); |
| 2917 | if (!value) goto failed; |
| 2918 | if (PyObject_SetAttrString(result, "type", value) == -1) |
| 2919 | goto failed; |
| 2920 | Py_DECREF(value); |
| 2921 | value = ast2obj_expr(o->v.ExceptHandler.name); |
| 2922 | if (!value) goto failed; |
| 2923 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 2924 | goto failed; |
| 2925 | Py_DECREF(value); |
| 2926 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 2927 | if (!value) goto failed; |
| 2928 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2929 | goto failed; |
| 2930 | Py_DECREF(value); |
| 2931 | break; |
| 2932 | } |
Jeremy Hylton | 2f327c1 | 2006-04-04 04:00:23 +0000 | [diff] [blame] | 2933 | value = ast2obj_int(o->lineno); |
| 2934 | if (!value) goto failed; |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame^] | 2935 | if (PyObject_SetAttrString(result, "lineno", value) < 0) |
Jeremy Hylton | 2f327c1 | 2006-04-04 04:00:23 +0000 | [diff] [blame] | 2936 | goto failed; |
| 2937 | Py_DECREF(value); |
| 2938 | value = ast2obj_int(o->col_offset); |
| 2939 | if (!value) goto failed; |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame^] | 2940 | if (PyObject_SetAttrString(result, "col_offset", value) < 0) |
Jeremy Hylton | 2f327c1 | 2006-04-04 04:00:23 +0000 | [diff] [blame] | 2941 | goto failed; |
| 2942 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2943 | return result; |
| 2944 | failed: |
| 2945 | Py_XDECREF(value); |
| 2946 | Py_XDECREF(result); |
| 2947 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2948 | } |
| 2949 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2950 | PyObject* |
| 2951 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2952 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2953 | arguments_ty o = (arguments_ty)_o; |
| 2954 | PyObject *result = NULL, *value = NULL; |
| 2955 | if (!o) { |
| 2956 | Py_INCREF(Py_None); |
| 2957 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2958 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2959 | |
| 2960 | result = PyType_GenericNew(arguments_type, NULL, NULL); |
| 2961 | if (!result) return NULL; |
| 2962 | value = ast2obj_list(o->args, ast2obj_expr); |
| 2963 | if (!value) goto failed; |
| 2964 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 2965 | goto failed; |
| 2966 | Py_DECREF(value); |
| 2967 | value = ast2obj_identifier(o->vararg); |
| 2968 | if (!value) goto failed; |
| 2969 | if (PyObject_SetAttrString(result, "vararg", value) == -1) |
| 2970 | goto failed; |
| 2971 | Py_DECREF(value); |
| 2972 | value = ast2obj_identifier(o->kwarg); |
| 2973 | if (!value) goto failed; |
| 2974 | if (PyObject_SetAttrString(result, "kwarg", value) == -1) |
| 2975 | goto failed; |
| 2976 | Py_DECREF(value); |
| 2977 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 2978 | if (!value) goto failed; |
| 2979 | if (PyObject_SetAttrString(result, "defaults", value) == -1) |
| 2980 | goto failed; |
| 2981 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2982 | return result; |
| 2983 | failed: |
| 2984 | Py_XDECREF(value); |
| 2985 | Py_XDECREF(result); |
| 2986 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2987 | } |
| 2988 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2989 | PyObject* |
| 2990 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2991 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2992 | keyword_ty o = (keyword_ty)_o; |
| 2993 | PyObject *result = NULL, *value = NULL; |
| 2994 | if (!o) { |
| 2995 | Py_INCREF(Py_None); |
| 2996 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2997 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2998 | |
| 2999 | result = PyType_GenericNew(keyword_type, NULL, NULL); |
| 3000 | if (!result) return NULL; |
| 3001 | value = ast2obj_identifier(o->arg); |
| 3002 | if (!value) goto failed; |
| 3003 | if (PyObject_SetAttrString(result, "arg", value) == -1) |
| 3004 | goto failed; |
| 3005 | Py_DECREF(value); |
| 3006 | value = ast2obj_expr(o->value); |
| 3007 | if (!value) goto failed; |
| 3008 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 3009 | goto failed; |
| 3010 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3011 | return result; |
| 3012 | failed: |
| 3013 | Py_XDECREF(value); |
| 3014 | Py_XDECREF(result); |
| 3015 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3016 | } |
| 3017 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3018 | PyObject* |
| 3019 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3020 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3021 | alias_ty o = (alias_ty)_o; |
| 3022 | PyObject *result = NULL, *value = NULL; |
| 3023 | if (!o) { |
| 3024 | Py_INCREF(Py_None); |
| 3025 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3026 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3027 | |
| 3028 | result = PyType_GenericNew(alias_type, NULL, NULL); |
| 3029 | if (!result) return NULL; |
| 3030 | value = ast2obj_identifier(o->name); |
| 3031 | if (!value) goto failed; |
| 3032 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 3033 | goto failed; |
| 3034 | Py_DECREF(value); |
| 3035 | value = ast2obj_identifier(o->asname); |
| 3036 | if (!value) goto failed; |
| 3037 | if (PyObject_SetAttrString(result, "asname", value) == -1) |
| 3038 | goto failed; |
| 3039 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3040 | return result; |
| 3041 | failed: |
| 3042 | Py_XDECREF(value); |
| 3043 | Py_XDECREF(result); |
| 3044 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3045 | } |
| 3046 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3047 | |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3048 | int |
| 3049 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 3050 | { |
| 3051 | PyObject* tmp = NULL; |
| 3052 | |
| 3053 | |
| 3054 | if (obj == Py_None) { |
| 3055 | *out = NULL; |
| 3056 | return 0; |
| 3057 | } |
| 3058 | if (PyObject_IsInstance(obj, (PyObject*)Module_type)) { |
| 3059 | asdl_seq* body; |
| 3060 | |
| 3061 | if (PyObject_HasAttrString(obj, "body")) { |
| 3062 | int res; |
| 3063 | Py_ssize_t len; |
| 3064 | Py_ssize_t i; |
| 3065 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3066 | if (tmp == NULL) goto failed; |
| 3067 | if (!PyList_Check(tmp)) { |
| 3068 | PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3069 | goto failed; |
| 3070 | } |
| 3071 | len = PyList_GET_SIZE(tmp); |
| 3072 | body = asdl_seq_new(len, arena); |
| 3073 | if (body == NULL) goto failed; |
| 3074 | for (i = 0; i < len; i++) { |
| 3075 | stmt_ty value; |
| 3076 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3077 | if (res != 0) goto failed; |
| 3078 | asdl_seq_SET(body, i, value); |
| 3079 | } |
| 3080 | Py_XDECREF(tmp); |
| 3081 | tmp = NULL; |
| 3082 | } else { |
| 3083 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 3084 | return 1; |
| 3085 | } |
| 3086 | *out = Module(body, arena); |
| 3087 | if (*out == NULL) goto failed; |
| 3088 | return 0; |
| 3089 | } |
| 3090 | if (PyObject_IsInstance(obj, (PyObject*)Interactive_type)) { |
| 3091 | asdl_seq* body; |
| 3092 | |
| 3093 | if (PyObject_HasAttrString(obj, "body")) { |
| 3094 | int res; |
| 3095 | Py_ssize_t len; |
| 3096 | Py_ssize_t i; |
| 3097 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3098 | if (tmp == NULL) goto failed; |
| 3099 | if (!PyList_Check(tmp)) { |
| 3100 | PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3101 | goto failed; |
| 3102 | } |
| 3103 | len = PyList_GET_SIZE(tmp); |
| 3104 | body = asdl_seq_new(len, arena); |
| 3105 | if (body == NULL) goto failed; |
| 3106 | for (i = 0; i < len; i++) { |
| 3107 | stmt_ty value; |
| 3108 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3109 | if (res != 0) goto failed; |
| 3110 | asdl_seq_SET(body, i, value); |
| 3111 | } |
| 3112 | Py_XDECREF(tmp); |
| 3113 | tmp = NULL; |
| 3114 | } else { |
| 3115 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 3116 | return 1; |
| 3117 | } |
| 3118 | *out = Interactive(body, arena); |
| 3119 | if (*out == NULL) goto failed; |
| 3120 | return 0; |
| 3121 | } |
| 3122 | if (PyObject_IsInstance(obj, (PyObject*)Expression_type)) { |
| 3123 | expr_ty body; |
| 3124 | |
| 3125 | if (PyObject_HasAttrString(obj, "body")) { |
| 3126 | int res; |
| 3127 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3128 | if (tmp == NULL) goto failed; |
| 3129 | res = obj2ast_expr(tmp, &body, arena); |
| 3130 | if (res != 0) goto failed; |
| 3131 | Py_XDECREF(tmp); |
| 3132 | tmp = NULL; |
| 3133 | } else { |
| 3134 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 3135 | return 1; |
| 3136 | } |
| 3137 | *out = Expression(body, arena); |
| 3138 | if (*out == NULL) goto failed; |
| 3139 | return 0; |
| 3140 | } |
| 3141 | if (PyObject_IsInstance(obj, (PyObject*)Suite_type)) { |
| 3142 | asdl_seq* body; |
| 3143 | |
| 3144 | if (PyObject_HasAttrString(obj, "body")) { |
| 3145 | int res; |
| 3146 | Py_ssize_t len; |
| 3147 | Py_ssize_t i; |
| 3148 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3149 | if (tmp == NULL) goto failed; |
| 3150 | if (!PyList_Check(tmp)) { |
| 3151 | PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3152 | goto failed; |
| 3153 | } |
| 3154 | len = PyList_GET_SIZE(tmp); |
| 3155 | body = asdl_seq_new(len, arena); |
| 3156 | if (body == NULL) goto failed; |
| 3157 | for (i = 0; i < len; i++) { |
| 3158 | stmt_ty value; |
| 3159 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3160 | if (res != 0) goto failed; |
| 3161 | asdl_seq_SET(body, i, value); |
| 3162 | } |
| 3163 | Py_XDECREF(tmp); |
| 3164 | tmp = NULL; |
| 3165 | } else { |
| 3166 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite"); |
| 3167 | return 1; |
| 3168 | } |
| 3169 | *out = Suite(body, arena); |
| 3170 | if (*out == NULL) goto failed; |
| 3171 | return 0; |
| 3172 | } |
| 3173 | |
| 3174 | tmp = PyObject_Repr(obj); |
| 3175 | if (tmp == NULL) goto failed; |
| 3176 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %.400s", PyString_AS_STRING(tmp)); |
| 3177 | failed: |
| 3178 | Py_XDECREF(tmp); |
| 3179 | return 1; |
| 3180 | } |
| 3181 | |
| 3182 | int |
| 3183 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 3184 | { |
| 3185 | PyObject* tmp = NULL; |
| 3186 | |
| 3187 | int lineno; |
| 3188 | int col_offset; |
| 3189 | |
| 3190 | if (obj == Py_None) { |
| 3191 | *out = NULL; |
| 3192 | return 0; |
| 3193 | } |
| 3194 | if (PyObject_HasAttrString(obj, "lineno")) { |
| 3195 | int res; |
| 3196 | tmp = PyObject_GetAttrString(obj, "lineno"); |
| 3197 | if (tmp == NULL) goto failed; |
| 3198 | res = obj2ast_int(tmp, &lineno, arena); |
| 3199 | if (res != 0) goto failed; |
| 3200 | Py_XDECREF(tmp); |
| 3201 | tmp = NULL; |
| 3202 | } else { |
| 3203 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 3204 | return 1; |
| 3205 | } |
| 3206 | if (PyObject_HasAttrString(obj, "col_offset")) { |
| 3207 | int res; |
| 3208 | tmp = PyObject_GetAttrString(obj, "col_offset"); |
| 3209 | if (tmp == NULL) goto failed; |
| 3210 | res = obj2ast_int(tmp, &col_offset, arena); |
| 3211 | if (res != 0) goto failed; |
| 3212 | Py_XDECREF(tmp); |
| 3213 | tmp = NULL; |
| 3214 | } else { |
| 3215 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 3216 | return 1; |
| 3217 | } |
| 3218 | if (PyObject_IsInstance(obj, (PyObject*)FunctionDef_type)) { |
| 3219 | identifier name; |
| 3220 | arguments_ty args; |
| 3221 | asdl_seq* body; |
| 3222 | asdl_seq* decorator_list; |
| 3223 | |
| 3224 | if (PyObject_HasAttrString(obj, "name")) { |
| 3225 | int res; |
| 3226 | tmp = PyObject_GetAttrString(obj, "name"); |
| 3227 | if (tmp == NULL) goto failed; |
| 3228 | res = obj2ast_identifier(tmp, &name, arena); |
| 3229 | if (res != 0) goto failed; |
| 3230 | Py_XDECREF(tmp); |
| 3231 | tmp = NULL; |
| 3232 | } else { |
| 3233 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 3234 | return 1; |
| 3235 | } |
| 3236 | if (PyObject_HasAttrString(obj, "args")) { |
| 3237 | int res; |
| 3238 | tmp = PyObject_GetAttrString(obj, "args"); |
| 3239 | if (tmp == NULL) goto failed; |
| 3240 | res = obj2ast_arguments(tmp, &args, arena); |
| 3241 | if (res != 0) goto failed; |
| 3242 | Py_XDECREF(tmp); |
| 3243 | tmp = NULL; |
| 3244 | } else { |
| 3245 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 3246 | return 1; |
| 3247 | } |
| 3248 | if (PyObject_HasAttrString(obj, "body")) { |
| 3249 | int res; |
| 3250 | Py_ssize_t len; |
| 3251 | Py_ssize_t i; |
| 3252 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3253 | if (tmp == NULL) goto failed; |
| 3254 | if (!PyList_Check(tmp)) { |
| 3255 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3256 | goto failed; |
| 3257 | } |
| 3258 | len = PyList_GET_SIZE(tmp); |
| 3259 | body = asdl_seq_new(len, arena); |
| 3260 | if (body == NULL) goto failed; |
| 3261 | for (i = 0; i < len; i++) { |
| 3262 | stmt_ty value; |
| 3263 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3264 | if (res != 0) goto failed; |
| 3265 | asdl_seq_SET(body, i, value); |
| 3266 | } |
| 3267 | Py_XDECREF(tmp); |
| 3268 | tmp = NULL; |
| 3269 | } else { |
| 3270 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 3271 | return 1; |
| 3272 | } |
| 3273 | if (PyObject_HasAttrString(obj, "decorator_list")) { |
| 3274 | int res; |
| 3275 | Py_ssize_t len; |
| 3276 | Py_ssize_t i; |
| 3277 | tmp = PyObject_GetAttrString(obj, "decorator_list"); |
| 3278 | if (tmp == NULL) goto failed; |
| 3279 | if (!PyList_Check(tmp)) { |
| 3280 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3281 | goto failed; |
| 3282 | } |
| 3283 | len = PyList_GET_SIZE(tmp); |
| 3284 | decorator_list = asdl_seq_new(len, arena); |
| 3285 | if (decorator_list == NULL) goto failed; |
| 3286 | for (i = 0; i < len; i++) { |
| 3287 | expr_ty value; |
| 3288 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3289 | if (res != 0) goto failed; |
| 3290 | asdl_seq_SET(decorator_list, i, value); |
| 3291 | } |
| 3292 | Py_XDECREF(tmp); |
| 3293 | tmp = NULL; |
| 3294 | } else { |
| 3295 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 3296 | return 1; |
| 3297 | } |
| 3298 | *out = FunctionDef(name, args, body, decorator_list, lineno, |
| 3299 | col_offset, arena); |
| 3300 | if (*out == NULL) goto failed; |
| 3301 | return 0; |
| 3302 | } |
| 3303 | if (PyObject_IsInstance(obj, (PyObject*)ClassDef_type)) { |
| 3304 | identifier name; |
| 3305 | asdl_seq* bases; |
| 3306 | asdl_seq* body; |
| 3307 | asdl_seq* decorator_list; |
| 3308 | |
| 3309 | if (PyObject_HasAttrString(obj, "name")) { |
| 3310 | int res; |
| 3311 | tmp = PyObject_GetAttrString(obj, "name"); |
| 3312 | if (tmp == NULL) goto failed; |
| 3313 | res = obj2ast_identifier(tmp, &name, arena); |
| 3314 | if (res != 0) goto failed; |
| 3315 | Py_XDECREF(tmp); |
| 3316 | tmp = NULL; |
| 3317 | } else { |
| 3318 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 3319 | return 1; |
| 3320 | } |
| 3321 | if (PyObject_HasAttrString(obj, "bases")) { |
| 3322 | int res; |
| 3323 | Py_ssize_t len; |
| 3324 | Py_ssize_t i; |
| 3325 | tmp = PyObject_GetAttrString(obj, "bases"); |
| 3326 | if (tmp == NULL) goto failed; |
| 3327 | if (!PyList_Check(tmp)) { |
| 3328 | PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3329 | goto failed; |
| 3330 | } |
| 3331 | len = PyList_GET_SIZE(tmp); |
| 3332 | bases = asdl_seq_new(len, arena); |
| 3333 | if (bases == NULL) goto failed; |
| 3334 | for (i = 0; i < len; i++) { |
| 3335 | expr_ty value; |
| 3336 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3337 | if (res != 0) goto failed; |
| 3338 | asdl_seq_SET(bases, i, value); |
| 3339 | } |
| 3340 | Py_XDECREF(tmp); |
| 3341 | tmp = NULL; |
| 3342 | } else { |
| 3343 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 3344 | return 1; |
| 3345 | } |
| 3346 | if (PyObject_HasAttrString(obj, "body")) { |
| 3347 | int res; |
| 3348 | Py_ssize_t len; |
| 3349 | Py_ssize_t i; |
| 3350 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3351 | if (tmp == NULL) goto failed; |
| 3352 | if (!PyList_Check(tmp)) { |
| 3353 | PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3354 | goto failed; |
| 3355 | } |
| 3356 | len = PyList_GET_SIZE(tmp); |
| 3357 | body = asdl_seq_new(len, arena); |
| 3358 | if (body == NULL) goto failed; |
| 3359 | for (i = 0; i < len; i++) { |
| 3360 | stmt_ty value; |
| 3361 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3362 | if (res != 0) goto failed; |
| 3363 | asdl_seq_SET(body, i, value); |
| 3364 | } |
| 3365 | Py_XDECREF(tmp); |
| 3366 | tmp = NULL; |
| 3367 | } else { |
| 3368 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 3369 | return 1; |
| 3370 | } |
| 3371 | if (PyObject_HasAttrString(obj, "decorator_list")) { |
| 3372 | int res; |
| 3373 | Py_ssize_t len; |
| 3374 | Py_ssize_t i; |
| 3375 | tmp = PyObject_GetAttrString(obj, "decorator_list"); |
| 3376 | if (tmp == NULL) goto failed; |
| 3377 | if (!PyList_Check(tmp)) { |
| 3378 | PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3379 | goto failed; |
| 3380 | } |
| 3381 | len = PyList_GET_SIZE(tmp); |
| 3382 | decorator_list = asdl_seq_new(len, arena); |
| 3383 | if (decorator_list == NULL) goto failed; |
| 3384 | for (i = 0; i < len; i++) { |
| 3385 | expr_ty value; |
| 3386 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3387 | if (res != 0) goto failed; |
| 3388 | asdl_seq_SET(decorator_list, i, value); |
| 3389 | } |
| 3390 | Py_XDECREF(tmp); |
| 3391 | tmp = NULL; |
| 3392 | } else { |
| 3393 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 3394 | return 1; |
| 3395 | } |
| 3396 | *out = ClassDef(name, bases, body, decorator_list, lineno, |
| 3397 | col_offset, arena); |
| 3398 | if (*out == NULL) goto failed; |
| 3399 | return 0; |
| 3400 | } |
| 3401 | if (PyObject_IsInstance(obj, (PyObject*)Return_type)) { |
| 3402 | expr_ty value; |
| 3403 | |
| 3404 | if (PyObject_HasAttrString(obj, "value")) { |
| 3405 | int res; |
| 3406 | tmp = PyObject_GetAttrString(obj, "value"); |
| 3407 | if (tmp == NULL) goto failed; |
| 3408 | res = obj2ast_expr(tmp, &value, arena); |
| 3409 | if (res != 0) goto failed; |
| 3410 | Py_XDECREF(tmp); |
| 3411 | tmp = NULL; |
| 3412 | } else { |
| 3413 | value = NULL; |
| 3414 | } |
| 3415 | *out = Return(value, lineno, col_offset, arena); |
| 3416 | if (*out == NULL) goto failed; |
| 3417 | return 0; |
| 3418 | } |
| 3419 | if (PyObject_IsInstance(obj, (PyObject*)Delete_type)) { |
| 3420 | asdl_seq* targets; |
| 3421 | |
| 3422 | if (PyObject_HasAttrString(obj, "targets")) { |
| 3423 | int res; |
| 3424 | Py_ssize_t len; |
| 3425 | Py_ssize_t i; |
| 3426 | tmp = PyObject_GetAttrString(obj, "targets"); |
| 3427 | if (tmp == NULL) goto failed; |
| 3428 | if (!PyList_Check(tmp)) { |
| 3429 | PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3430 | goto failed; |
| 3431 | } |
| 3432 | len = PyList_GET_SIZE(tmp); |
| 3433 | targets = asdl_seq_new(len, arena); |
| 3434 | if (targets == NULL) goto failed; |
| 3435 | for (i = 0; i < len; i++) { |
| 3436 | expr_ty value; |
| 3437 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3438 | if (res != 0) goto failed; |
| 3439 | asdl_seq_SET(targets, i, value); |
| 3440 | } |
| 3441 | Py_XDECREF(tmp); |
| 3442 | tmp = NULL; |
| 3443 | } else { |
| 3444 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 3445 | return 1; |
| 3446 | } |
| 3447 | *out = Delete(targets, lineno, col_offset, arena); |
| 3448 | if (*out == NULL) goto failed; |
| 3449 | return 0; |
| 3450 | } |
| 3451 | if (PyObject_IsInstance(obj, (PyObject*)Assign_type)) { |
| 3452 | asdl_seq* targets; |
| 3453 | expr_ty value; |
| 3454 | |
| 3455 | if (PyObject_HasAttrString(obj, "targets")) { |
| 3456 | int res; |
| 3457 | Py_ssize_t len; |
| 3458 | Py_ssize_t i; |
| 3459 | tmp = PyObject_GetAttrString(obj, "targets"); |
| 3460 | if (tmp == NULL) goto failed; |
| 3461 | if (!PyList_Check(tmp)) { |
| 3462 | PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3463 | goto failed; |
| 3464 | } |
| 3465 | len = PyList_GET_SIZE(tmp); |
| 3466 | targets = asdl_seq_new(len, arena); |
| 3467 | if (targets == NULL) goto failed; |
| 3468 | for (i = 0; i < len; i++) { |
| 3469 | expr_ty value; |
| 3470 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3471 | if (res != 0) goto failed; |
| 3472 | asdl_seq_SET(targets, i, value); |
| 3473 | } |
| 3474 | Py_XDECREF(tmp); |
| 3475 | tmp = NULL; |
| 3476 | } else { |
| 3477 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 3478 | return 1; |
| 3479 | } |
| 3480 | if (PyObject_HasAttrString(obj, "value")) { |
| 3481 | int res; |
| 3482 | tmp = PyObject_GetAttrString(obj, "value"); |
| 3483 | if (tmp == NULL) goto failed; |
| 3484 | res = obj2ast_expr(tmp, &value, arena); |
| 3485 | if (res != 0) goto failed; |
| 3486 | Py_XDECREF(tmp); |
| 3487 | tmp = NULL; |
| 3488 | } else { |
| 3489 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 3490 | return 1; |
| 3491 | } |
| 3492 | *out = Assign(targets, value, lineno, col_offset, arena); |
| 3493 | if (*out == NULL) goto failed; |
| 3494 | return 0; |
| 3495 | } |
| 3496 | if (PyObject_IsInstance(obj, (PyObject*)AugAssign_type)) { |
| 3497 | expr_ty target; |
| 3498 | operator_ty op; |
| 3499 | expr_ty value; |
| 3500 | |
| 3501 | if (PyObject_HasAttrString(obj, "target")) { |
| 3502 | int res; |
| 3503 | tmp = PyObject_GetAttrString(obj, "target"); |
| 3504 | if (tmp == NULL) goto failed; |
| 3505 | res = obj2ast_expr(tmp, &target, arena); |
| 3506 | if (res != 0) goto failed; |
| 3507 | Py_XDECREF(tmp); |
| 3508 | tmp = NULL; |
| 3509 | } else { |
| 3510 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 3511 | return 1; |
| 3512 | } |
| 3513 | if (PyObject_HasAttrString(obj, "op")) { |
| 3514 | int res; |
| 3515 | tmp = PyObject_GetAttrString(obj, "op"); |
| 3516 | if (tmp == NULL) goto failed; |
| 3517 | res = obj2ast_operator(tmp, &op, arena); |
| 3518 | if (res != 0) goto failed; |
| 3519 | Py_XDECREF(tmp); |
| 3520 | tmp = NULL; |
| 3521 | } else { |
| 3522 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 3523 | return 1; |
| 3524 | } |
| 3525 | if (PyObject_HasAttrString(obj, "value")) { |
| 3526 | int res; |
| 3527 | tmp = PyObject_GetAttrString(obj, "value"); |
| 3528 | if (tmp == NULL) goto failed; |
| 3529 | res = obj2ast_expr(tmp, &value, arena); |
| 3530 | if (res != 0) goto failed; |
| 3531 | Py_XDECREF(tmp); |
| 3532 | tmp = NULL; |
| 3533 | } else { |
| 3534 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 3535 | return 1; |
| 3536 | } |
| 3537 | *out = AugAssign(target, op, value, lineno, col_offset, arena); |
| 3538 | if (*out == NULL) goto failed; |
| 3539 | return 0; |
| 3540 | } |
| 3541 | if (PyObject_IsInstance(obj, (PyObject*)Print_type)) { |
| 3542 | expr_ty dest; |
| 3543 | asdl_seq* values; |
| 3544 | bool nl; |
| 3545 | |
| 3546 | if (PyObject_HasAttrString(obj, "dest")) { |
| 3547 | int res; |
| 3548 | tmp = PyObject_GetAttrString(obj, "dest"); |
| 3549 | if (tmp == NULL) goto failed; |
| 3550 | res = obj2ast_expr(tmp, &dest, arena); |
| 3551 | if (res != 0) goto failed; |
| 3552 | Py_XDECREF(tmp); |
| 3553 | tmp = NULL; |
| 3554 | } else { |
| 3555 | dest = NULL; |
| 3556 | } |
| 3557 | if (PyObject_HasAttrString(obj, "values")) { |
| 3558 | int res; |
| 3559 | Py_ssize_t len; |
| 3560 | Py_ssize_t i; |
| 3561 | tmp = PyObject_GetAttrString(obj, "values"); |
| 3562 | if (tmp == NULL) goto failed; |
| 3563 | if (!PyList_Check(tmp)) { |
| 3564 | PyErr_Format(PyExc_TypeError, "Print field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3565 | goto failed; |
| 3566 | } |
| 3567 | len = PyList_GET_SIZE(tmp); |
| 3568 | values = asdl_seq_new(len, arena); |
| 3569 | if (values == NULL) goto failed; |
| 3570 | for (i = 0; i < len; i++) { |
| 3571 | expr_ty value; |
| 3572 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3573 | if (res != 0) goto failed; |
| 3574 | asdl_seq_SET(values, i, value); |
| 3575 | } |
| 3576 | Py_XDECREF(tmp); |
| 3577 | tmp = NULL; |
| 3578 | } else { |
| 3579 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Print"); |
| 3580 | return 1; |
| 3581 | } |
| 3582 | if (PyObject_HasAttrString(obj, "nl")) { |
| 3583 | int res; |
| 3584 | tmp = PyObject_GetAttrString(obj, "nl"); |
| 3585 | if (tmp == NULL) goto failed; |
| 3586 | res = obj2ast_bool(tmp, &nl, arena); |
| 3587 | if (res != 0) goto failed; |
| 3588 | Py_XDECREF(tmp); |
| 3589 | tmp = NULL; |
| 3590 | } else { |
| 3591 | PyErr_SetString(PyExc_TypeError, "required field \"nl\" missing from Print"); |
| 3592 | return 1; |
| 3593 | } |
| 3594 | *out = Print(dest, values, nl, lineno, col_offset, arena); |
| 3595 | if (*out == NULL) goto failed; |
| 3596 | return 0; |
| 3597 | } |
| 3598 | if (PyObject_IsInstance(obj, (PyObject*)For_type)) { |
| 3599 | expr_ty target; |
| 3600 | expr_ty iter; |
| 3601 | asdl_seq* body; |
| 3602 | asdl_seq* orelse; |
| 3603 | |
| 3604 | if (PyObject_HasAttrString(obj, "target")) { |
| 3605 | int res; |
| 3606 | tmp = PyObject_GetAttrString(obj, "target"); |
| 3607 | if (tmp == NULL) goto failed; |
| 3608 | res = obj2ast_expr(tmp, &target, arena); |
| 3609 | if (res != 0) goto failed; |
| 3610 | Py_XDECREF(tmp); |
| 3611 | tmp = NULL; |
| 3612 | } else { |
| 3613 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 3614 | return 1; |
| 3615 | } |
| 3616 | if (PyObject_HasAttrString(obj, "iter")) { |
| 3617 | int res; |
| 3618 | tmp = PyObject_GetAttrString(obj, "iter"); |
| 3619 | if (tmp == NULL) goto failed; |
| 3620 | res = obj2ast_expr(tmp, &iter, arena); |
| 3621 | if (res != 0) goto failed; |
| 3622 | Py_XDECREF(tmp); |
| 3623 | tmp = NULL; |
| 3624 | } else { |
| 3625 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 3626 | return 1; |
| 3627 | } |
| 3628 | if (PyObject_HasAttrString(obj, "body")) { |
| 3629 | int res; |
| 3630 | Py_ssize_t len; |
| 3631 | Py_ssize_t i; |
| 3632 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3633 | if (tmp == NULL) goto failed; |
| 3634 | if (!PyList_Check(tmp)) { |
| 3635 | PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3636 | goto failed; |
| 3637 | } |
| 3638 | len = PyList_GET_SIZE(tmp); |
| 3639 | body = asdl_seq_new(len, arena); |
| 3640 | if (body == NULL) goto failed; |
| 3641 | for (i = 0; i < len; i++) { |
| 3642 | stmt_ty value; |
| 3643 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3644 | if (res != 0) goto failed; |
| 3645 | asdl_seq_SET(body, i, value); |
| 3646 | } |
| 3647 | Py_XDECREF(tmp); |
| 3648 | tmp = NULL; |
| 3649 | } else { |
| 3650 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 3651 | return 1; |
| 3652 | } |
| 3653 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 3654 | int res; |
| 3655 | Py_ssize_t len; |
| 3656 | Py_ssize_t i; |
| 3657 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 3658 | if (tmp == NULL) goto failed; |
| 3659 | if (!PyList_Check(tmp)) { |
| 3660 | PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3661 | goto failed; |
| 3662 | } |
| 3663 | len = PyList_GET_SIZE(tmp); |
| 3664 | orelse = asdl_seq_new(len, arena); |
| 3665 | if (orelse == NULL) goto failed; |
| 3666 | for (i = 0; i < len; i++) { |
| 3667 | stmt_ty value; |
| 3668 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3669 | if (res != 0) goto failed; |
| 3670 | asdl_seq_SET(orelse, i, value); |
| 3671 | } |
| 3672 | Py_XDECREF(tmp); |
| 3673 | tmp = NULL; |
| 3674 | } else { |
| 3675 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 3676 | return 1; |
| 3677 | } |
| 3678 | *out = For(target, iter, body, orelse, lineno, col_offset, |
| 3679 | arena); |
| 3680 | if (*out == NULL) goto failed; |
| 3681 | return 0; |
| 3682 | } |
| 3683 | if (PyObject_IsInstance(obj, (PyObject*)While_type)) { |
| 3684 | expr_ty test; |
| 3685 | asdl_seq* body; |
| 3686 | asdl_seq* orelse; |
| 3687 | |
| 3688 | if (PyObject_HasAttrString(obj, "test")) { |
| 3689 | int res; |
| 3690 | tmp = PyObject_GetAttrString(obj, "test"); |
| 3691 | if (tmp == NULL) goto failed; |
| 3692 | res = obj2ast_expr(tmp, &test, arena); |
| 3693 | if (res != 0) goto failed; |
| 3694 | Py_XDECREF(tmp); |
| 3695 | tmp = NULL; |
| 3696 | } else { |
| 3697 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 3698 | return 1; |
| 3699 | } |
| 3700 | if (PyObject_HasAttrString(obj, "body")) { |
| 3701 | int res; |
| 3702 | Py_ssize_t len; |
| 3703 | Py_ssize_t i; |
| 3704 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3705 | if (tmp == NULL) goto failed; |
| 3706 | if (!PyList_Check(tmp)) { |
| 3707 | PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3708 | goto failed; |
| 3709 | } |
| 3710 | len = PyList_GET_SIZE(tmp); |
| 3711 | body = asdl_seq_new(len, arena); |
| 3712 | if (body == NULL) goto failed; |
| 3713 | for (i = 0; i < len; i++) { |
| 3714 | stmt_ty value; |
| 3715 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3716 | if (res != 0) goto failed; |
| 3717 | asdl_seq_SET(body, i, value); |
| 3718 | } |
| 3719 | Py_XDECREF(tmp); |
| 3720 | tmp = NULL; |
| 3721 | } else { |
| 3722 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 3723 | return 1; |
| 3724 | } |
| 3725 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 3726 | int res; |
| 3727 | Py_ssize_t len; |
| 3728 | Py_ssize_t i; |
| 3729 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 3730 | if (tmp == NULL) goto failed; |
| 3731 | if (!PyList_Check(tmp)) { |
| 3732 | PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3733 | goto failed; |
| 3734 | } |
| 3735 | len = PyList_GET_SIZE(tmp); |
| 3736 | orelse = asdl_seq_new(len, arena); |
| 3737 | if (orelse == NULL) goto failed; |
| 3738 | for (i = 0; i < len; i++) { |
| 3739 | stmt_ty value; |
| 3740 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3741 | if (res != 0) goto failed; |
| 3742 | asdl_seq_SET(orelse, i, value); |
| 3743 | } |
| 3744 | Py_XDECREF(tmp); |
| 3745 | tmp = NULL; |
| 3746 | } else { |
| 3747 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 3748 | return 1; |
| 3749 | } |
| 3750 | *out = While(test, body, orelse, lineno, col_offset, arena); |
| 3751 | if (*out == NULL) goto failed; |
| 3752 | return 0; |
| 3753 | } |
| 3754 | if (PyObject_IsInstance(obj, (PyObject*)If_type)) { |
| 3755 | expr_ty test; |
| 3756 | asdl_seq* body; |
| 3757 | asdl_seq* orelse; |
| 3758 | |
| 3759 | if (PyObject_HasAttrString(obj, "test")) { |
| 3760 | int res; |
| 3761 | tmp = PyObject_GetAttrString(obj, "test"); |
| 3762 | if (tmp == NULL) goto failed; |
| 3763 | res = obj2ast_expr(tmp, &test, arena); |
| 3764 | if (res != 0) goto failed; |
| 3765 | Py_XDECREF(tmp); |
| 3766 | tmp = NULL; |
| 3767 | } else { |
| 3768 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 3769 | return 1; |
| 3770 | } |
| 3771 | if (PyObject_HasAttrString(obj, "body")) { |
| 3772 | int res; |
| 3773 | Py_ssize_t len; |
| 3774 | Py_ssize_t i; |
| 3775 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3776 | if (tmp == NULL) goto failed; |
| 3777 | if (!PyList_Check(tmp)) { |
| 3778 | PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3779 | goto failed; |
| 3780 | } |
| 3781 | len = PyList_GET_SIZE(tmp); |
| 3782 | body = asdl_seq_new(len, arena); |
| 3783 | if (body == NULL) goto failed; |
| 3784 | for (i = 0; i < len; i++) { |
| 3785 | stmt_ty value; |
| 3786 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3787 | if (res != 0) goto failed; |
| 3788 | asdl_seq_SET(body, i, value); |
| 3789 | } |
| 3790 | Py_XDECREF(tmp); |
| 3791 | tmp = NULL; |
| 3792 | } else { |
| 3793 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 3794 | return 1; |
| 3795 | } |
| 3796 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 3797 | int res; |
| 3798 | Py_ssize_t len; |
| 3799 | Py_ssize_t i; |
| 3800 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 3801 | if (tmp == NULL) goto failed; |
| 3802 | if (!PyList_Check(tmp)) { |
| 3803 | PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3804 | goto failed; |
| 3805 | } |
| 3806 | len = PyList_GET_SIZE(tmp); |
| 3807 | orelse = asdl_seq_new(len, arena); |
| 3808 | if (orelse == NULL) goto failed; |
| 3809 | for (i = 0; i < len; i++) { |
| 3810 | stmt_ty value; |
| 3811 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3812 | if (res != 0) goto failed; |
| 3813 | asdl_seq_SET(orelse, i, value); |
| 3814 | } |
| 3815 | Py_XDECREF(tmp); |
| 3816 | tmp = NULL; |
| 3817 | } else { |
| 3818 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 3819 | return 1; |
| 3820 | } |
| 3821 | *out = If(test, body, orelse, lineno, col_offset, arena); |
| 3822 | if (*out == NULL) goto failed; |
| 3823 | return 0; |
| 3824 | } |
| 3825 | if (PyObject_IsInstance(obj, (PyObject*)With_type)) { |
| 3826 | expr_ty context_expr; |
| 3827 | expr_ty optional_vars; |
| 3828 | asdl_seq* body; |
| 3829 | |
| 3830 | if (PyObject_HasAttrString(obj, "context_expr")) { |
| 3831 | int res; |
| 3832 | tmp = PyObject_GetAttrString(obj, "context_expr"); |
| 3833 | if (tmp == NULL) goto failed; |
| 3834 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 3835 | if (res != 0) goto failed; |
| 3836 | Py_XDECREF(tmp); |
| 3837 | tmp = NULL; |
| 3838 | } else { |
| 3839 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from With"); |
| 3840 | return 1; |
| 3841 | } |
| 3842 | if (PyObject_HasAttrString(obj, "optional_vars")) { |
| 3843 | int res; |
| 3844 | tmp = PyObject_GetAttrString(obj, "optional_vars"); |
| 3845 | if (tmp == NULL) goto failed; |
| 3846 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 3847 | if (res != 0) goto failed; |
| 3848 | Py_XDECREF(tmp); |
| 3849 | tmp = NULL; |
| 3850 | } else { |
| 3851 | optional_vars = NULL; |
| 3852 | } |
| 3853 | if (PyObject_HasAttrString(obj, "body")) { |
| 3854 | int res; |
| 3855 | Py_ssize_t len; |
| 3856 | Py_ssize_t i; |
| 3857 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3858 | if (tmp == NULL) goto failed; |
| 3859 | if (!PyList_Check(tmp)) { |
| 3860 | PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3861 | goto failed; |
| 3862 | } |
| 3863 | len = PyList_GET_SIZE(tmp); |
| 3864 | body = asdl_seq_new(len, arena); |
| 3865 | if (body == NULL) goto failed; |
| 3866 | for (i = 0; i < len; i++) { |
| 3867 | stmt_ty value; |
| 3868 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3869 | if (res != 0) goto failed; |
| 3870 | asdl_seq_SET(body, i, value); |
| 3871 | } |
| 3872 | Py_XDECREF(tmp); |
| 3873 | tmp = NULL; |
| 3874 | } else { |
| 3875 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 3876 | return 1; |
| 3877 | } |
| 3878 | *out = With(context_expr, optional_vars, body, lineno, |
| 3879 | col_offset, arena); |
| 3880 | if (*out == NULL) goto failed; |
| 3881 | return 0; |
| 3882 | } |
| 3883 | if (PyObject_IsInstance(obj, (PyObject*)Raise_type)) { |
| 3884 | expr_ty type; |
| 3885 | expr_ty inst; |
| 3886 | expr_ty tback; |
| 3887 | |
| 3888 | if (PyObject_HasAttrString(obj, "type")) { |
| 3889 | int res; |
| 3890 | tmp = PyObject_GetAttrString(obj, "type"); |
| 3891 | if (tmp == NULL) goto failed; |
| 3892 | res = obj2ast_expr(tmp, &type, arena); |
| 3893 | if (res != 0) goto failed; |
| 3894 | Py_XDECREF(tmp); |
| 3895 | tmp = NULL; |
| 3896 | } else { |
| 3897 | type = NULL; |
| 3898 | } |
| 3899 | if (PyObject_HasAttrString(obj, "inst")) { |
| 3900 | int res; |
| 3901 | tmp = PyObject_GetAttrString(obj, "inst"); |
| 3902 | if (tmp == NULL) goto failed; |
| 3903 | res = obj2ast_expr(tmp, &inst, arena); |
| 3904 | if (res != 0) goto failed; |
| 3905 | Py_XDECREF(tmp); |
| 3906 | tmp = NULL; |
| 3907 | } else { |
| 3908 | inst = NULL; |
| 3909 | } |
| 3910 | if (PyObject_HasAttrString(obj, "tback")) { |
| 3911 | int res; |
| 3912 | tmp = PyObject_GetAttrString(obj, "tback"); |
| 3913 | if (tmp == NULL) goto failed; |
| 3914 | res = obj2ast_expr(tmp, &tback, arena); |
| 3915 | if (res != 0) goto failed; |
| 3916 | Py_XDECREF(tmp); |
| 3917 | tmp = NULL; |
| 3918 | } else { |
| 3919 | tback = NULL; |
| 3920 | } |
| 3921 | *out = Raise(type, inst, tback, lineno, col_offset, arena); |
| 3922 | if (*out == NULL) goto failed; |
| 3923 | return 0; |
| 3924 | } |
| 3925 | if (PyObject_IsInstance(obj, (PyObject*)TryExcept_type)) { |
| 3926 | asdl_seq* body; |
| 3927 | asdl_seq* handlers; |
| 3928 | asdl_seq* orelse; |
| 3929 | |
| 3930 | if (PyObject_HasAttrString(obj, "body")) { |
| 3931 | int res; |
| 3932 | Py_ssize_t len; |
| 3933 | Py_ssize_t i; |
| 3934 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3935 | if (tmp == NULL) goto failed; |
| 3936 | if (!PyList_Check(tmp)) { |
| 3937 | PyErr_Format(PyExc_TypeError, "TryExcept field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3938 | goto failed; |
| 3939 | } |
| 3940 | len = PyList_GET_SIZE(tmp); |
| 3941 | body = asdl_seq_new(len, arena); |
| 3942 | if (body == NULL) goto failed; |
| 3943 | for (i = 0; i < len; i++) { |
| 3944 | stmt_ty value; |
| 3945 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3946 | if (res != 0) goto failed; |
| 3947 | asdl_seq_SET(body, i, value); |
| 3948 | } |
| 3949 | Py_XDECREF(tmp); |
| 3950 | tmp = NULL; |
| 3951 | } else { |
| 3952 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryExcept"); |
| 3953 | return 1; |
| 3954 | } |
| 3955 | if (PyObject_HasAttrString(obj, "handlers")) { |
| 3956 | int res; |
| 3957 | Py_ssize_t len; |
| 3958 | Py_ssize_t i; |
| 3959 | tmp = PyObject_GetAttrString(obj, "handlers"); |
| 3960 | if (tmp == NULL) goto failed; |
| 3961 | if (!PyList_Check(tmp)) { |
| 3962 | PyErr_Format(PyExc_TypeError, "TryExcept field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3963 | goto failed; |
| 3964 | } |
| 3965 | len = PyList_GET_SIZE(tmp); |
| 3966 | handlers = asdl_seq_new(len, arena); |
| 3967 | if (handlers == NULL) goto failed; |
| 3968 | for (i = 0; i < len; i++) { |
| 3969 | excepthandler_ty value; |
| 3970 | res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3971 | if (res != 0) goto failed; |
| 3972 | asdl_seq_SET(handlers, i, value); |
| 3973 | } |
| 3974 | Py_XDECREF(tmp); |
| 3975 | tmp = NULL; |
| 3976 | } else { |
| 3977 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from TryExcept"); |
| 3978 | return 1; |
| 3979 | } |
| 3980 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 3981 | int res; |
| 3982 | Py_ssize_t len; |
| 3983 | Py_ssize_t i; |
| 3984 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 3985 | if (tmp == NULL) goto failed; |
| 3986 | if (!PyList_Check(tmp)) { |
| 3987 | PyErr_Format(PyExc_TypeError, "TryExcept field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3988 | goto failed; |
| 3989 | } |
| 3990 | len = PyList_GET_SIZE(tmp); |
| 3991 | orelse = asdl_seq_new(len, arena); |
| 3992 | if (orelse == NULL) goto failed; |
| 3993 | for (i = 0; i < len; i++) { |
| 3994 | stmt_ty value; |
| 3995 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3996 | if (res != 0) goto failed; |
| 3997 | asdl_seq_SET(orelse, i, value); |
| 3998 | } |
| 3999 | Py_XDECREF(tmp); |
| 4000 | tmp = NULL; |
| 4001 | } else { |
| 4002 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from TryExcept"); |
| 4003 | return 1; |
| 4004 | } |
| 4005 | *out = TryExcept(body, handlers, orelse, lineno, col_offset, |
| 4006 | arena); |
| 4007 | if (*out == NULL) goto failed; |
| 4008 | return 0; |
| 4009 | } |
| 4010 | if (PyObject_IsInstance(obj, (PyObject*)TryFinally_type)) { |
| 4011 | asdl_seq* body; |
| 4012 | asdl_seq* finalbody; |
| 4013 | |
| 4014 | if (PyObject_HasAttrString(obj, "body")) { |
| 4015 | int res; |
| 4016 | Py_ssize_t len; |
| 4017 | Py_ssize_t i; |
| 4018 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4019 | if (tmp == NULL) goto failed; |
| 4020 | if (!PyList_Check(tmp)) { |
| 4021 | PyErr_Format(PyExc_TypeError, "TryFinally field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4022 | goto failed; |
| 4023 | } |
| 4024 | len = PyList_GET_SIZE(tmp); |
| 4025 | body = asdl_seq_new(len, arena); |
| 4026 | if (body == NULL) goto failed; |
| 4027 | for (i = 0; i < len; i++) { |
| 4028 | stmt_ty value; |
| 4029 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4030 | if (res != 0) goto failed; |
| 4031 | asdl_seq_SET(body, i, value); |
| 4032 | } |
| 4033 | Py_XDECREF(tmp); |
| 4034 | tmp = NULL; |
| 4035 | } else { |
| 4036 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryFinally"); |
| 4037 | return 1; |
| 4038 | } |
| 4039 | if (PyObject_HasAttrString(obj, "finalbody")) { |
| 4040 | int res; |
| 4041 | Py_ssize_t len; |
| 4042 | Py_ssize_t i; |
| 4043 | tmp = PyObject_GetAttrString(obj, "finalbody"); |
| 4044 | if (tmp == NULL) goto failed; |
| 4045 | if (!PyList_Check(tmp)) { |
| 4046 | PyErr_Format(PyExc_TypeError, "TryFinally field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4047 | goto failed; |
| 4048 | } |
| 4049 | len = PyList_GET_SIZE(tmp); |
| 4050 | finalbody = asdl_seq_new(len, arena); |
| 4051 | if (finalbody == NULL) goto failed; |
| 4052 | for (i = 0; i < len; i++) { |
| 4053 | stmt_ty value; |
| 4054 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4055 | if (res != 0) goto failed; |
| 4056 | asdl_seq_SET(finalbody, i, value); |
| 4057 | } |
| 4058 | Py_XDECREF(tmp); |
| 4059 | tmp = NULL; |
| 4060 | } else { |
| 4061 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from TryFinally"); |
| 4062 | return 1; |
| 4063 | } |
| 4064 | *out = TryFinally(body, finalbody, lineno, col_offset, arena); |
| 4065 | if (*out == NULL) goto failed; |
| 4066 | return 0; |
| 4067 | } |
| 4068 | if (PyObject_IsInstance(obj, (PyObject*)Assert_type)) { |
| 4069 | expr_ty test; |
| 4070 | expr_ty msg; |
| 4071 | |
| 4072 | if (PyObject_HasAttrString(obj, "test")) { |
| 4073 | int res; |
| 4074 | tmp = PyObject_GetAttrString(obj, "test"); |
| 4075 | if (tmp == NULL) goto failed; |
| 4076 | res = obj2ast_expr(tmp, &test, arena); |
| 4077 | if (res != 0) goto failed; |
| 4078 | Py_XDECREF(tmp); |
| 4079 | tmp = NULL; |
| 4080 | } else { |
| 4081 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 4082 | return 1; |
| 4083 | } |
| 4084 | if (PyObject_HasAttrString(obj, "msg")) { |
| 4085 | int res; |
| 4086 | tmp = PyObject_GetAttrString(obj, "msg"); |
| 4087 | if (tmp == NULL) goto failed; |
| 4088 | res = obj2ast_expr(tmp, &msg, arena); |
| 4089 | if (res != 0) goto failed; |
| 4090 | Py_XDECREF(tmp); |
| 4091 | tmp = NULL; |
| 4092 | } else { |
| 4093 | msg = NULL; |
| 4094 | } |
| 4095 | *out = Assert(test, msg, lineno, col_offset, arena); |
| 4096 | if (*out == NULL) goto failed; |
| 4097 | return 0; |
| 4098 | } |
| 4099 | if (PyObject_IsInstance(obj, (PyObject*)Import_type)) { |
| 4100 | asdl_seq* names; |
| 4101 | |
| 4102 | if (PyObject_HasAttrString(obj, "names")) { |
| 4103 | int res; |
| 4104 | Py_ssize_t len; |
| 4105 | Py_ssize_t i; |
| 4106 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4107 | if (tmp == NULL) goto failed; |
| 4108 | if (!PyList_Check(tmp)) { |
| 4109 | PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4110 | goto failed; |
| 4111 | } |
| 4112 | len = PyList_GET_SIZE(tmp); |
| 4113 | names = asdl_seq_new(len, arena); |
| 4114 | if (names == NULL) goto failed; |
| 4115 | for (i = 0; i < len; i++) { |
| 4116 | alias_ty value; |
| 4117 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4118 | if (res != 0) goto failed; |
| 4119 | asdl_seq_SET(names, i, value); |
| 4120 | } |
| 4121 | Py_XDECREF(tmp); |
| 4122 | tmp = NULL; |
| 4123 | } else { |
| 4124 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 4125 | return 1; |
| 4126 | } |
| 4127 | *out = Import(names, lineno, col_offset, arena); |
| 4128 | if (*out == NULL) goto failed; |
| 4129 | return 0; |
| 4130 | } |
| 4131 | if (PyObject_IsInstance(obj, (PyObject*)ImportFrom_type)) { |
| 4132 | identifier module; |
| 4133 | asdl_seq* names; |
| 4134 | int level; |
| 4135 | |
| 4136 | if (PyObject_HasAttrString(obj, "module")) { |
| 4137 | int res; |
| 4138 | tmp = PyObject_GetAttrString(obj, "module"); |
| 4139 | if (tmp == NULL) goto failed; |
| 4140 | res = obj2ast_identifier(tmp, &module, arena); |
| 4141 | if (res != 0) goto failed; |
| 4142 | Py_XDECREF(tmp); |
| 4143 | tmp = NULL; |
| 4144 | } else { |
| 4145 | PyErr_SetString(PyExc_TypeError, "required field \"module\" missing from ImportFrom"); |
| 4146 | return 1; |
| 4147 | } |
| 4148 | if (PyObject_HasAttrString(obj, "names")) { |
| 4149 | int res; |
| 4150 | Py_ssize_t len; |
| 4151 | Py_ssize_t i; |
| 4152 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4153 | if (tmp == NULL) goto failed; |
| 4154 | if (!PyList_Check(tmp)) { |
| 4155 | PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4156 | goto failed; |
| 4157 | } |
| 4158 | len = PyList_GET_SIZE(tmp); |
| 4159 | names = asdl_seq_new(len, arena); |
| 4160 | if (names == NULL) goto failed; |
| 4161 | for (i = 0; i < len; i++) { |
| 4162 | alias_ty value; |
| 4163 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4164 | if (res != 0) goto failed; |
| 4165 | asdl_seq_SET(names, i, value); |
| 4166 | } |
| 4167 | Py_XDECREF(tmp); |
| 4168 | tmp = NULL; |
| 4169 | } else { |
| 4170 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 4171 | return 1; |
| 4172 | } |
| 4173 | if (PyObject_HasAttrString(obj, "level")) { |
| 4174 | int res; |
| 4175 | tmp = PyObject_GetAttrString(obj, "level"); |
| 4176 | if (tmp == NULL) goto failed; |
| 4177 | res = obj2ast_int(tmp, &level, arena); |
| 4178 | if (res != 0) goto failed; |
| 4179 | Py_XDECREF(tmp); |
| 4180 | tmp = NULL; |
| 4181 | } else { |
| 4182 | level = 0; |
| 4183 | } |
| 4184 | *out = ImportFrom(module, names, level, lineno, col_offset, |
| 4185 | arena); |
| 4186 | if (*out == NULL) goto failed; |
| 4187 | return 0; |
| 4188 | } |
| 4189 | if (PyObject_IsInstance(obj, (PyObject*)Exec_type)) { |
| 4190 | expr_ty body; |
| 4191 | expr_ty globals; |
| 4192 | expr_ty locals; |
| 4193 | |
| 4194 | if (PyObject_HasAttrString(obj, "body")) { |
| 4195 | int res; |
| 4196 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4197 | if (tmp == NULL) goto failed; |
| 4198 | res = obj2ast_expr(tmp, &body, arena); |
| 4199 | if (res != 0) goto failed; |
| 4200 | Py_XDECREF(tmp); |
| 4201 | tmp = NULL; |
| 4202 | } else { |
| 4203 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Exec"); |
| 4204 | return 1; |
| 4205 | } |
| 4206 | if (PyObject_HasAttrString(obj, "globals")) { |
| 4207 | int res; |
| 4208 | tmp = PyObject_GetAttrString(obj, "globals"); |
| 4209 | if (tmp == NULL) goto failed; |
| 4210 | res = obj2ast_expr(tmp, &globals, arena); |
| 4211 | if (res != 0) goto failed; |
| 4212 | Py_XDECREF(tmp); |
| 4213 | tmp = NULL; |
| 4214 | } else { |
| 4215 | globals = NULL; |
| 4216 | } |
| 4217 | if (PyObject_HasAttrString(obj, "locals")) { |
| 4218 | int res; |
| 4219 | tmp = PyObject_GetAttrString(obj, "locals"); |
| 4220 | if (tmp == NULL) goto failed; |
| 4221 | res = obj2ast_expr(tmp, &locals, arena); |
| 4222 | if (res != 0) goto failed; |
| 4223 | Py_XDECREF(tmp); |
| 4224 | tmp = NULL; |
| 4225 | } else { |
| 4226 | locals = NULL; |
| 4227 | } |
| 4228 | *out = Exec(body, globals, locals, lineno, col_offset, arena); |
| 4229 | if (*out == NULL) goto failed; |
| 4230 | return 0; |
| 4231 | } |
| 4232 | if (PyObject_IsInstance(obj, (PyObject*)Global_type)) { |
| 4233 | asdl_seq* names; |
| 4234 | |
| 4235 | if (PyObject_HasAttrString(obj, "names")) { |
| 4236 | int res; |
| 4237 | Py_ssize_t len; |
| 4238 | Py_ssize_t i; |
| 4239 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4240 | if (tmp == NULL) goto failed; |
| 4241 | if (!PyList_Check(tmp)) { |
| 4242 | PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4243 | goto failed; |
| 4244 | } |
| 4245 | len = PyList_GET_SIZE(tmp); |
| 4246 | names = asdl_seq_new(len, arena); |
| 4247 | if (names == NULL) goto failed; |
| 4248 | for (i = 0; i < len; i++) { |
| 4249 | identifier value; |
| 4250 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4251 | if (res != 0) goto failed; |
| 4252 | asdl_seq_SET(names, i, value); |
| 4253 | } |
| 4254 | Py_XDECREF(tmp); |
| 4255 | tmp = NULL; |
| 4256 | } else { |
| 4257 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 4258 | return 1; |
| 4259 | } |
| 4260 | *out = Global(names, lineno, col_offset, arena); |
| 4261 | if (*out == NULL) goto failed; |
| 4262 | return 0; |
| 4263 | } |
| 4264 | if (PyObject_IsInstance(obj, (PyObject*)Expr_type)) { |
| 4265 | expr_ty value; |
| 4266 | |
| 4267 | if (PyObject_HasAttrString(obj, "value")) { |
| 4268 | int res; |
| 4269 | tmp = PyObject_GetAttrString(obj, "value"); |
| 4270 | if (tmp == NULL) goto failed; |
| 4271 | res = obj2ast_expr(tmp, &value, arena); |
| 4272 | if (res != 0) goto failed; |
| 4273 | Py_XDECREF(tmp); |
| 4274 | tmp = NULL; |
| 4275 | } else { |
| 4276 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 4277 | return 1; |
| 4278 | } |
| 4279 | *out = Expr(value, lineno, col_offset, arena); |
| 4280 | if (*out == NULL) goto failed; |
| 4281 | return 0; |
| 4282 | } |
| 4283 | if (PyObject_IsInstance(obj, (PyObject*)Pass_type)) { |
| 4284 | |
| 4285 | *out = Pass(lineno, col_offset, arena); |
| 4286 | if (*out == NULL) goto failed; |
| 4287 | return 0; |
| 4288 | } |
| 4289 | if (PyObject_IsInstance(obj, (PyObject*)Break_type)) { |
| 4290 | |
| 4291 | *out = Break(lineno, col_offset, arena); |
| 4292 | if (*out == NULL) goto failed; |
| 4293 | return 0; |
| 4294 | } |
| 4295 | if (PyObject_IsInstance(obj, (PyObject*)Continue_type)) { |
| 4296 | |
| 4297 | *out = Continue(lineno, col_offset, arena); |
| 4298 | if (*out == NULL) goto failed; |
| 4299 | return 0; |
| 4300 | } |
| 4301 | |
| 4302 | tmp = PyObject_Repr(obj); |
| 4303 | if (tmp == NULL) goto failed; |
| 4304 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %.400s", PyString_AS_STRING(tmp)); |
| 4305 | failed: |
| 4306 | Py_XDECREF(tmp); |
| 4307 | return 1; |
| 4308 | } |
| 4309 | |
| 4310 | int |
| 4311 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 4312 | { |
| 4313 | PyObject* tmp = NULL; |
| 4314 | |
| 4315 | int lineno; |
| 4316 | int col_offset; |
| 4317 | |
| 4318 | if (obj == Py_None) { |
| 4319 | *out = NULL; |
| 4320 | return 0; |
| 4321 | } |
| 4322 | if (PyObject_HasAttrString(obj, "lineno")) { |
| 4323 | int res; |
| 4324 | tmp = PyObject_GetAttrString(obj, "lineno"); |
| 4325 | if (tmp == NULL) goto failed; |
| 4326 | res = obj2ast_int(tmp, &lineno, arena); |
| 4327 | if (res != 0) goto failed; |
| 4328 | Py_XDECREF(tmp); |
| 4329 | tmp = NULL; |
| 4330 | } else { |
| 4331 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 4332 | return 1; |
| 4333 | } |
| 4334 | if (PyObject_HasAttrString(obj, "col_offset")) { |
| 4335 | int res; |
| 4336 | tmp = PyObject_GetAttrString(obj, "col_offset"); |
| 4337 | if (tmp == NULL) goto failed; |
| 4338 | res = obj2ast_int(tmp, &col_offset, arena); |
| 4339 | if (res != 0) goto failed; |
| 4340 | Py_XDECREF(tmp); |
| 4341 | tmp = NULL; |
| 4342 | } else { |
| 4343 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 4344 | return 1; |
| 4345 | } |
| 4346 | if (PyObject_IsInstance(obj, (PyObject*)BoolOp_type)) { |
| 4347 | boolop_ty op; |
| 4348 | asdl_seq* values; |
| 4349 | |
| 4350 | if (PyObject_HasAttrString(obj, "op")) { |
| 4351 | int res; |
| 4352 | tmp = PyObject_GetAttrString(obj, "op"); |
| 4353 | if (tmp == NULL) goto failed; |
| 4354 | res = obj2ast_boolop(tmp, &op, arena); |
| 4355 | if (res != 0) goto failed; |
| 4356 | Py_XDECREF(tmp); |
| 4357 | tmp = NULL; |
| 4358 | } else { |
| 4359 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 4360 | return 1; |
| 4361 | } |
| 4362 | if (PyObject_HasAttrString(obj, "values")) { |
| 4363 | int res; |
| 4364 | Py_ssize_t len; |
| 4365 | Py_ssize_t i; |
| 4366 | tmp = PyObject_GetAttrString(obj, "values"); |
| 4367 | if (tmp == NULL) goto failed; |
| 4368 | if (!PyList_Check(tmp)) { |
| 4369 | PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4370 | goto failed; |
| 4371 | } |
| 4372 | len = PyList_GET_SIZE(tmp); |
| 4373 | values = asdl_seq_new(len, arena); |
| 4374 | if (values == NULL) goto failed; |
| 4375 | for (i = 0; i < len; i++) { |
| 4376 | expr_ty value; |
| 4377 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4378 | if (res != 0) goto failed; |
| 4379 | asdl_seq_SET(values, i, value); |
| 4380 | } |
| 4381 | Py_XDECREF(tmp); |
| 4382 | tmp = NULL; |
| 4383 | } else { |
| 4384 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 4385 | return 1; |
| 4386 | } |
| 4387 | *out = BoolOp(op, values, lineno, col_offset, arena); |
| 4388 | if (*out == NULL) goto failed; |
| 4389 | return 0; |
| 4390 | } |
| 4391 | if (PyObject_IsInstance(obj, (PyObject*)BinOp_type)) { |
| 4392 | expr_ty left; |
| 4393 | operator_ty op; |
| 4394 | expr_ty right; |
| 4395 | |
| 4396 | if (PyObject_HasAttrString(obj, "left")) { |
| 4397 | int res; |
| 4398 | tmp = PyObject_GetAttrString(obj, "left"); |
| 4399 | if (tmp == NULL) goto failed; |
| 4400 | res = obj2ast_expr(tmp, &left, arena); |
| 4401 | if (res != 0) goto failed; |
| 4402 | Py_XDECREF(tmp); |
| 4403 | tmp = NULL; |
| 4404 | } else { |
| 4405 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 4406 | return 1; |
| 4407 | } |
| 4408 | if (PyObject_HasAttrString(obj, "op")) { |
| 4409 | int res; |
| 4410 | tmp = PyObject_GetAttrString(obj, "op"); |
| 4411 | if (tmp == NULL) goto failed; |
| 4412 | res = obj2ast_operator(tmp, &op, arena); |
| 4413 | if (res != 0) goto failed; |
| 4414 | Py_XDECREF(tmp); |
| 4415 | tmp = NULL; |
| 4416 | } else { |
| 4417 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 4418 | return 1; |
| 4419 | } |
| 4420 | if (PyObject_HasAttrString(obj, "right")) { |
| 4421 | int res; |
| 4422 | tmp = PyObject_GetAttrString(obj, "right"); |
| 4423 | if (tmp == NULL) goto failed; |
| 4424 | res = obj2ast_expr(tmp, &right, arena); |
| 4425 | if (res != 0) goto failed; |
| 4426 | Py_XDECREF(tmp); |
| 4427 | tmp = NULL; |
| 4428 | } else { |
| 4429 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 4430 | return 1; |
| 4431 | } |
| 4432 | *out = BinOp(left, op, right, lineno, col_offset, arena); |
| 4433 | if (*out == NULL) goto failed; |
| 4434 | return 0; |
| 4435 | } |
| 4436 | if (PyObject_IsInstance(obj, (PyObject*)UnaryOp_type)) { |
| 4437 | unaryop_ty op; |
| 4438 | expr_ty operand; |
| 4439 | |
| 4440 | if (PyObject_HasAttrString(obj, "op")) { |
| 4441 | int res; |
| 4442 | tmp = PyObject_GetAttrString(obj, "op"); |
| 4443 | if (tmp == NULL) goto failed; |
| 4444 | res = obj2ast_unaryop(tmp, &op, arena); |
| 4445 | if (res != 0) goto failed; |
| 4446 | Py_XDECREF(tmp); |
| 4447 | tmp = NULL; |
| 4448 | } else { |
| 4449 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 4450 | return 1; |
| 4451 | } |
| 4452 | if (PyObject_HasAttrString(obj, "operand")) { |
| 4453 | int res; |
| 4454 | tmp = PyObject_GetAttrString(obj, "operand"); |
| 4455 | if (tmp == NULL) goto failed; |
| 4456 | res = obj2ast_expr(tmp, &operand, arena); |
| 4457 | if (res != 0) goto failed; |
| 4458 | Py_XDECREF(tmp); |
| 4459 | tmp = NULL; |
| 4460 | } else { |
| 4461 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 4462 | return 1; |
| 4463 | } |
| 4464 | *out = UnaryOp(op, operand, lineno, col_offset, arena); |
| 4465 | if (*out == NULL) goto failed; |
| 4466 | return 0; |
| 4467 | } |
| 4468 | if (PyObject_IsInstance(obj, (PyObject*)Lambda_type)) { |
| 4469 | arguments_ty args; |
| 4470 | expr_ty body; |
| 4471 | |
| 4472 | if (PyObject_HasAttrString(obj, "args")) { |
| 4473 | int res; |
| 4474 | tmp = PyObject_GetAttrString(obj, "args"); |
| 4475 | if (tmp == NULL) goto failed; |
| 4476 | res = obj2ast_arguments(tmp, &args, arena); |
| 4477 | if (res != 0) goto failed; |
| 4478 | Py_XDECREF(tmp); |
| 4479 | tmp = NULL; |
| 4480 | } else { |
| 4481 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 4482 | return 1; |
| 4483 | } |
| 4484 | if (PyObject_HasAttrString(obj, "body")) { |
| 4485 | int res; |
| 4486 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4487 | if (tmp == NULL) goto failed; |
| 4488 | res = obj2ast_expr(tmp, &body, arena); |
| 4489 | if (res != 0) goto failed; |
| 4490 | Py_XDECREF(tmp); |
| 4491 | tmp = NULL; |
| 4492 | } else { |
| 4493 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 4494 | return 1; |
| 4495 | } |
| 4496 | *out = Lambda(args, body, lineno, col_offset, arena); |
| 4497 | if (*out == NULL) goto failed; |
| 4498 | return 0; |
| 4499 | } |
| 4500 | if (PyObject_IsInstance(obj, (PyObject*)IfExp_type)) { |
| 4501 | expr_ty test; |
| 4502 | expr_ty body; |
| 4503 | expr_ty orelse; |
| 4504 | |
| 4505 | if (PyObject_HasAttrString(obj, "test")) { |
| 4506 | int res; |
| 4507 | tmp = PyObject_GetAttrString(obj, "test"); |
| 4508 | if (tmp == NULL) goto failed; |
| 4509 | res = obj2ast_expr(tmp, &test, arena); |
| 4510 | if (res != 0) goto failed; |
| 4511 | Py_XDECREF(tmp); |
| 4512 | tmp = NULL; |
| 4513 | } else { |
| 4514 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 4515 | return 1; |
| 4516 | } |
| 4517 | if (PyObject_HasAttrString(obj, "body")) { |
| 4518 | int res; |
| 4519 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4520 | if (tmp == NULL) goto failed; |
| 4521 | res = obj2ast_expr(tmp, &body, arena); |
| 4522 | if (res != 0) goto failed; |
| 4523 | Py_XDECREF(tmp); |
| 4524 | tmp = NULL; |
| 4525 | } else { |
| 4526 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 4527 | return 1; |
| 4528 | } |
| 4529 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4530 | int res; |
| 4531 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4532 | if (tmp == NULL) goto failed; |
| 4533 | res = obj2ast_expr(tmp, &orelse, arena); |
| 4534 | if (res != 0) goto failed; |
| 4535 | Py_XDECREF(tmp); |
| 4536 | tmp = NULL; |
| 4537 | } else { |
| 4538 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 4539 | return 1; |
| 4540 | } |
| 4541 | *out = IfExp(test, body, orelse, lineno, col_offset, arena); |
| 4542 | if (*out == NULL) goto failed; |
| 4543 | return 0; |
| 4544 | } |
| 4545 | if (PyObject_IsInstance(obj, (PyObject*)Dict_type)) { |
| 4546 | asdl_seq* keys; |
| 4547 | asdl_seq* values; |
| 4548 | |
| 4549 | if (PyObject_HasAttrString(obj, "keys")) { |
| 4550 | int res; |
| 4551 | Py_ssize_t len; |
| 4552 | Py_ssize_t i; |
| 4553 | tmp = PyObject_GetAttrString(obj, "keys"); |
| 4554 | if (tmp == NULL) goto failed; |
| 4555 | if (!PyList_Check(tmp)) { |
| 4556 | PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4557 | goto failed; |
| 4558 | } |
| 4559 | len = PyList_GET_SIZE(tmp); |
| 4560 | keys = asdl_seq_new(len, arena); |
| 4561 | if (keys == NULL) goto failed; |
| 4562 | for (i = 0; i < len; i++) { |
| 4563 | expr_ty value; |
| 4564 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4565 | if (res != 0) goto failed; |
| 4566 | asdl_seq_SET(keys, i, value); |
| 4567 | } |
| 4568 | Py_XDECREF(tmp); |
| 4569 | tmp = NULL; |
| 4570 | } else { |
| 4571 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 4572 | return 1; |
| 4573 | } |
| 4574 | if (PyObject_HasAttrString(obj, "values")) { |
| 4575 | int res; |
| 4576 | Py_ssize_t len; |
| 4577 | Py_ssize_t i; |
| 4578 | tmp = PyObject_GetAttrString(obj, "values"); |
| 4579 | if (tmp == NULL) goto failed; |
| 4580 | if (!PyList_Check(tmp)) { |
| 4581 | PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4582 | goto failed; |
| 4583 | } |
| 4584 | len = PyList_GET_SIZE(tmp); |
| 4585 | values = asdl_seq_new(len, arena); |
| 4586 | if (values == NULL) goto failed; |
| 4587 | for (i = 0; i < len; i++) { |
| 4588 | expr_ty value; |
| 4589 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4590 | if (res != 0) goto failed; |
| 4591 | asdl_seq_SET(values, i, value); |
| 4592 | } |
| 4593 | Py_XDECREF(tmp); |
| 4594 | tmp = NULL; |
| 4595 | } else { |
| 4596 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 4597 | return 1; |
| 4598 | } |
| 4599 | *out = Dict(keys, values, lineno, col_offset, arena); |
| 4600 | if (*out == NULL) goto failed; |
| 4601 | return 0; |
| 4602 | } |
| 4603 | if (PyObject_IsInstance(obj, (PyObject*)ListComp_type)) { |
| 4604 | expr_ty elt; |
| 4605 | asdl_seq* generators; |
| 4606 | |
| 4607 | if (PyObject_HasAttrString(obj, "elt")) { |
| 4608 | int res; |
| 4609 | tmp = PyObject_GetAttrString(obj, "elt"); |
| 4610 | if (tmp == NULL) goto failed; |
| 4611 | res = obj2ast_expr(tmp, &elt, arena); |
| 4612 | if (res != 0) goto failed; |
| 4613 | Py_XDECREF(tmp); |
| 4614 | tmp = NULL; |
| 4615 | } else { |
| 4616 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 4617 | return 1; |
| 4618 | } |
| 4619 | if (PyObject_HasAttrString(obj, "generators")) { |
| 4620 | int res; |
| 4621 | Py_ssize_t len; |
| 4622 | Py_ssize_t i; |
| 4623 | tmp = PyObject_GetAttrString(obj, "generators"); |
| 4624 | if (tmp == NULL) goto failed; |
| 4625 | if (!PyList_Check(tmp)) { |
| 4626 | PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4627 | goto failed; |
| 4628 | } |
| 4629 | len = PyList_GET_SIZE(tmp); |
| 4630 | generators = asdl_seq_new(len, arena); |
| 4631 | if (generators == NULL) goto failed; |
| 4632 | for (i = 0; i < len; i++) { |
| 4633 | comprehension_ty value; |
| 4634 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4635 | if (res != 0) goto failed; |
| 4636 | asdl_seq_SET(generators, i, value); |
| 4637 | } |
| 4638 | Py_XDECREF(tmp); |
| 4639 | tmp = NULL; |
| 4640 | } else { |
| 4641 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 4642 | return 1; |
| 4643 | } |
| 4644 | *out = ListComp(elt, generators, lineno, col_offset, arena); |
| 4645 | if (*out == NULL) goto failed; |
| 4646 | return 0; |
| 4647 | } |
| 4648 | if (PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type)) { |
| 4649 | expr_ty elt; |
| 4650 | asdl_seq* generators; |
| 4651 | |
| 4652 | if (PyObject_HasAttrString(obj, "elt")) { |
| 4653 | int res; |
| 4654 | tmp = PyObject_GetAttrString(obj, "elt"); |
| 4655 | if (tmp == NULL) goto failed; |
| 4656 | res = obj2ast_expr(tmp, &elt, arena); |
| 4657 | if (res != 0) goto failed; |
| 4658 | Py_XDECREF(tmp); |
| 4659 | tmp = NULL; |
| 4660 | } else { |
| 4661 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 4662 | return 1; |
| 4663 | } |
| 4664 | if (PyObject_HasAttrString(obj, "generators")) { |
| 4665 | int res; |
| 4666 | Py_ssize_t len; |
| 4667 | Py_ssize_t i; |
| 4668 | tmp = PyObject_GetAttrString(obj, "generators"); |
| 4669 | if (tmp == NULL) goto failed; |
| 4670 | if (!PyList_Check(tmp)) { |
| 4671 | PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4672 | goto failed; |
| 4673 | } |
| 4674 | len = PyList_GET_SIZE(tmp); |
| 4675 | generators = asdl_seq_new(len, arena); |
| 4676 | if (generators == NULL) goto failed; |
| 4677 | for (i = 0; i < len; i++) { |
| 4678 | comprehension_ty value; |
| 4679 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4680 | if (res != 0) goto failed; |
| 4681 | asdl_seq_SET(generators, i, value); |
| 4682 | } |
| 4683 | Py_XDECREF(tmp); |
| 4684 | tmp = NULL; |
| 4685 | } else { |
| 4686 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 4687 | return 1; |
| 4688 | } |
| 4689 | *out = GeneratorExp(elt, generators, lineno, col_offset, arena); |
| 4690 | if (*out == NULL) goto failed; |
| 4691 | return 0; |
| 4692 | } |
| 4693 | if (PyObject_IsInstance(obj, (PyObject*)Yield_type)) { |
| 4694 | expr_ty value; |
| 4695 | |
| 4696 | if (PyObject_HasAttrString(obj, "value")) { |
| 4697 | int res; |
| 4698 | tmp = PyObject_GetAttrString(obj, "value"); |
| 4699 | if (tmp == NULL) goto failed; |
| 4700 | res = obj2ast_expr(tmp, &value, arena); |
| 4701 | if (res != 0) goto failed; |
| 4702 | Py_XDECREF(tmp); |
| 4703 | tmp = NULL; |
| 4704 | } else { |
| 4705 | value = NULL; |
| 4706 | } |
| 4707 | *out = Yield(value, lineno, col_offset, arena); |
| 4708 | if (*out == NULL) goto failed; |
| 4709 | return 0; |
| 4710 | } |
| 4711 | if (PyObject_IsInstance(obj, (PyObject*)Compare_type)) { |
| 4712 | expr_ty left; |
| 4713 | asdl_int_seq* ops; |
| 4714 | asdl_seq* comparators; |
| 4715 | |
| 4716 | if (PyObject_HasAttrString(obj, "left")) { |
| 4717 | int res; |
| 4718 | tmp = PyObject_GetAttrString(obj, "left"); |
| 4719 | if (tmp == NULL) goto failed; |
| 4720 | res = obj2ast_expr(tmp, &left, arena); |
| 4721 | if (res != 0) goto failed; |
| 4722 | Py_XDECREF(tmp); |
| 4723 | tmp = NULL; |
| 4724 | } else { |
| 4725 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 4726 | return 1; |
| 4727 | } |
| 4728 | if (PyObject_HasAttrString(obj, "ops")) { |
| 4729 | int res; |
| 4730 | Py_ssize_t len; |
| 4731 | Py_ssize_t i; |
| 4732 | tmp = PyObject_GetAttrString(obj, "ops"); |
| 4733 | if (tmp == NULL) goto failed; |
| 4734 | if (!PyList_Check(tmp)) { |
| 4735 | PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4736 | goto failed; |
| 4737 | } |
| 4738 | len = PyList_GET_SIZE(tmp); |
| 4739 | ops = asdl_int_seq_new(len, arena); |
| 4740 | if (ops == NULL) goto failed; |
| 4741 | for (i = 0; i < len; i++) { |
| 4742 | cmpop_ty value; |
| 4743 | res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4744 | if (res != 0) goto failed; |
| 4745 | asdl_seq_SET(ops, i, value); |
| 4746 | } |
| 4747 | Py_XDECREF(tmp); |
| 4748 | tmp = NULL; |
| 4749 | } else { |
| 4750 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 4751 | return 1; |
| 4752 | } |
| 4753 | if (PyObject_HasAttrString(obj, "comparators")) { |
| 4754 | int res; |
| 4755 | Py_ssize_t len; |
| 4756 | Py_ssize_t i; |
| 4757 | tmp = PyObject_GetAttrString(obj, "comparators"); |
| 4758 | if (tmp == NULL) goto failed; |
| 4759 | if (!PyList_Check(tmp)) { |
| 4760 | PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4761 | goto failed; |
| 4762 | } |
| 4763 | len = PyList_GET_SIZE(tmp); |
| 4764 | comparators = asdl_seq_new(len, arena); |
| 4765 | if (comparators == NULL) goto failed; |
| 4766 | for (i = 0; i < len; i++) { |
| 4767 | expr_ty value; |
| 4768 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4769 | if (res != 0) goto failed; |
| 4770 | asdl_seq_SET(comparators, i, value); |
| 4771 | } |
| 4772 | Py_XDECREF(tmp); |
| 4773 | tmp = NULL; |
| 4774 | } else { |
| 4775 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 4776 | return 1; |
| 4777 | } |
| 4778 | *out = Compare(left, ops, comparators, lineno, col_offset, |
| 4779 | arena); |
| 4780 | if (*out == NULL) goto failed; |
| 4781 | return 0; |
| 4782 | } |
| 4783 | if (PyObject_IsInstance(obj, (PyObject*)Call_type)) { |
| 4784 | expr_ty func; |
| 4785 | asdl_seq* args; |
| 4786 | asdl_seq* keywords; |
| 4787 | expr_ty starargs; |
| 4788 | expr_ty kwargs; |
| 4789 | |
| 4790 | if (PyObject_HasAttrString(obj, "func")) { |
| 4791 | int res; |
| 4792 | tmp = PyObject_GetAttrString(obj, "func"); |
| 4793 | if (tmp == NULL) goto failed; |
| 4794 | res = obj2ast_expr(tmp, &func, arena); |
| 4795 | if (res != 0) goto failed; |
| 4796 | Py_XDECREF(tmp); |
| 4797 | tmp = NULL; |
| 4798 | } else { |
| 4799 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 4800 | return 1; |
| 4801 | } |
| 4802 | if (PyObject_HasAttrString(obj, "args")) { |
| 4803 | int res; |
| 4804 | Py_ssize_t len; |
| 4805 | Py_ssize_t i; |
| 4806 | tmp = PyObject_GetAttrString(obj, "args"); |
| 4807 | if (tmp == NULL) goto failed; |
| 4808 | if (!PyList_Check(tmp)) { |
| 4809 | PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4810 | goto failed; |
| 4811 | } |
| 4812 | len = PyList_GET_SIZE(tmp); |
| 4813 | args = asdl_seq_new(len, arena); |
| 4814 | if (args == NULL) goto failed; |
| 4815 | for (i = 0; i < len; i++) { |
| 4816 | expr_ty value; |
| 4817 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4818 | if (res != 0) goto failed; |
| 4819 | asdl_seq_SET(args, i, value); |
| 4820 | } |
| 4821 | Py_XDECREF(tmp); |
| 4822 | tmp = NULL; |
| 4823 | } else { |
| 4824 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 4825 | return 1; |
| 4826 | } |
| 4827 | if (PyObject_HasAttrString(obj, "keywords")) { |
| 4828 | int res; |
| 4829 | Py_ssize_t len; |
| 4830 | Py_ssize_t i; |
| 4831 | tmp = PyObject_GetAttrString(obj, "keywords"); |
| 4832 | if (tmp == NULL) goto failed; |
| 4833 | if (!PyList_Check(tmp)) { |
| 4834 | PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4835 | goto failed; |
| 4836 | } |
| 4837 | len = PyList_GET_SIZE(tmp); |
| 4838 | keywords = asdl_seq_new(len, arena); |
| 4839 | if (keywords == NULL) goto failed; |
| 4840 | for (i = 0; i < len; i++) { |
| 4841 | keyword_ty value; |
| 4842 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4843 | if (res != 0) goto failed; |
| 4844 | asdl_seq_SET(keywords, i, value); |
| 4845 | } |
| 4846 | Py_XDECREF(tmp); |
| 4847 | tmp = NULL; |
| 4848 | } else { |
| 4849 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 4850 | return 1; |
| 4851 | } |
| 4852 | if (PyObject_HasAttrString(obj, "starargs")) { |
| 4853 | int res; |
| 4854 | tmp = PyObject_GetAttrString(obj, "starargs"); |
| 4855 | if (tmp == NULL) goto failed; |
| 4856 | res = obj2ast_expr(tmp, &starargs, arena); |
| 4857 | if (res != 0) goto failed; |
| 4858 | Py_XDECREF(tmp); |
| 4859 | tmp = NULL; |
| 4860 | } else { |
| 4861 | starargs = NULL; |
| 4862 | } |
| 4863 | if (PyObject_HasAttrString(obj, "kwargs")) { |
| 4864 | int res; |
| 4865 | tmp = PyObject_GetAttrString(obj, "kwargs"); |
| 4866 | if (tmp == NULL) goto failed; |
| 4867 | res = obj2ast_expr(tmp, &kwargs, arena); |
| 4868 | if (res != 0) goto failed; |
| 4869 | Py_XDECREF(tmp); |
| 4870 | tmp = NULL; |
| 4871 | } else { |
| 4872 | kwargs = NULL; |
| 4873 | } |
| 4874 | *out = Call(func, args, keywords, starargs, kwargs, lineno, |
| 4875 | col_offset, arena); |
| 4876 | if (*out == NULL) goto failed; |
| 4877 | return 0; |
| 4878 | } |
| 4879 | if (PyObject_IsInstance(obj, (PyObject*)Repr_type)) { |
| 4880 | expr_ty value; |
| 4881 | |
| 4882 | if (PyObject_HasAttrString(obj, "value")) { |
| 4883 | int res; |
| 4884 | tmp = PyObject_GetAttrString(obj, "value"); |
| 4885 | if (tmp == NULL) goto failed; |
| 4886 | res = obj2ast_expr(tmp, &value, arena); |
| 4887 | if (res != 0) goto failed; |
| 4888 | Py_XDECREF(tmp); |
| 4889 | tmp = NULL; |
| 4890 | } else { |
| 4891 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Repr"); |
| 4892 | return 1; |
| 4893 | } |
| 4894 | *out = Repr(value, lineno, col_offset, arena); |
| 4895 | if (*out == NULL) goto failed; |
| 4896 | return 0; |
| 4897 | } |
| 4898 | if (PyObject_IsInstance(obj, (PyObject*)Num_type)) { |
| 4899 | object n; |
| 4900 | |
| 4901 | if (PyObject_HasAttrString(obj, "n")) { |
| 4902 | int res; |
| 4903 | tmp = PyObject_GetAttrString(obj, "n"); |
| 4904 | if (tmp == NULL) goto failed; |
| 4905 | res = obj2ast_object(tmp, &n, arena); |
| 4906 | if (res != 0) goto failed; |
| 4907 | Py_XDECREF(tmp); |
| 4908 | tmp = NULL; |
| 4909 | } else { |
| 4910 | PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num"); |
| 4911 | return 1; |
| 4912 | } |
| 4913 | *out = Num(n, lineno, col_offset, arena); |
| 4914 | if (*out == NULL) goto failed; |
| 4915 | return 0; |
| 4916 | } |
| 4917 | if (PyObject_IsInstance(obj, (PyObject*)Str_type)) { |
| 4918 | string s; |
| 4919 | |
| 4920 | if (PyObject_HasAttrString(obj, "s")) { |
| 4921 | int res; |
| 4922 | tmp = PyObject_GetAttrString(obj, "s"); |
| 4923 | if (tmp == NULL) goto failed; |
| 4924 | res = obj2ast_string(tmp, &s, arena); |
| 4925 | if (res != 0) goto failed; |
| 4926 | Py_XDECREF(tmp); |
| 4927 | tmp = NULL; |
| 4928 | } else { |
| 4929 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str"); |
| 4930 | return 1; |
| 4931 | } |
| 4932 | *out = Str(s, lineno, col_offset, arena); |
| 4933 | if (*out == NULL) goto failed; |
| 4934 | return 0; |
| 4935 | } |
| 4936 | if (PyObject_IsInstance(obj, (PyObject*)Attribute_type)) { |
| 4937 | expr_ty value; |
| 4938 | identifier attr; |
| 4939 | expr_context_ty ctx; |
| 4940 | |
| 4941 | if (PyObject_HasAttrString(obj, "value")) { |
| 4942 | int res; |
| 4943 | tmp = PyObject_GetAttrString(obj, "value"); |
| 4944 | if (tmp == NULL) goto failed; |
| 4945 | res = obj2ast_expr(tmp, &value, arena); |
| 4946 | if (res != 0) goto failed; |
| 4947 | Py_XDECREF(tmp); |
| 4948 | tmp = NULL; |
| 4949 | } else { |
| 4950 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 4951 | return 1; |
| 4952 | } |
| 4953 | if (PyObject_HasAttrString(obj, "attr")) { |
| 4954 | int res; |
| 4955 | tmp = PyObject_GetAttrString(obj, "attr"); |
| 4956 | if (tmp == NULL) goto failed; |
| 4957 | res = obj2ast_identifier(tmp, &attr, arena); |
| 4958 | if (res != 0) goto failed; |
| 4959 | Py_XDECREF(tmp); |
| 4960 | tmp = NULL; |
| 4961 | } else { |
| 4962 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 4963 | return 1; |
| 4964 | } |
| 4965 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 4966 | int res; |
| 4967 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 4968 | if (tmp == NULL) goto failed; |
| 4969 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 4970 | if (res != 0) goto failed; |
| 4971 | Py_XDECREF(tmp); |
| 4972 | tmp = NULL; |
| 4973 | } else { |
| 4974 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 4975 | return 1; |
| 4976 | } |
| 4977 | *out = Attribute(value, attr, ctx, lineno, col_offset, arena); |
| 4978 | if (*out == NULL) goto failed; |
| 4979 | return 0; |
| 4980 | } |
| 4981 | if (PyObject_IsInstance(obj, (PyObject*)Subscript_type)) { |
| 4982 | expr_ty value; |
| 4983 | slice_ty slice; |
| 4984 | expr_context_ty ctx; |
| 4985 | |
| 4986 | if (PyObject_HasAttrString(obj, "value")) { |
| 4987 | int res; |
| 4988 | tmp = PyObject_GetAttrString(obj, "value"); |
| 4989 | if (tmp == NULL) goto failed; |
| 4990 | res = obj2ast_expr(tmp, &value, arena); |
| 4991 | if (res != 0) goto failed; |
| 4992 | Py_XDECREF(tmp); |
| 4993 | tmp = NULL; |
| 4994 | } else { |
| 4995 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 4996 | return 1; |
| 4997 | } |
| 4998 | if (PyObject_HasAttrString(obj, "slice")) { |
| 4999 | int res; |
| 5000 | tmp = PyObject_GetAttrString(obj, "slice"); |
| 5001 | if (tmp == NULL) goto failed; |
| 5002 | res = obj2ast_slice(tmp, &slice, arena); |
| 5003 | if (res != 0) goto failed; |
| 5004 | Py_XDECREF(tmp); |
| 5005 | tmp = NULL; |
| 5006 | } else { |
| 5007 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 5008 | return 1; |
| 5009 | } |
| 5010 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5011 | int res; |
| 5012 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5013 | if (tmp == NULL) goto failed; |
| 5014 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5015 | if (res != 0) goto failed; |
| 5016 | Py_XDECREF(tmp); |
| 5017 | tmp = NULL; |
| 5018 | } else { |
| 5019 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 5020 | return 1; |
| 5021 | } |
| 5022 | *out = Subscript(value, slice, ctx, lineno, col_offset, arena); |
| 5023 | if (*out == NULL) goto failed; |
| 5024 | return 0; |
| 5025 | } |
| 5026 | if (PyObject_IsInstance(obj, (PyObject*)Name_type)) { |
| 5027 | identifier id; |
| 5028 | expr_context_ty ctx; |
| 5029 | |
| 5030 | if (PyObject_HasAttrString(obj, "id")) { |
| 5031 | int res; |
| 5032 | tmp = PyObject_GetAttrString(obj, "id"); |
| 5033 | if (tmp == NULL) goto failed; |
| 5034 | res = obj2ast_identifier(tmp, &id, arena); |
| 5035 | if (res != 0) goto failed; |
| 5036 | Py_XDECREF(tmp); |
| 5037 | tmp = NULL; |
| 5038 | } else { |
| 5039 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 5040 | return 1; |
| 5041 | } |
| 5042 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5043 | int res; |
| 5044 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5045 | if (tmp == NULL) goto failed; |
| 5046 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5047 | if (res != 0) goto failed; |
| 5048 | Py_XDECREF(tmp); |
| 5049 | tmp = NULL; |
| 5050 | } else { |
| 5051 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 5052 | return 1; |
| 5053 | } |
| 5054 | *out = Name(id, ctx, lineno, col_offset, arena); |
| 5055 | if (*out == NULL) goto failed; |
| 5056 | return 0; |
| 5057 | } |
| 5058 | if (PyObject_IsInstance(obj, (PyObject*)List_type)) { |
| 5059 | asdl_seq* elts; |
| 5060 | expr_context_ty ctx; |
| 5061 | |
| 5062 | if (PyObject_HasAttrString(obj, "elts")) { |
| 5063 | int res; |
| 5064 | Py_ssize_t len; |
| 5065 | Py_ssize_t i; |
| 5066 | tmp = PyObject_GetAttrString(obj, "elts"); |
| 5067 | if (tmp == NULL) goto failed; |
| 5068 | if (!PyList_Check(tmp)) { |
| 5069 | PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5070 | goto failed; |
| 5071 | } |
| 5072 | len = PyList_GET_SIZE(tmp); |
| 5073 | elts = asdl_seq_new(len, arena); |
| 5074 | if (elts == NULL) goto failed; |
| 5075 | for (i = 0; i < len; i++) { |
| 5076 | expr_ty value; |
| 5077 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5078 | if (res != 0) goto failed; |
| 5079 | asdl_seq_SET(elts, i, value); |
| 5080 | } |
| 5081 | Py_XDECREF(tmp); |
| 5082 | tmp = NULL; |
| 5083 | } else { |
| 5084 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 5085 | return 1; |
| 5086 | } |
| 5087 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5088 | int res; |
| 5089 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5090 | if (tmp == NULL) goto failed; |
| 5091 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5092 | if (res != 0) goto failed; |
| 5093 | Py_XDECREF(tmp); |
| 5094 | tmp = NULL; |
| 5095 | } else { |
| 5096 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 5097 | return 1; |
| 5098 | } |
| 5099 | *out = List(elts, ctx, lineno, col_offset, arena); |
| 5100 | if (*out == NULL) goto failed; |
| 5101 | return 0; |
| 5102 | } |
| 5103 | if (PyObject_IsInstance(obj, (PyObject*)Tuple_type)) { |
| 5104 | asdl_seq* elts; |
| 5105 | expr_context_ty ctx; |
| 5106 | |
| 5107 | if (PyObject_HasAttrString(obj, "elts")) { |
| 5108 | int res; |
| 5109 | Py_ssize_t len; |
| 5110 | Py_ssize_t i; |
| 5111 | tmp = PyObject_GetAttrString(obj, "elts"); |
| 5112 | if (tmp == NULL) goto failed; |
| 5113 | if (!PyList_Check(tmp)) { |
| 5114 | PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5115 | goto failed; |
| 5116 | } |
| 5117 | len = PyList_GET_SIZE(tmp); |
| 5118 | elts = asdl_seq_new(len, arena); |
| 5119 | if (elts == NULL) goto failed; |
| 5120 | for (i = 0; i < len; i++) { |
| 5121 | expr_ty value; |
| 5122 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5123 | if (res != 0) goto failed; |
| 5124 | asdl_seq_SET(elts, i, value); |
| 5125 | } |
| 5126 | Py_XDECREF(tmp); |
| 5127 | tmp = NULL; |
| 5128 | } else { |
| 5129 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 5130 | return 1; |
| 5131 | } |
| 5132 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5133 | int res; |
| 5134 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5135 | if (tmp == NULL) goto failed; |
| 5136 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5137 | if (res != 0) goto failed; |
| 5138 | Py_XDECREF(tmp); |
| 5139 | tmp = NULL; |
| 5140 | } else { |
| 5141 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 5142 | return 1; |
| 5143 | } |
| 5144 | *out = Tuple(elts, ctx, lineno, col_offset, arena); |
| 5145 | if (*out == NULL) goto failed; |
| 5146 | return 0; |
| 5147 | } |
| 5148 | |
| 5149 | tmp = PyObject_Repr(obj); |
| 5150 | if (tmp == NULL) goto failed; |
| 5151 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %.400s", PyString_AS_STRING(tmp)); |
| 5152 | failed: |
| 5153 | Py_XDECREF(tmp); |
| 5154 | return 1; |
| 5155 | } |
| 5156 | |
| 5157 | int |
| 5158 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 5159 | { |
| 5160 | PyObject* tmp = NULL; |
| 5161 | |
| 5162 | if (PyObject_IsInstance(obj, (PyObject*)Load_type)) { |
| 5163 | *out = Load; |
| 5164 | return 0; |
| 5165 | } |
| 5166 | if (PyObject_IsInstance(obj, (PyObject*)Store_type)) { |
| 5167 | *out = Store; |
| 5168 | return 0; |
| 5169 | } |
| 5170 | if (PyObject_IsInstance(obj, (PyObject*)Del_type)) { |
| 5171 | *out = Del; |
| 5172 | return 0; |
| 5173 | } |
| 5174 | if (PyObject_IsInstance(obj, (PyObject*)AugLoad_type)) { |
| 5175 | *out = AugLoad; |
| 5176 | return 0; |
| 5177 | } |
| 5178 | if (PyObject_IsInstance(obj, (PyObject*)AugStore_type)) { |
| 5179 | *out = AugStore; |
| 5180 | return 0; |
| 5181 | } |
| 5182 | if (PyObject_IsInstance(obj, (PyObject*)Param_type)) { |
| 5183 | *out = Param; |
| 5184 | return 0; |
| 5185 | } |
| 5186 | |
| 5187 | tmp = PyObject_Repr(obj); |
| 5188 | if (tmp == NULL) goto failed; |
| 5189 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %.400s", PyString_AS_STRING(tmp)); |
| 5190 | failed: |
| 5191 | Py_XDECREF(tmp); |
| 5192 | return 1; |
| 5193 | } |
| 5194 | |
| 5195 | int |
| 5196 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
| 5197 | { |
| 5198 | PyObject* tmp = NULL; |
| 5199 | |
| 5200 | |
| 5201 | if (obj == Py_None) { |
| 5202 | *out = NULL; |
| 5203 | return 0; |
| 5204 | } |
| 5205 | if (PyObject_IsInstance(obj, (PyObject*)Ellipsis_type)) { |
| 5206 | |
| 5207 | *out = Ellipsis(arena); |
| 5208 | if (*out == NULL) goto failed; |
| 5209 | return 0; |
| 5210 | } |
| 5211 | if (PyObject_IsInstance(obj, (PyObject*)Slice_type)) { |
| 5212 | expr_ty lower; |
| 5213 | expr_ty upper; |
| 5214 | expr_ty step; |
| 5215 | |
| 5216 | if (PyObject_HasAttrString(obj, "lower")) { |
| 5217 | int res; |
| 5218 | tmp = PyObject_GetAttrString(obj, "lower"); |
| 5219 | if (tmp == NULL) goto failed; |
| 5220 | res = obj2ast_expr(tmp, &lower, arena); |
| 5221 | if (res != 0) goto failed; |
| 5222 | Py_XDECREF(tmp); |
| 5223 | tmp = NULL; |
| 5224 | } else { |
| 5225 | lower = NULL; |
| 5226 | } |
| 5227 | if (PyObject_HasAttrString(obj, "upper")) { |
| 5228 | int res; |
| 5229 | tmp = PyObject_GetAttrString(obj, "upper"); |
| 5230 | if (tmp == NULL) goto failed; |
| 5231 | res = obj2ast_expr(tmp, &upper, arena); |
| 5232 | if (res != 0) goto failed; |
| 5233 | Py_XDECREF(tmp); |
| 5234 | tmp = NULL; |
| 5235 | } else { |
| 5236 | upper = NULL; |
| 5237 | } |
| 5238 | if (PyObject_HasAttrString(obj, "step")) { |
| 5239 | int res; |
| 5240 | tmp = PyObject_GetAttrString(obj, "step"); |
| 5241 | if (tmp == NULL) goto failed; |
| 5242 | res = obj2ast_expr(tmp, &step, arena); |
| 5243 | if (res != 0) goto failed; |
| 5244 | Py_XDECREF(tmp); |
| 5245 | tmp = NULL; |
| 5246 | } else { |
| 5247 | step = NULL; |
| 5248 | } |
| 5249 | *out = Slice(lower, upper, step, arena); |
| 5250 | if (*out == NULL) goto failed; |
| 5251 | return 0; |
| 5252 | } |
| 5253 | if (PyObject_IsInstance(obj, (PyObject*)ExtSlice_type)) { |
| 5254 | asdl_seq* dims; |
| 5255 | |
| 5256 | if (PyObject_HasAttrString(obj, "dims")) { |
| 5257 | int res; |
| 5258 | Py_ssize_t len; |
| 5259 | Py_ssize_t i; |
| 5260 | tmp = PyObject_GetAttrString(obj, "dims"); |
| 5261 | if (tmp == NULL) goto failed; |
| 5262 | if (!PyList_Check(tmp)) { |
| 5263 | PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5264 | goto failed; |
| 5265 | } |
| 5266 | len = PyList_GET_SIZE(tmp); |
| 5267 | dims = asdl_seq_new(len, arena); |
| 5268 | if (dims == NULL) goto failed; |
| 5269 | for (i = 0; i < len; i++) { |
| 5270 | slice_ty value; |
| 5271 | res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5272 | if (res != 0) goto failed; |
| 5273 | asdl_seq_SET(dims, i, value); |
| 5274 | } |
| 5275 | Py_XDECREF(tmp); |
| 5276 | tmp = NULL; |
| 5277 | } else { |
| 5278 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
| 5279 | return 1; |
| 5280 | } |
| 5281 | *out = ExtSlice(dims, arena); |
| 5282 | if (*out == NULL) goto failed; |
| 5283 | return 0; |
| 5284 | } |
| 5285 | if (PyObject_IsInstance(obj, (PyObject*)Index_type)) { |
| 5286 | expr_ty value; |
| 5287 | |
| 5288 | if (PyObject_HasAttrString(obj, "value")) { |
| 5289 | int res; |
| 5290 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5291 | if (tmp == NULL) goto failed; |
| 5292 | res = obj2ast_expr(tmp, &value, arena); |
| 5293 | if (res != 0) goto failed; |
| 5294 | Py_XDECREF(tmp); |
| 5295 | tmp = NULL; |
| 5296 | } else { |
| 5297 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
| 5298 | return 1; |
| 5299 | } |
| 5300 | *out = Index(value, arena); |
| 5301 | if (*out == NULL) goto failed; |
| 5302 | return 0; |
| 5303 | } |
| 5304 | |
| 5305 | tmp = PyObject_Repr(obj); |
| 5306 | if (tmp == NULL) goto failed; |
| 5307 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %.400s", PyString_AS_STRING(tmp)); |
| 5308 | failed: |
| 5309 | Py_XDECREF(tmp); |
| 5310 | return 1; |
| 5311 | } |
| 5312 | |
| 5313 | int |
| 5314 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 5315 | { |
| 5316 | PyObject* tmp = NULL; |
| 5317 | |
| 5318 | if (PyObject_IsInstance(obj, (PyObject*)And_type)) { |
| 5319 | *out = And; |
| 5320 | return 0; |
| 5321 | } |
| 5322 | if (PyObject_IsInstance(obj, (PyObject*)Or_type)) { |
| 5323 | *out = Or; |
| 5324 | return 0; |
| 5325 | } |
| 5326 | |
| 5327 | tmp = PyObject_Repr(obj); |
| 5328 | if (tmp == NULL) goto failed; |
| 5329 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %.400s", PyString_AS_STRING(tmp)); |
| 5330 | failed: |
| 5331 | Py_XDECREF(tmp); |
| 5332 | return 1; |
| 5333 | } |
| 5334 | |
| 5335 | int |
| 5336 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 5337 | { |
| 5338 | PyObject* tmp = NULL; |
| 5339 | |
| 5340 | if (PyObject_IsInstance(obj, (PyObject*)Add_type)) { |
| 5341 | *out = Add; |
| 5342 | return 0; |
| 5343 | } |
| 5344 | if (PyObject_IsInstance(obj, (PyObject*)Sub_type)) { |
| 5345 | *out = Sub; |
| 5346 | return 0; |
| 5347 | } |
| 5348 | if (PyObject_IsInstance(obj, (PyObject*)Mult_type)) { |
| 5349 | *out = Mult; |
| 5350 | return 0; |
| 5351 | } |
| 5352 | if (PyObject_IsInstance(obj, (PyObject*)Div_type)) { |
| 5353 | *out = Div; |
| 5354 | return 0; |
| 5355 | } |
| 5356 | if (PyObject_IsInstance(obj, (PyObject*)Mod_type)) { |
| 5357 | *out = Mod; |
| 5358 | return 0; |
| 5359 | } |
| 5360 | if (PyObject_IsInstance(obj, (PyObject*)Pow_type)) { |
| 5361 | *out = Pow; |
| 5362 | return 0; |
| 5363 | } |
| 5364 | if (PyObject_IsInstance(obj, (PyObject*)LShift_type)) { |
| 5365 | *out = LShift; |
| 5366 | return 0; |
| 5367 | } |
| 5368 | if (PyObject_IsInstance(obj, (PyObject*)RShift_type)) { |
| 5369 | *out = RShift; |
| 5370 | return 0; |
| 5371 | } |
| 5372 | if (PyObject_IsInstance(obj, (PyObject*)BitOr_type)) { |
| 5373 | *out = BitOr; |
| 5374 | return 0; |
| 5375 | } |
| 5376 | if (PyObject_IsInstance(obj, (PyObject*)BitXor_type)) { |
| 5377 | *out = BitXor; |
| 5378 | return 0; |
| 5379 | } |
| 5380 | if (PyObject_IsInstance(obj, (PyObject*)BitAnd_type)) { |
| 5381 | *out = BitAnd; |
| 5382 | return 0; |
| 5383 | } |
| 5384 | if (PyObject_IsInstance(obj, (PyObject*)FloorDiv_type)) { |
| 5385 | *out = FloorDiv; |
| 5386 | return 0; |
| 5387 | } |
| 5388 | |
| 5389 | tmp = PyObject_Repr(obj); |
| 5390 | if (tmp == NULL) goto failed; |
| 5391 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %.400s", PyString_AS_STRING(tmp)); |
| 5392 | failed: |
| 5393 | Py_XDECREF(tmp); |
| 5394 | return 1; |
| 5395 | } |
| 5396 | |
| 5397 | int |
| 5398 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 5399 | { |
| 5400 | PyObject* tmp = NULL; |
| 5401 | |
| 5402 | if (PyObject_IsInstance(obj, (PyObject*)Invert_type)) { |
| 5403 | *out = Invert; |
| 5404 | return 0; |
| 5405 | } |
| 5406 | if (PyObject_IsInstance(obj, (PyObject*)Not_type)) { |
| 5407 | *out = Not; |
| 5408 | return 0; |
| 5409 | } |
| 5410 | if (PyObject_IsInstance(obj, (PyObject*)UAdd_type)) { |
| 5411 | *out = UAdd; |
| 5412 | return 0; |
| 5413 | } |
| 5414 | if (PyObject_IsInstance(obj, (PyObject*)USub_type)) { |
| 5415 | *out = USub; |
| 5416 | return 0; |
| 5417 | } |
| 5418 | |
| 5419 | tmp = PyObject_Repr(obj); |
| 5420 | if (tmp == NULL) goto failed; |
| 5421 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %.400s", PyString_AS_STRING(tmp)); |
| 5422 | failed: |
| 5423 | Py_XDECREF(tmp); |
| 5424 | return 1; |
| 5425 | } |
| 5426 | |
| 5427 | int |
| 5428 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 5429 | { |
| 5430 | PyObject* tmp = NULL; |
| 5431 | |
| 5432 | if (PyObject_IsInstance(obj, (PyObject*)Eq_type)) { |
| 5433 | *out = Eq; |
| 5434 | return 0; |
| 5435 | } |
| 5436 | if (PyObject_IsInstance(obj, (PyObject*)NotEq_type)) { |
| 5437 | *out = NotEq; |
| 5438 | return 0; |
| 5439 | } |
| 5440 | if (PyObject_IsInstance(obj, (PyObject*)Lt_type)) { |
| 5441 | *out = Lt; |
| 5442 | return 0; |
| 5443 | } |
| 5444 | if (PyObject_IsInstance(obj, (PyObject*)LtE_type)) { |
| 5445 | *out = LtE; |
| 5446 | return 0; |
| 5447 | } |
| 5448 | if (PyObject_IsInstance(obj, (PyObject*)Gt_type)) { |
| 5449 | *out = Gt; |
| 5450 | return 0; |
| 5451 | } |
| 5452 | if (PyObject_IsInstance(obj, (PyObject*)GtE_type)) { |
| 5453 | *out = GtE; |
| 5454 | return 0; |
| 5455 | } |
| 5456 | if (PyObject_IsInstance(obj, (PyObject*)Is_type)) { |
| 5457 | *out = Is; |
| 5458 | return 0; |
| 5459 | } |
| 5460 | if (PyObject_IsInstance(obj, (PyObject*)IsNot_type)) { |
| 5461 | *out = IsNot; |
| 5462 | return 0; |
| 5463 | } |
| 5464 | if (PyObject_IsInstance(obj, (PyObject*)In_type)) { |
| 5465 | *out = In; |
| 5466 | return 0; |
| 5467 | } |
| 5468 | if (PyObject_IsInstance(obj, (PyObject*)NotIn_type)) { |
| 5469 | *out = NotIn; |
| 5470 | return 0; |
| 5471 | } |
| 5472 | |
| 5473 | tmp = PyObject_Repr(obj); |
| 5474 | if (tmp == NULL) goto failed; |
| 5475 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %.400s", PyString_AS_STRING(tmp)); |
| 5476 | failed: |
| 5477 | Py_XDECREF(tmp); |
| 5478 | return 1; |
| 5479 | } |
| 5480 | |
| 5481 | int |
| 5482 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 5483 | { |
| 5484 | PyObject* tmp = NULL; |
| 5485 | expr_ty target; |
| 5486 | expr_ty iter; |
| 5487 | asdl_seq* ifs; |
| 5488 | |
| 5489 | if (PyObject_HasAttrString(obj, "target")) { |
| 5490 | int res; |
| 5491 | tmp = PyObject_GetAttrString(obj, "target"); |
| 5492 | if (tmp == NULL) goto failed; |
| 5493 | res = obj2ast_expr(tmp, &target, arena); |
| 5494 | if (res != 0) goto failed; |
| 5495 | Py_XDECREF(tmp); |
| 5496 | tmp = NULL; |
| 5497 | } else { |
| 5498 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 5499 | return 1; |
| 5500 | } |
| 5501 | if (PyObject_HasAttrString(obj, "iter")) { |
| 5502 | int res; |
| 5503 | tmp = PyObject_GetAttrString(obj, "iter"); |
| 5504 | if (tmp == NULL) goto failed; |
| 5505 | res = obj2ast_expr(tmp, &iter, arena); |
| 5506 | if (res != 0) goto failed; |
| 5507 | Py_XDECREF(tmp); |
| 5508 | tmp = NULL; |
| 5509 | } else { |
| 5510 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 5511 | return 1; |
| 5512 | } |
| 5513 | if (PyObject_HasAttrString(obj, "ifs")) { |
| 5514 | int res; |
| 5515 | Py_ssize_t len; |
| 5516 | Py_ssize_t i; |
| 5517 | tmp = PyObject_GetAttrString(obj, "ifs"); |
| 5518 | if (tmp == NULL) goto failed; |
| 5519 | if (!PyList_Check(tmp)) { |
| 5520 | PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5521 | goto failed; |
| 5522 | } |
| 5523 | len = PyList_GET_SIZE(tmp); |
| 5524 | ifs = asdl_seq_new(len, arena); |
| 5525 | if (ifs == NULL) goto failed; |
| 5526 | for (i = 0; i < len; i++) { |
| 5527 | expr_ty value; |
| 5528 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5529 | if (res != 0) goto failed; |
| 5530 | asdl_seq_SET(ifs, i, value); |
| 5531 | } |
| 5532 | Py_XDECREF(tmp); |
| 5533 | tmp = NULL; |
| 5534 | } else { |
| 5535 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 5536 | return 1; |
| 5537 | } |
| 5538 | *out = comprehension(target, iter, ifs, arena); |
| 5539 | return 0; |
| 5540 | failed: |
| 5541 | Py_XDECREF(tmp); |
| 5542 | return 1; |
| 5543 | } |
| 5544 | |
| 5545 | int |
| 5546 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 5547 | { |
| 5548 | PyObject* tmp = NULL; |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame^] | 5549 | |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5550 | int lineno; |
| 5551 | int col_offset; |
| 5552 | |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame^] | 5553 | if (obj == Py_None) { |
| 5554 | *out = NULL; |
| 5555 | return 0; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5556 | } |
| 5557 | if (PyObject_HasAttrString(obj, "lineno")) { |
| 5558 | int res; |
| 5559 | tmp = PyObject_GetAttrString(obj, "lineno"); |
| 5560 | if (tmp == NULL) goto failed; |
| 5561 | res = obj2ast_int(tmp, &lineno, arena); |
| 5562 | if (res != 0) goto failed; |
| 5563 | Py_XDECREF(tmp); |
| 5564 | tmp = NULL; |
| 5565 | } else { |
| 5566 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 5567 | return 1; |
| 5568 | } |
| 5569 | if (PyObject_HasAttrString(obj, "col_offset")) { |
| 5570 | int res; |
| 5571 | tmp = PyObject_GetAttrString(obj, "col_offset"); |
| 5572 | if (tmp == NULL) goto failed; |
| 5573 | res = obj2ast_int(tmp, &col_offset, arena); |
| 5574 | if (res != 0) goto failed; |
| 5575 | Py_XDECREF(tmp); |
| 5576 | tmp = NULL; |
| 5577 | } else { |
| 5578 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 5579 | return 1; |
| 5580 | } |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame^] | 5581 | if (PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type)) { |
| 5582 | expr_ty type; |
| 5583 | expr_ty name; |
| 5584 | asdl_seq* body; |
| 5585 | |
| 5586 | if (PyObject_HasAttrString(obj, "type")) { |
| 5587 | int res; |
| 5588 | tmp = PyObject_GetAttrString(obj, "type"); |
| 5589 | if (tmp == NULL) goto failed; |
| 5590 | res = obj2ast_expr(tmp, &type, arena); |
| 5591 | if (res != 0) goto failed; |
| 5592 | Py_XDECREF(tmp); |
| 5593 | tmp = NULL; |
| 5594 | } else { |
| 5595 | type = NULL; |
| 5596 | } |
| 5597 | if (PyObject_HasAttrString(obj, "name")) { |
| 5598 | int res; |
| 5599 | tmp = PyObject_GetAttrString(obj, "name"); |
| 5600 | if (tmp == NULL) goto failed; |
| 5601 | res = obj2ast_expr(tmp, &name, arena); |
| 5602 | if (res != 0) goto failed; |
| 5603 | Py_XDECREF(tmp); |
| 5604 | tmp = NULL; |
| 5605 | } else { |
| 5606 | name = NULL; |
| 5607 | } |
| 5608 | if (PyObject_HasAttrString(obj, "body")) { |
| 5609 | int res; |
| 5610 | Py_ssize_t len; |
| 5611 | Py_ssize_t i; |
| 5612 | tmp = PyObject_GetAttrString(obj, "body"); |
| 5613 | if (tmp == NULL) goto failed; |
| 5614 | if (!PyList_Check(tmp)) { |
| 5615 | PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5616 | goto failed; |
| 5617 | } |
| 5618 | len = PyList_GET_SIZE(tmp); |
| 5619 | body = asdl_seq_new(len, arena); |
| 5620 | if (body == NULL) goto failed; |
| 5621 | for (i = 0; i < len; i++) { |
| 5622 | stmt_ty value; |
| 5623 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5624 | if (res != 0) goto failed; |
| 5625 | asdl_seq_SET(body, i, value); |
| 5626 | } |
| 5627 | Py_XDECREF(tmp); |
| 5628 | tmp = NULL; |
| 5629 | } else { |
| 5630 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 5631 | return 1; |
| 5632 | } |
| 5633 | *out = ExceptHandler(type, name, body, lineno, col_offset, |
| 5634 | arena); |
| 5635 | if (*out == NULL) goto failed; |
| 5636 | return 0; |
| 5637 | } |
| 5638 | |
| 5639 | tmp = PyObject_Repr(obj); |
| 5640 | if (tmp == NULL) goto failed; |
| 5641 | 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] | 5642 | failed: |
| 5643 | Py_XDECREF(tmp); |
| 5644 | return 1; |
| 5645 | } |
| 5646 | |
| 5647 | int |
| 5648 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 5649 | { |
| 5650 | PyObject* tmp = NULL; |
| 5651 | asdl_seq* args; |
| 5652 | identifier vararg; |
| 5653 | identifier kwarg; |
| 5654 | asdl_seq* defaults; |
| 5655 | |
| 5656 | if (PyObject_HasAttrString(obj, "args")) { |
| 5657 | int res; |
| 5658 | Py_ssize_t len; |
| 5659 | Py_ssize_t i; |
| 5660 | tmp = PyObject_GetAttrString(obj, "args"); |
| 5661 | if (tmp == NULL) goto failed; |
| 5662 | if (!PyList_Check(tmp)) { |
| 5663 | PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5664 | goto failed; |
| 5665 | } |
| 5666 | len = PyList_GET_SIZE(tmp); |
| 5667 | args = asdl_seq_new(len, arena); |
| 5668 | if (args == NULL) goto failed; |
| 5669 | for (i = 0; i < len; i++) { |
| 5670 | expr_ty value; |
| 5671 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5672 | if (res != 0) goto failed; |
| 5673 | asdl_seq_SET(args, i, value); |
| 5674 | } |
| 5675 | Py_XDECREF(tmp); |
| 5676 | tmp = NULL; |
| 5677 | } else { |
| 5678 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 5679 | return 1; |
| 5680 | } |
| 5681 | if (PyObject_HasAttrString(obj, "vararg")) { |
| 5682 | int res; |
| 5683 | tmp = PyObject_GetAttrString(obj, "vararg"); |
| 5684 | if (tmp == NULL) goto failed; |
| 5685 | res = obj2ast_identifier(tmp, &vararg, arena); |
| 5686 | if (res != 0) goto failed; |
| 5687 | Py_XDECREF(tmp); |
| 5688 | tmp = NULL; |
| 5689 | } else { |
| 5690 | vararg = NULL; |
| 5691 | } |
| 5692 | if (PyObject_HasAttrString(obj, "kwarg")) { |
| 5693 | int res; |
| 5694 | tmp = PyObject_GetAttrString(obj, "kwarg"); |
| 5695 | if (tmp == NULL) goto failed; |
| 5696 | res = obj2ast_identifier(tmp, &kwarg, arena); |
| 5697 | if (res != 0) goto failed; |
| 5698 | Py_XDECREF(tmp); |
| 5699 | tmp = NULL; |
| 5700 | } else { |
| 5701 | kwarg = NULL; |
| 5702 | } |
| 5703 | if (PyObject_HasAttrString(obj, "defaults")) { |
| 5704 | int res; |
| 5705 | Py_ssize_t len; |
| 5706 | Py_ssize_t i; |
| 5707 | tmp = PyObject_GetAttrString(obj, "defaults"); |
| 5708 | if (tmp == NULL) goto failed; |
| 5709 | if (!PyList_Check(tmp)) { |
| 5710 | PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5711 | goto failed; |
| 5712 | } |
| 5713 | len = PyList_GET_SIZE(tmp); |
| 5714 | defaults = asdl_seq_new(len, arena); |
| 5715 | if (defaults == NULL) goto failed; |
| 5716 | for (i = 0; i < len; i++) { |
| 5717 | expr_ty value; |
| 5718 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5719 | if (res != 0) goto failed; |
| 5720 | asdl_seq_SET(defaults, i, value); |
| 5721 | } |
| 5722 | Py_XDECREF(tmp); |
| 5723 | tmp = NULL; |
| 5724 | } else { |
| 5725 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 5726 | return 1; |
| 5727 | } |
| 5728 | *out = arguments(args, vararg, kwarg, defaults, arena); |
| 5729 | return 0; |
| 5730 | failed: |
| 5731 | Py_XDECREF(tmp); |
| 5732 | return 1; |
| 5733 | } |
| 5734 | |
| 5735 | int |
| 5736 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 5737 | { |
| 5738 | PyObject* tmp = NULL; |
| 5739 | identifier arg; |
| 5740 | expr_ty value; |
| 5741 | |
| 5742 | if (PyObject_HasAttrString(obj, "arg")) { |
| 5743 | int res; |
| 5744 | tmp = PyObject_GetAttrString(obj, "arg"); |
| 5745 | if (tmp == NULL) goto failed; |
| 5746 | res = obj2ast_identifier(tmp, &arg, arena); |
| 5747 | if (res != 0) goto failed; |
| 5748 | Py_XDECREF(tmp); |
| 5749 | tmp = NULL; |
| 5750 | } else { |
| 5751 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from keyword"); |
| 5752 | return 1; |
| 5753 | } |
| 5754 | if (PyObject_HasAttrString(obj, "value")) { |
| 5755 | int res; |
| 5756 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5757 | if (tmp == NULL) goto failed; |
| 5758 | res = obj2ast_expr(tmp, &value, arena); |
| 5759 | if (res != 0) goto failed; |
| 5760 | Py_XDECREF(tmp); |
| 5761 | tmp = NULL; |
| 5762 | } else { |
| 5763 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 5764 | return 1; |
| 5765 | } |
| 5766 | *out = keyword(arg, value, arena); |
| 5767 | return 0; |
| 5768 | failed: |
| 5769 | Py_XDECREF(tmp); |
| 5770 | return 1; |
| 5771 | } |
| 5772 | |
| 5773 | int |
| 5774 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 5775 | { |
| 5776 | PyObject* tmp = NULL; |
| 5777 | identifier name; |
| 5778 | identifier asname; |
| 5779 | |
| 5780 | if (PyObject_HasAttrString(obj, "name")) { |
| 5781 | int res; |
| 5782 | tmp = PyObject_GetAttrString(obj, "name"); |
| 5783 | if (tmp == NULL) goto failed; |
| 5784 | res = obj2ast_identifier(tmp, &name, arena); |
| 5785 | if (res != 0) goto failed; |
| 5786 | Py_XDECREF(tmp); |
| 5787 | tmp = NULL; |
| 5788 | } else { |
| 5789 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 5790 | return 1; |
| 5791 | } |
| 5792 | if (PyObject_HasAttrString(obj, "asname")) { |
| 5793 | int res; |
| 5794 | tmp = PyObject_GetAttrString(obj, "asname"); |
| 5795 | if (tmp == NULL) goto failed; |
| 5796 | res = obj2ast_identifier(tmp, &asname, arena); |
| 5797 | if (res != 0) goto failed; |
| 5798 | Py_XDECREF(tmp); |
| 5799 | tmp = NULL; |
| 5800 | } else { |
| 5801 | asname = NULL; |
| 5802 | } |
| 5803 | *out = alias(name, asname, arena); |
| 5804 | return 0; |
| 5805 | failed: |
| 5806 | Py_XDECREF(tmp); |
| 5807 | return 1; |
| 5808 | } |
| 5809 | |
| 5810 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 5811 | PyMODINIT_FUNC |
| 5812 | init_ast(void) |
| 5813 | { |
| 5814 | PyObject *m, *d; |
| 5815 | if (!init_types()) return; |
| 5816 | m = Py_InitModule3("_ast", NULL, NULL); |
| 5817 | if (!m) return; |
| 5818 | d = PyModule_GetDict(m); |
| 5819 | if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return; |
| 5820 | if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) |
| 5821 | return; |
Christian Heimes | 4034685 | 2008-02-23 17:52:07 +0000 | [diff] [blame] | 5822 | if (PyModule_AddStringConstant(m, "__version__", "60978") < 0) |
Martin v. Löwis | ace990c | 2006-02-28 00:32:31 +0000 | [diff] [blame] | 5823 | return; |
Neal Norwitz | 19379f1 | 2006-04-03 04:50:58 +0000 | [diff] [blame] | 5824 | if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return; |
| 5825 | if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) |
| 5826 | return; |
| 5827 | if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) |
| 5828 | < 0) return; |
| 5829 | if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < |
| 5830 | 0) return; |
| 5831 | if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return; |
| 5832 | if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return; |
| 5833 | if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) |
| 5834 | < 0) return; |
| 5835 | if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) |
| 5836 | return; |
| 5837 | if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) |
| 5838 | return; |
| 5839 | if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) |
| 5840 | return; |
| 5841 | if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) |
| 5842 | return; |
| 5843 | if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < |
| 5844 | 0) return; |
| 5845 | if (PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return; |
| 5846 | if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return; |
| 5847 | if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return; |
| 5848 | if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return; |
| 5849 | if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return; |
| 5850 | if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return; |
| 5851 | if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) < |
| 5852 | 0) return; |
| 5853 | if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) < |
| 5854 | 0) return; |
| 5855 | if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) |
| 5856 | return; |
| 5857 | if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) |
| 5858 | return; |
| 5859 | if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < |
| 5860 | 0) return; |
| 5861 | if (PyDict_SetItemString(d, "Exec", (PyObject*)Exec_type) < 0) return; |
| 5862 | if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) |
| 5863 | return; |
| 5864 | if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return; |
| 5865 | if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return; |
| 5866 | if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return; |
| 5867 | if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) |
| 5868 | return; |
| 5869 | if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return; |
| 5870 | if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) |
| 5871 | return; |
| 5872 | if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return; |
| 5873 | if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) |
| 5874 | return; |
| 5875 | if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) |
| 5876 | return; |
| 5877 | if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return; |
| 5878 | if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return; |
| 5879 | if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) |
| 5880 | return; |
| 5881 | if (PyDict_SetItemString(d, "GeneratorExp", |
| 5882 | (PyObject*)GeneratorExp_type) < 0) return; |
| 5883 | if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return; |
| 5884 | if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) |
| 5885 | return; |
| 5886 | if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return; |
| 5887 | if (PyDict_SetItemString(d, "Repr", (PyObject*)Repr_type) < 0) return; |
| 5888 | if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return; |
| 5889 | if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return; |
| 5890 | if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < |
| 5891 | 0) return; |
| 5892 | if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < |
| 5893 | 0) return; |
| 5894 | if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return; |
| 5895 | if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return; |
| 5896 | if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return; |
| 5897 | if (PyDict_SetItemString(d, "expr_context", |
| 5898 | (PyObject*)expr_context_type) < 0) return; |
| 5899 | if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return; |
| 5900 | if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return; |
| 5901 | if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return; |
| 5902 | if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) |
| 5903 | return; |
| 5904 | if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) |
| 5905 | return; |
| 5906 | if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return; |
| 5907 | if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return; |
| 5908 | if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0) |
| 5909 | return; |
| 5910 | if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return; |
| 5911 | if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) |
| 5912 | return; |
| 5913 | if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return; |
| 5914 | if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) |
| 5915 | return; |
| 5916 | if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return; |
| 5917 | if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return; |
| 5918 | if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) |
| 5919 | return; |
| 5920 | if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return; |
| 5921 | if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return; |
| 5922 | if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return; |
| 5923 | if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return; |
| 5924 | if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return; |
| 5925 | if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return; |
| 5926 | if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) |
| 5927 | return; |
| 5928 | if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) |
| 5929 | return; |
| 5930 | if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return; |
| 5931 | if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) |
| 5932 | return; |
| 5933 | if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) |
| 5934 | return; |
| 5935 | if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) |
| 5936 | return; |
| 5937 | if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) |
| 5938 | return; |
| 5939 | if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) |
| 5940 | return; |
| 5941 | if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return; |
| 5942 | if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return; |
| 5943 | if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return; |
| 5944 | if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return; |
| 5945 | if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return; |
| 5946 | if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return; |
| 5947 | if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return; |
| 5948 | if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return; |
| 5949 | if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return; |
| 5950 | if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return; |
| 5951 | if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return; |
| 5952 | if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return; |
| 5953 | if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return; |
| 5954 | if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return; |
| 5955 | if (PyDict_SetItemString(d, "comprehension", |
| 5956 | (PyObject*)comprehension_type) < 0) return; |
| 5957 | if (PyDict_SetItemString(d, "excepthandler", |
| 5958 | (PyObject*)excepthandler_type) < 0) return; |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame^] | 5959 | if (PyDict_SetItemString(d, "ExceptHandler", |
| 5960 | (PyObject*)ExceptHandler_type) < 0) return; |
Neal Norwitz | 19379f1 | 2006-04-03 04:50:58 +0000 | [diff] [blame] | 5961 | if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < |
| 5962 | 0) return; |
| 5963 | if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) |
| 5964 | return; |
| 5965 | if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 5966 | } |
| 5967 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 5968 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 5969 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 5970 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 5971 | init_types(); |
| 5972 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 5973 | } |
| 5974 | |
Georg Brandl | f2bfd54 | 2008-03-29 13:24:23 +0000 | [diff] [blame] | 5975 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 5976 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5977 | { |
| 5978 | mod_ty res; |
Georg Brandl | f2bfd54 | 2008-03-29 13:24:23 +0000 | [diff] [blame] | 5979 | PyObject *req_type[] = {(PyObject*)Module_type, (PyObject*)Expression_type, |
| 5980 | (PyObject*)Interactive_type}; |
| 5981 | char *req_name[] = {"Module", "Expression", "Interactive"}; |
| 5982 | assert(0 <= mode && mode <= 2); |
| 5983 | |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5984 | init_types(); |
Georg Brandl | f2bfd54 | 2008-03-29 13:24:23 +0000 | [diff] [blame] | 5985 | |
| 5986 | if (!PyObject_IsInstance(ast, req_type[mode])) { |
| 5987 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
| 5988 | req_name[mode], Py_TYPE(ast)->tp_name); |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5989 | return NULL; |
| 5990 | } |
| 5991 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 5992 | return NULL; |
| 5993 | else |
| 5994 | return res; |
| 5995 | } |
| 5996 | |
| 5997 | int PyAST_Check(PyObject* obj) |
| 5998 | { |
| 5999 | init_types(); |
| 6000 | return PyObject_IsInstance(obj, (PyObject*)AST_type); |
| 6001 | } |
| 6002 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 6003 | |