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