Brett Cannon | 0db62aa | 2007-02-12 03:51:02 +0000 | [diff] [blame] | 1 | /* File automatically generated by Parser/asdl_c.py. */ |
| 2 | |
| 3 | |
| 4 | /* |
Brett Cannon | 3ad57e2 | 2010-01-10 02:48:50 +0000 | [diff] [blame] | 5 | __version__ 77400. |
Brett Cannon | 0db62aa | 2007-02-12 03:51:02 +0000 | [diff] [blame] | 6 | |
| 7 | This module must be committed separately after each AST grammar change; |
| 8 | The __version__ number is set to the revision number of the commit |
| 9 | containing the grammar change. |
| 10 | */ |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 11 | |
| 12 | #include "Python.h" |
| 13 | #include "Python-ast.h" |
| 14 | |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 15 | static PyTypeObject AST_type; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 16 | static PyTypeObject *mod_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 17 | static PyObject* ast2obj_mod(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 18 | static PyTypeObject *Module_type; |
| 19 | static char *Module_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 20 | "body", |
| 21 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 22 | static PyTypeObject *Interactive_type; |
| 23 | static char *Interactive_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 24 | "body", |
| 25 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 26 | static PyTypeObject *Expression_type; |
| 27 | static char *Expression_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 28 | "body", |
| 29 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 30 | static PyTypeObject *Suite_type; |
| 31 | static char *Suite_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 32 | "body", |
| 33 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 34 | static PyTypeObject *stmt_type; |
| 35 | static char *stmt_attributes[] = { |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 36 | "lineno", |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 37 | "col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 38 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 39 | static PyObject* ast2obj_stmt(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 40 | static PyTypeObject *FunctionDef_type; |
| 41 | static char *FunctionDef_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 42 | "name", |
| 43 | "args", |
| 44 | "body", |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 45 | "decorator_list", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 46 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 47 | static PyTypeObject *ClassDef_type; |
| 48 | static char *ClassDef_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 49 | "name", |
| 50 | "bases", |
| 51 | "body", |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 52 | "decorator_list", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 53 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 54 | static PyTypeObject *Return_type; |
| 55 | static char *Return_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 56 | "value", |
| 57 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 58 | static PyTypeObject *Delete_type; |
| 59 | static char *Delete_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 60 | "targets", |
| 61 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 62 | static PyTypeObject *Assign_type; |
| 63 | static char *Assign_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 64 | "targets", |
| 65 | "value", |
| 66 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 67 | static PyTypeObject *AugAssign_type; |
| 68 | static char *AugAssign_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 69 | "target", |
| 70 | "op", |
| 71 | "value", |
| 72 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 73 | static PyTypeObject *Print_type; |
| 74 | static char *Print_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 75 | "dest", |
| 76 | "values", |
| 77 | "nl", |
| 78 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 79 | static PyTypeObject *For_type; |
| 80 | static char *For_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 81 | "target", |
| 82 | "iter", |
| 83 | "body", |
| 84 | "orelse", |
| 85 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 86 | static PyTypeObject *While_type; |
| 87 | static char *While_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 88 | "test", |
| 89 | "body", |
| 90 | "orelse", |
| 91 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 92 | static PyTypeObject *If_type; |
| 93 | static char *If_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 94 | "test", |
| 95 | "body", |
| 96 | "orelse", |
| 97 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 98 | static PyTypeObject *With_type; |
| 99 | static char *With_fields[]={ |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 100 | "context_expr", |
| 101 | "optional_vars", |
| 102 | "body", |
| 103 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 104 | static PyTypeObject *Raise_type; |
| 105 | static char *Raise_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 106 | "type", |
| 107 | "inst", |
| 108 | "tback", |
| 109 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 110 | static PyTypeObject *TryExcept_type; |
| 111 | static char *TryExcept_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 112 | "body", |
| 113 | "handlers", |
| 114 | "orelse", |
| 115 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 116 | static PyTypeObject *TryFinally_type; |
| 117 | static char *TryFinally_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 118 | "body", |
| 119 | "finalbody", |
| 120 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 121 | static PyTypeObject *Assert_type; |
| 122 | static char *Assert_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 123 | "test", |
| 124 | "msg", |
| 125 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 126 | static PyTypeObject *Import_type; |
| 127 | static char *Import_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 128 | "names", |
| 129 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 130 | static PyTypeObject *ImportFrom_type; |
| 131 | static char *ImportFrom_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 132 | "module", |
| 133 | "names", |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 134 | "level", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 135 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 136 | static PyTypeObject *Exec_type; |
| 137 | static char *Exec_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 138 | "body", |
| 139 | "globals", |
| 140 | "locals", |
| 141 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 142 | static PyTypeObject *Global_type; |
| 143 | static char *Global_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 144 | "names", |
| 145 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 146 | static PyTypeObject *Expr_type; |
| 147 | static char *Expr_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 148 | "value", |
| 149 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 150 | static PyTypeObject *Pass_type; |
| 151 | static PyTypeObject *Break_type; |
| 152 | static PyTypeObject *Continue_type; |
| 153 | static PyTypeObject *expr_type; |
| 154 | static char *expr_attributes[] = { |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 155 | "lineno", |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 156 | "col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 157 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 158 | static PyObject* ast2obj_expr(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 159 | static PyTypeObject *BoolOp_type; |
| 160 | static char *BoolOp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 161 | "op", |
| 162 | "values", |
| 163 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 164 | static PyTypeObject *BinOp_type; |
| 165 | static char *BinOp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 166 | "left", |
| 167 | "op", |
| 168 | "right", |
| 169 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 170 | static PyTypeObject *UnaryOp_type; |
| 171 | static char *UnaryOp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 172 | "op", |
| 173 | "operand", |
| 174 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 175 | static PyTypeObject *Lambda_type; |
| 176 | static char *Lambda_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 177 | "args", |
| 178 | "body", |
| 179 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 180 | static PyTypeObject *IfExp_type; |
| 181 | static char *IfExp_fields[]={ |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 182 | "test", |
| 183 | "body", |
| 184 | "orelse", |
| 185 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 186 | static PyTypeObject *Dict_type; |
| 187 | static char *Dict_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 188 | "keys", |
| 189 | "values", |
| 190 | }; |
Alexandre Vassalotti | ee936a2 | 2010-01-09 23:35:54 +0000 | [diff] [blame] | 191 | static PyTypeObject *Set_type; |
| 192 | static char *Set_fields[]={ |
| 193 | "elts", |
| 194 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 195 | static PyTypeObject *ListComp_type; |
| 196 | static char *ListComp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 197 | "elt", |
| 198 | "generators", |
| 199 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 200 | static PyTypeObject *GeneratorExp_type; |
| 201 | static char *GeneratorExp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 202 | "elt", |
| 203 | "generators", |
| 204 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 205 | static PyTypeObject *Yield_type; |
| 206 | static char *Yield_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 207 | "value", |
| 208 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 209 | static PyTypeObject *Compare_type; |
| 210 | static char *Compare_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 211 | "left", |
| 212 | "ops", |
| 213 | "comparators", |
| 214 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 215 | static PyTypeObject *Call_type; |
| 216 | static char *Call_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 217 | "func", |
| 218 | "args", |
| 219 | "keywords", |
| 220 | "starargs", |
| 221 | "kwargs", |
| 222 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 223 | static PyTypeObject *Repr_type; |
| 224 | static char *Repr_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 225 | "value", |
| 226 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 227 | static PyTypeObject *Num_type; |
| 228 | static char *Num_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 229 | "n", |
| 230 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 231 | static PyTypeObject *Str_type; |
| 232 | static char *Str_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 233 | "s", |
| 234 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 235 | static PyTypeObject *Attribute_type; |
| 236 | static char *Attribute_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 237 | "value", |
| 238 | "attr", |
| 239 | "ctx", |
| 240 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 241 | static PyTypeObject *Subscript_type; |
| 242 | static char *Subscript_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 243 | "value", |
| 244 | "slice", |
| 245 | "ctx", |
| 246 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 247 | static PyTypeObject *Name_type; |
| 248 | static char *Name_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 249 | "id", |
| 250 | "ctx", |
| 251 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 252 | static PyTypeObject *List_type; |
| 253 | static char *List_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 254 | "elts", |
| 255 | "ctx", |
| 256 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 257 | static PyTypeObject *Tuple_type; |
| 258 | static char *Tuple_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 259 | "elts", |
| 260 | "ctx", |
| 261 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 262 | static PyTypeObject *expr_context_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 263 | static PyObject *Load_singleton, *Store_singleton, *Del_singleton, |
| 264 | *AugLoad_singleton, *AugStore_singleton, *Param_singleton; |
| 265 | static PyObject* ast2obj_expr_context(expr_context_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 266 | static PyTypeObject *Load_type; |
| 267 | static PyTypeObject *Store_type; |
| 268 | static PyTypeObject *Del_type; |
| 269 | static PyTypeObject *AugLoad_type; |
| 270 | static PyTypeObject *AugStore_type; |
| 271 | static PyTypeObject *Param_type; |
| 272 | static PyTypeObject *slice_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 273 | static PyObject* ast2obj_slice(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 274 | static PyTypeObject *Ellipsis_type; |
| 275 | static PyTypeObject *Slice_type; |
| 276 | static char *Slice_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 277 | "lower", |
| 278 | "upper", |
| 279 | "step", |
| 280 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 281 | static PyTypeObject *ExtSlice_type; |
| 282 | static char *ExtSlice_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 283 | "dims", |
| 284 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 285 | static PyTypeObject *Index_type; |
| 286 | static char *Index_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 287 | "value", |
| 288 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 289 | static PyTypeObject *boolop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 290 | static PyObject *And_singleton, *Or_singleton; |
| 291 | static PyObject* ast2obj_boolop(boolop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 292 | static PyTypeObject *And_type; |
| 293 | static PyTypeObject *Or_type; |
| 294 | static PyTypeObject *operator_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 295 | static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton, |
| 296 | *Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton, |
| 297 | *RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton, |
| 298 | *FloorDiv_singleton; |
| 299 | static PyObject* ast2obj_operator(operator_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 300 | static PyTypeObject *Add_type; |
| 301 | static PyTypeObject *Sub_type; |
| 302 | static PyTypeObject *Mult_type; |
| 303 | static PyTypeObject *Div_type; |
| 304 | static PyTypeObject *Mod_type; |
| 305 | static PyTypeObject *Pow_type; |
| 306 | static PyTypeObject *LShift_type; |
| 307 | static PyTypeObject *RShift_type; |
| 308 | static PyTypeObject *BitOr_type; |
| 309 | static PyTypeObject *BitXor_type; |
| 310 | static PyTypeObject *BitAnd_type; |
| 311 | static PyTypeObject *FloorDiv_type; |
| 312 | static PyTypeObject *unaryop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 313 | static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton, |
| 314 | *USub_singleton; |
| 315 | static PyObject* ast2obj_unaryop(unaryop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 316 | static PyTypeObject *Invert_type; |
| 317 | static PyTypeObject *Not_type; |
| 318 | static PyTypeObject *UAdd_type; |
| 319 | static PyTypeObject *USub_type; |
| 320 | static PyTypeObject *cmpop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 321 | static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton, |
| 322 | *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton, |
| 323 | *NotIn_singleton; |
| 324 | static PyObject* ast2obj_cmpop(cmpop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 325 | static PyTypeObject *Eq_type; |
| 326 | static PyTypeObject *NotEq_type; |
| 327 | static PyTypeObject *Lt_type; |
| 328 | static PyTypeObject *LtE_type; |
| 329 | static PyTypeObject *Gt_type; |
| 330 | static PyTypeObject *GtE_type; |
| 331 | static PyTypeObject *Is_type; |
| 332 | static PyTypeObject *IsNot_type; |
| 333 | static PyTypeObject *In_type; |
| 334 | static PyTypeObject *NotIn_type; |
| 335 | static PyTypeObject *comprehension_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 336 | static PyObject* ast2obj_comprehension(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 337 | static char *comprehension_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 338 | "target", |
| 339 | "iter", |
| 340 | "ifs", |
| 341 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 342 | static PyTypeObject *excepthandler_type; |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame] | 343 | static char *excepthandler_attributes[] = { |
| 344 | "lineno", |
| 345 | "col_offset", |
| 346 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 347 | static PyObject* ast2obj_excepthandler(void*); |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame] | 348 | static PyTypeObject *ExceptHandler_type; |
| 349 | static char *ExceptHandler_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 350 | "type", |
| 351 | "name", |
| 352 | "body", |
| 353 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 354 | static PyTypeObject *arguments_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 355 | static PyObject* ast2obj_arguments(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 356 | static char *arguments_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 357 | "args", |
| 358 | "vararg", |
| 359 | "kwarg", |
| 360 | "defaults", |
| 361 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 362 | static PyTypeObject *keyword_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 363 | static PyObject* ast2obj_keyword(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 364 | static char *keyword_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 365 | "arg", |
| 366 | "value", |
| 367 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 368 | static PyTypeObject *alias_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 369 | static PyObject* ast2obj_alias(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 370 | static char *alias_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 371 | "name", |
| 372 | "asname", |
| 373 | }; |
| 374 | |
| 375 | |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 376 | static int |
| 377 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 378 | { |
| 379 | Py_ssize_t i, numfields = 0; |
| 380 | int res = -1; |
| 381 | PyObject *key, *value, *fields; |
| 382 | fields = PyObject_GetAttrString((PyObject*)Py_TYPE(self), "_fields"); |
| 383 | if (!fields) |
| 384 | PyErr_Clear(); |
| 385 | if (fields) { |
| 386 | numfields = PySequence_Size(fields); |
| 387 | if (numfields == -1) |
| 388 | goto cleanup; |
| 389 | } |
| 390 | res = 0; /* if no error occurs, this stays 0 to the end */ |
| 391 | if (PyTuple_GET_SIZE(args) > 0) { |
| 392 | if (numfields != PyTuple_GET_SIZE(args)) { |
Georg Brandl | 1721e75 | 2008-03-30 19:43:27 +0000 | [diff] [blame] | 393 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes %s" |
Amaury Forgeot d'Arc | 05e3449 | 2008-09-10 22:04:45 +0000 | [diff] [blame] | 394 | "%zd positional argument%s", |
Georg Brandl | 1721e75 | 2008-03-30 19:43:27 +0000 | [diff] [blame] | 395 | Py_TYPE(self)->tp_name, |
| 396 | numfields == 0 ? "" : "either 0 or ", |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 397 | numfields, numfields == 1 ? "" : "s"); |
| 398 | res = -1; |
| 399 | goto cleanup; |
| 400 | } |
| 401 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
| 402 | /* cannot be reached when fields is NULL */ |
| 403 | PyObject *name = PySequence_GetItem(fields, i); |
| 404 | if (!name) { |
| 405 | res = -1; |
| 406 | goto cleanup; |
| 407 | } |
| 408 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
| 409 | Py_DECREF(name); |
| 410 | if (res < 0) |
| 411 | goto cleanup; |
| 412 | } |
| 413 | } |
| 414 | if (kw) { |
| 415 | i = 0; /* needed by PyDict_Next */ |
| 416 | while (PyDict_Next(kw, &i, &key, &value)) { |
| 417 | res = PyObject_SetAttr(self, key, value); |
| 418 | if (res < 0) |
| 419 | goto cleanup; |
| 420 | } |
| 421 | } |
| 422 | cleanup: |
| 423 | Py_XDECREF(fields); |
| 424 | return res; |
| 425 | } |
| 426 | |
Georg Brandl | e34c21c | 2008-03-30 20:20:39 +0000 | [diff] [blame] | 427 | /* Pickling support */ |
| 428 | static PyObject * |
| 429 | ast_type_reduce(PyObject *self, PyObject *unused) |
| 430 | { |
| 431 | PyObject *res; |
| 432 | PyObject *dict = PyObject_GetAttrString(self, "__dict__"); |
| 433 | if (dict == NULL) { |
| 434 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) |
| 435 | PyErr_Clear(); |
| 436 | else |
| 437 | return NULL; |
| 438 | } |
| 439 | if (dict) { |
| 440 | res = Py_BuildValue("O()O", Py_TYPE(self), dict); |
| 441 | Py_DECREF(dict); |
| 442 | return res; |
| 443 | } |
| 444 | return Py_BuildValue("O()", Py_TYPE(self)); |
| 445 | } |
| 446 | |
| 447 | static PyMethodDef ast_type_methods[] = { |
| 448 | {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, |
| 449 | {NULL} |
| 450 | }; |
| 451 | |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 452 | static PyTypeObject AST_type = { |
| 453 | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
Georg Brandl | e34c21c | 2008-03-30 20:20:39 +0000 | [diff] [blame] | 454 | "_ast.AST", |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 455 | sizeof(PyObject), |
| 456 | 0, |
| 457 | 0, /* tp_dealloc */ |
| 458 | 0, /* tp_print */ |
| 459 | 0, /* tp_getattr */ |
| 460 | 0, /* tp_setattr */ |
| 461 | 0, /* tp_compare */ |
| 462 | 0, /* tp_repr */ |
| 463 | 0, /* tp_as_number */ |
| 464 | 0, /* tp_as_sequence */ |
| 465 | 0, /* tp_as_mapping */ |
| 466 | 0, /* tp_hash */ |
| 467 | 0, /* tp_call */ |
| 468 | 0, /* tp_str */ |
| 469 | PyObject_GenericGetAttr, /* tp_getattro */ |
| 470 | PyObject_GenericSetAttr, /* tp_setattro */ |
| 471 | 0, /* tp_as_buffer */ |
| 472 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
| 473 | 0, /* tp_doc */ |
| 474 | 0, /* tp_traverse */ |
| 475 | 0, /* tp_clear */ |
| 476 | 0, /* tp_richcompare */ |
| 477 | 0, /* tp_weaklistoffset */ |
| 478 | 0, /* tp_iter */ |
| 479 | 0, /* tp_iternext */ |
Georg Brandl | e34c21c | 2008-03-30 20:20:39 +0000 | [diff] [blame] | 480 | ast_type_methods, /* tp_methods */ |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 481 | 0, /* tp_members */ |
| 482 | 0, /* tp_getset */ |
| 483 | 0, /* tp_base */ |
| 484 | 0, /* tp_dict */ |
| 485 | 0, /* tp_descr_get */ |
| 486 | 0, /* tp_descr_set */ |
| 487 | 0, /* tp_dictoffset */ |
| 488 | (initproc)ast_type_init, /* tp_init */ |
| 489 | PyType_GenericAlloc, /* tp_alloc */ |
| 490 | PyType_GenericNew, /* tp_new */ |
| 491 | PyObject_Del, /* tp_free */ |
| 492 | }; |
| 493 | |
| 494 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 495 | static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields) |
| 496 | { |
| 497 | PyObject *fnames, *result; |
| 498 | int i; |
Georg Brandl | 2c55c59 | 2008-03-30 19:00:49 +0000 | [diff] [blame] | 499 | fnames = PyTuple_New(num_fields); |
| 500 | if (!fnames) return NULL; |
| 501 | for (i = 0; i < num_fields; i++) { |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 502 | PyObject *field = PyString_FromString(fields[i]); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 503 | if (!field) { |
| 504 | Py_DECREF(fnames); |
| 505 | return NULL; |
| 506 | } |
| 507 | PyTuple_SET_ITEM(fnames, i, field); |
| 508 | } |
Thomas Wouters | 34aa7ba | 2006-02-28 19:02:24 +0000 | [diff] [blame] | 509 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 510 | type, base, "_fields", fnames, "__module__", "_ast"); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 511 | Py_DECREF(fnames); |
| 512 | return (PyTypeObject*)result; |
| 513 | } |
| 514 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 515 | static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) |
| 516 | { |
Neal Norwitz | 19379f1 | 2006-04-03 04:50:58 +0000 | [diff] [blame] | 517 | int i, result; |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 518 | PyObject *s, *l = PyTuple_New(num_fields); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 519 | if (!l) return 0; |
Neal Norwitz | 19379f1 | 2006-04-03 04:50:58 +0000 | [diff] [blame] | 520 | for(i = 0; i < num_fields; i++) { |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 521 | s = PyString_FromString(attrs[i]); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 522 | if (!s) { |
| 523 | Py_DECREF(l); |
| 524 | return 0; |
| 525 | } |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 526 | PyTuple_SET_ITEM(l, i, s); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 527 | } |
Neal Norwitz | 19379f1 | 2006-04-03 04:50:58 +0000 | [diff] [blame] | 528 | result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0; |
| 529 | Py_DECREF(l); |
| 530 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 531 | } |
| 532 | |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 533 | /* Conversion AST -> Python */ |
| 534 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 535 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 536 | { |
| 537 | int i, n = asdl_seq_LEN(seq); |
| 538 | PyObject *result = PyList_New(n); |
| 539 | PyObject *value; |
| 540 | if (!result) |
| 541 | return NULL; |
| 542 | for (i = 0; i < n; i++) { |
| 543 | value = func(asdl_seq_GET(seq, i)); |
| 544 | if (!value) { |
| 545 | Py_DECREF(result); |
| 546 | return NULL; |
| 547 | } |
| 548 | PyList_SET_ITEM(result, i, value); |
| 549 | } |
| 550 | return result; |
| 551 | } |
| 552 | |
| 553 | static PyObject* ast2obj_object(void *o) |
| 554 | { |
| 555 | if (!o) |
| 556 | o = Py_None; |
| 557 | Py_INCREF((PyObject*)o); |
| 558 | return (PyObject*)o; |
| 559 | } |
| 560 | #define ast2obj_identifier ast2obj_object |
| 561 | #define ast2obj_string ast2obj_object |
| 562 | static PyObject* ast2obj_bool(bool b) |
| 563 | { |
| 564 | return PyBool_FromLong(b); |
| 565 | } |
| 566 | |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 567 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 568 | { |
| 569 | return PyInt_FromLong(b); |
| 570 | } |
| 571 | |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 572 | /* Conversion Python -> AST */ |
| 573 | |
| 574 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 575 | { |
| 576 | if (obj == Py_None) |
| 577 | obj = NULL; |
| 578 | if (obj) |
| 579 | PyArena_AddPyObject(arena, obj); |
| 580 | Py_XINCREF(obj); |
| 581 | *out = obj; |
| 582 | return 0; |
| 583 | } |
| 584 | |
| 585 | #define obj2ast_identifier obj2ast_object |
| 586 | #define obj2ast_string obj2ast_object |
| 587 | |
| 588 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 589 | { |
| 590 | int i; |
| 591 | if (!PyInt_Check(obj) && !PyLong_Check(obj)) { |
| 592 | PyObject *s = PyObject_Repr(obj); |
| 593 | if (s == NULL) return 1; |
| 594 | PyErr_Format(PyExc_ValueError, "invalid integer value: %.400s", |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 595 | PyString_AS_STRING(s)); |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 596 | Py_DECREF(s); |
| 597 | return 1; |
| 598 | } |
| 599 | |
| 600 | i = (int)PyLong_AsLong(obj); |
| 601 | if (i == -1 && PyErr_Occurred()) |
| 602 | return 1; |
| 603 | *out = i; |
| 604 | return 0; |
| 605 | } |
| 606 | |
| 607 | static int obj2ast_bool(PyObject* obj, bool* out, PyArena* arena) |
| 608 | { |
| 609 | if (!PyBool_Check(obj)) { |
| 610 | PyObject *s = PyObject_Repr(obj); |
| 611 | if (s == NULL) return 1; |
| 612 | PyErr_Format(PyExc_ValueError, "invalid boolean value: %.400s", |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 613 | PyString_AS_STRING(s)); |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 614 | Py_DECREF(s); |
| 615 | return 1; |
| 616 | } |
| 617 | |
| 618 | *out = (obj == Py_True); |
| 619 | return 0; |
| 620 | } |
| 621 | |
Benjamin Peterson | aff36f1 | 2008-10-19 13:59:01 +0000 | [diff] [blame] | 622 | static int add_ast_fields(void) |
Armin Ronacher | 35e01fb | 2008-10-19 08:27:43 +0000 | [diff] [blame] | 623 | { |
| 624 | PyObject *empty_tuple, *d; |
| 625 | if (PyType_Ready(&AST_type) < 0) |
| 626 | return -1; |
| 627 | d = AST_type.tp_dict; |
| 628 | empty_tuple = PyTuple_New(0); |
| 629 | if (!empty_tuple || |
| 630 | PyDict_SetItemString(d, "_fields", empty_tuple) < 0 || |
| 631 | PyDict_SetItemString(d, "_attributes", empty_tuple) < 0) { |
| 632 | Py_XDECREF(empty_tuple); |
| 633 | return -1; |
| 634 | } |
| 635 | Py_DECREF(empty_tuple); |
| 636 | return 0; |
| 637 | } |
| 638 | |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 639 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 640 | static int init_types(void) |
| 641 | { |
Neal Norwitz | 19379f1 | 2006-04-03 04:50:58 +0000 | [diff] [blame] | 642 | static int initialized; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 643 | if (initialized) return 1; |
Armin Ronacher | 35e01fb | 2008-10-19 08:27:43 +0000 | [diff] [blame] | 644 | if (add_ast_fields() < 0) return 0; |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 645 | mod_type = make_type("mod", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 646 | if (!mod_type) return 0; |
| 647 | if (!add_attributes(mod_type, NULL, 0)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 648 | Module_type = make_type("Module", mod_type, Module_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 649 | if (!Module_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 650 | Interactive_type = make_type("Interactive", mod_type, |
| 651 | Interactive_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 652 | if (!Interactive_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 653 | Expression_type = make_type("Expression", mod_type, Expression_fields, |
| 654 | 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 655 | if (!Expression_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 656 | Suite_type = make_type("Suite", mod_type, Suite_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 657 | if (!Suite_type) return 0; |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 658 | stmt_type = make_type("stmt", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 659 | if (!stmt_type) return 0; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 660 | if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 661 | FunctionDef_type = make_type("FunctionDef", stmt_type, |
| 662 | FunctionDef_fields, 4); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 663 | if (!FunctionDef_type) return 0; |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 664 | ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 4); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 665 | if (!ClassDef_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 666 | Return_type = make_type("Return", stmt_type, Return_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 667 | if (!Return_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 668 | Delete_type = make_type("Delete", stmt_type, Delete_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 669 | if (!Delete_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 670 | Assign_type = make_type("Assign", stmt_type, Assign_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 671 | if (!Assign_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 672 | AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 673 | if (!AugAssign_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 674 | Print_type = make_type("Print", stmt_type, Print_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 675 | if (!Print_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 676 | For_type = make_type("For", stmt_type, For_fields, 4); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 677 | if (!For_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 678 | While_type = make_type("While", stmt_type, While_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 679 | if (!While_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 680 | If_type = make_type("If", stmt_type, If_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 681 | if (!If_type) return 0; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 682 | With_type = make_type("With", stmt_type, With_fields, 3); |
| 683 | if (!With_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 684 | Raise_type = make_type("Raise", stmt_type, Raise_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 685 | if (!Raise_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 686 | TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 687 | if (!TryExcept_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 688 | TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields, |
| 689 | 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 690 | if (!TryFinally_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 691 | Assert_type = make_type("Assert", stmt_type, Assert_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 692 | if (!Assert_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 693 | Import_type = make_type("Import", stmt_type, Import_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 694 | if (!Import_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 695 | ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 696 | 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 697 | if (!ImportFrom_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 698 | Exec_type = make_type("Exec", stmt_type, Exec_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 699 | if (!Exec_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 700 | Global_type = make_type("Global", stmt_type, Global_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 701 | if (!Global_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 702 | Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 703 | if (!Expr_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 704 | Pass_type = make_type("Pass", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 705 | if (!Pass_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 706 | Break_type = make_type("Break", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 707 | if (!Break_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 708 | Continue_type = make_type("Continue", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 709 | if (!Continue_type) return 0; |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 710 | expr_type = make_type("expr", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 711 | if (!expr_type) return 0; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 712 | if (!add_attributes(expr_type, expr_attributes, 2)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 713 | BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 714 | if (!BoolOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 715 | BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 716 | if (!BinOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 717 | UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 718 | if (!UnaryOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 719 | Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 720 | if (!Lambda_type) return 0; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 721 | IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 722 | if (!IfExp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 723 | Dict_type = make_type("Dict", expr_type, Dict_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 724 | if (!Dict_type) return 0; |
Alexandre Vassalotti | ee936a2 | 2010-01-09 23:35:54 +0000 | [diff] [blame] | 725 | Set_type = make_type("Set", expr_type, Set_fields, 1); |
| 726 | if (!Set_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 727 | ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 728 | if (!ListComp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 729 | GeneratorExp_type = make_type("GeneratorExp", expr_type, |
| 730 | GeneratorExp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 731 | if (!GeneratorExp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 732 | Yield_type = make_type("Yield", expr_type, Yield_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 733 | if (!Yield_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 734 | Compare_type = make_type("Compare", expr_type, Compare_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 735 | if (!Compare_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 736 | Call_type = make_type("Call", expr_type, Call_fields, 5); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 737 | if (!Call_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 738 | Repr_type = make_type("Repr", expr_type, Repr_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 739 | if (!Repr_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 740 | Num_type = make_type("Num", expr_type, Num_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 741 | if (!Num_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 742 | Str_type = make_type("Str", expr_type, Str_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 743 | if (!Str_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 744 | Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 745 | if (!Attribute_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 746 | Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 747 | if (!Subscript_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 748 | Name_type = make_type("Name", expr_type, Name_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 749 | if (!Name_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 750 | List_type = make_type("List", expr_type, List_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 751 | if (!List_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 752 | Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 753 | if (!Tuple_type) return 0; |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 754 | expr_context_type = make_type("expr_context", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 755 | if (!expr_context_type) return 0; |
| 756 | if (!add_attributes(expr_context_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 757 | Load_type = make_type("Load", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 758 | if (!Load_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 759 | Load_singleton = PyType_GenericNew(Load_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 760 | if (!Load_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 761 | Store_type = make_type("Store", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 762 | if (!Store_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 763 | Store_singleton = PyType_GenericNew(Store_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 764 | if (!Store_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 765 | Del_type = make_type("Del", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 766 | if (!Del_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 767 | Del_singleton = PyType_GenericNew(Del_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 768 | if (!Del_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 769 | AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 770 | if (!AugLoad_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 771 | AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 772 | if (!AugLoad_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 773 | AugStore_type = make_type("AugStore", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 774 | if (!AugStore_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 775 | AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 776 | if (!AugStore_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 777 | Param_type = make_type("Param", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 778 | if (!Param_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 779 | Param_singleton = PyType_GenericNew(Param_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 780 | if (!Param_singleton) return 0; |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 781 | slice_type = make_type("slice", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 782 | if (!slice_type) return 0; |
| 783 | if (!add_attributes(slice_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 784 | Ellipsis_type = make_type("Ellipsis", slice_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 785 | if (!Ellipsis_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 786 | Slice_type = make_type("Slice", slice_type, Slice_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 787 | if (!Slice_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 788 | ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 789 | if (!ExtSlice_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 790 | Index_type = make_type("Index", slice_type, Index_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 791 | if (!Index_type) return 0; |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 792 | boolop_type = make_type("boolop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 793 | if (!boolop_type) return 0; |
| 794 | if (!add_attributes(boolop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 795 | And_type = make_type("And", boolop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 796 | if (!And_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 797 | And_singleton = PyType_GenericNew(And_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 798 | if (!And_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 799 | Or_type = make_type("Or", boolop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 800 | if (!Or_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 801 | Or_singleton = PyType_GenericNew(Or_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 802 | if (!Or_singleton) return 0; |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 803 | operator_type = make_type("operator", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 804 | if (!operator_type) return 0; |
| 805 | if (!add_attributes(operator_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 806 | Add_type = make_type("Add", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 807 | if (!Add_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 808 | Add_singleton = PyType_GenericNew(Add_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 809 | if (!Add_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 810 | Sub_type = make_type("Sub", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 811 | if (!Sub_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 812 | Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 813 | if (!Sub_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 814 | Mult_type = make_type("Mult", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 815 | if (!Mult_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 816 | Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 817 | if (!Mult_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 818 | Div_type = make_type("Div", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 819 | if (!Div_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 820 | Div_singleton = PyType_GenericNew(Div_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 821 | if (!Div_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 822 | Mod_type = make_type("Mod", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 823 | if (!Mod_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 824 | Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 825 | if (!Mod_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 826 | Pow_type = make_type("Pow", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 827 | if (!Pow_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 828 | Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 829 | if (!Pow_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 830 | LShift_type = make_type("LShift", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 831 | if (!LShift_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 832 | LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 833 | if (!LShift_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 834 | RShift_type = make_type("RShift", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 835 | if (!RShift_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 836 | RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 837 | if (!RShift_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 838 | BitOr_type = make_type("BitOr", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 839 | if (!BitOr_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 840 | BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 841 | if (!BitOr_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 842 | BitXor_type = make_type("BitXor", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 843 | if (!BitXor_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 844 | BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 845 | if (!BitXor_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 846 | BitAnd_type = make_type("BitAnd", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 847 | if (!BitAnd_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 848 | BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 849 | if (!BitAnd_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 850 | FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 851 | if (!FloorDiv_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 852 | FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 853 | if (!FloorDiv_singleton) return 0; |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 854 | unaryop_type = make_type("unaryop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 855 | if (!unaryop_type) return 0; |
| 856 | if (!add_attributes(unaryop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 857 | Invert_type = make_type("Invert", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 858 | if (!Invert_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 859 | Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 860 | if (!Invert_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 861 | Not_type = make_type("Not", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 862 | if (!Not_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 863 | Not_singleton = PyType_GenericNew(Not_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 864 | if (!Not_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 865 | UAdd_type = make_type("UAdd", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 866 | if (!UAdd_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 867 | UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 868 | if (!UAdd_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 869 | USub_type = make_type("USub", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 870 | if (!USub_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 871 | USub_singleton = PyType_GenericNew(USub_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 872 | if (!USub_singleton) return 0; |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 873 | cmpop_type = make_type("cmpop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 874 | if (!cmpop_type) return 0; |
| 875 | if (!add_attributes(cmpop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 876 | Eq_type = make_type("Eq", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 877 | if (!Eq_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 878 | Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 879 | if (!Eq_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 880 | NotEq_type = make_type("NotEq", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 881 | if (!NotEq_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 882 | NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 883 | if (!NotEq_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 884 | Lt_type = make_type("Lt", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 885 | if (!Lt_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 886 | Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 887 | if (!Lt_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 888 | LtE_type = make_type("LtE", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 889 | if (!LtE_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 890 | LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 891 | if (!LtE_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 892 | Gt_type = make_type("Gt", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 893 | if (!Gt_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 894 | Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 895 | if (!Gt_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 896 | GtE_type = make_type("GtE", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 897 | if (!GtE_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 898 | GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 899 | if (!GtE_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 900 | Is_type = make_type("Is", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 901 | if (!Is_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 902 | Is_singleton = PyType_GenericNew(Is_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 903 | if (!Is_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 904 | IsNot_type = make_type("IsNot", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 905 | if (!IsNot_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 906 | IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 907 | if (!IsNot_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 908 | In_type = make_type("In", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 909 | if (!In_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 910 | In_singleton = PyType_GenericNew(In_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 911 | if (!In_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 912 | NotIn_type = make_type("NotIn", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 913 | if (!NotIn_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 914 | NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 915 | if (!NotIn_singleton) return 0; |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 916 | comprehension_type = make_type("comprehension", &AST_type, |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 917 | comprehension_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 918 | if (!comprehension_type) return 0; |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 919 | excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 920 | if (!excepthandler_type) return 0; |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame] | 921 | if (!add_attributes(excepthandler_type, excepthandler_attributes, 2)) |
| 922 | return 0; |
| 923 | ExceptHandler_type = make_type("ExceptHandler", excepthandler_type, |
| 924 | ExceptHandler_fields, 3); |
| 925 | if (!ExceptHandler_type) return 0; |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 926 | arguments_type = make_type("arguments", &AST_type, arguments_fields, 4); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 927 | if (!arguments_type) return 0; |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 928 | keyword_type = make_type("keyword", &AST_type, keyword_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 929 | if (!keyword_type) return 0; |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 930 | alias_type = make_type("alias", &AST_type, alias_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 931 | if (!alias_type) return 0; |
| 932 | initialized = 1; |
| 933 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 934 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 935 | |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 936 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 937 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 938 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 939 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 940 | arena); |
| 941 | static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena); |
| 942 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 943 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 944 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 945 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 946 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 947 | arena); |
| 948 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 949 | arena); |
| 950 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 951 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 952 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
| 953 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 954 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 955 | Module(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 956 | { |
| 957 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 958 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 959 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 960 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 961 | p->kind = Module_kind; |
| 962 | p->v.Module.body = body; |
| 963 | return p; |
| 964 | } |
| 965 | |
| 966 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 967 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 968 | { |
| 969 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 970 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 971 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 972 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 973 | p->kind = Interactive_kind; |
| 974 | p->v.Interactive.body = body; |
| 975 | return p; |
| 976 | } |
| 977 | |
| 978 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 979 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 980 | { |
| 981 | mod_ty p; |
| 982 | if (!body) { |
| 983 | PyErr_SetString(PyExc_ValueError, |
| 984 | "field body is required for Expression"); |
| 985 | return NULL; |
| 986 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 987 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 988 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 989 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 990 | p->kind = Expression_kind; |
| 991 | p->v.Expression.body = body; |
| 992 | return p; |
| 993 | } |
| 994 | |
| 995 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 996 | Suite(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 997 | { |
| 998 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 999 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1000 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1001 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1002 | p->kind = Suite_kind; |
| 1003 | p->v.Suite.body = body; |
| 1004 | return p; |
| 1005 | } |
| 1006 | |
| 1007 | stmt_ty |
| 1008 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 1009 | decorator_list, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1010 | { |
| 1011 | stmt_ty p; |
| 1012 | if (!name) { |
| 1013 | PyErr_SetString(PyExc_ValueError, |
| 1014 | "field name is required for FunctionDef"); |
| 1015 | return NULL; |
| 1016 | } |
| 1017 | if (!args) { |
| 1018 | PyErr_SetString(PyExc_ValueError, |
| 1019 | "field args is required for FunctionDef"); |
| 1020 | return NULL; |
| 1021 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1022 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1023 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1024 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1025 | p->kind = FunctionDef_kind; |
| 1026 | p->v.FunctionDef.name = name; |
| 1027 | p->v.FunctionDef.args = args; |
| 1028 | p->v.FunctionDef.body = body; |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 1029 | p->v.FunctionDef.decorator_list = decorator_list; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1030 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1031 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1032 | return p; |
| 1033 | } |
| 1034 | |
| 1035 | stmt_ty |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 1036 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, asdl_seq * |
| 1037 | decorator_list, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1038 | { |
| 1039 | stmt_ty p; |
| 1040 | if (!name) { |
| 1041 | PyErr_SetString(PyExc_ValueError, |
| 1042 | "field name is required for ClassDef"); |
| 1043 | return NULL; |
| 1044 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1045 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1046 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1047 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1048 | p->kind = ClassDef_kind; |
| 1049 | p->v.ClassDef.name = name; |
| 1050 | p->v.ClassDef.bases = bases; |
| 1051 | p->v.ClassDef.body = body; |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 1052 | p->v.ClassDef.decorator_list = decorator_list; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1053 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1054 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1055 | return p; |
| 1056 | } |
| 1057 | |
| 1058 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1059 | Return(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1060 | { |
| 1061 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1062 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1063 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1064 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1065 | p->kind = Return_kind; |
| 1066 | p->v.Return.value = value; |
| 1067 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1068 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1069 | return p; |
| 1070 | } |
| 1071 | |
| 1072 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1073 | Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1074 | { |
| 1075 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1076 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1077 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1078 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1079 | p->kind = Delete_kind; |
| 1080 | p->v.Delete.targets = targets; |
| 1081 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1082 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1083 | return p; |
| 1084 | } |
| 1085 | |
| 1086 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1087 | Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena |
| 1088 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1089 | { |
| 1090 | stmt_ty p; |
| 1091 | if (!value) { |
| 1092 | PyErr_SetString(PyExc_ValueError, |
| 1093 | "field value is required for Assign"); |
| 1094 | return NULL; |
| 1095 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1096 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1097 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1098 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1099 | p->kind = Assign_kind; |
| 1100 | p->v.Assign.targets = targets; |
| 1101 | p->v.Assign.value = value; |
| 1102 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1103 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1104 | return p; |
| 1105 | } |
| 1106 | |
| 1107 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1108 | AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int |
| 1109 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1110 | { |
| 1111 | stmt_ty p; |
| 1112 | if (!target) { |
| 1113 | PyErr_SetString(PyExc_ValueError, |
| 1114 | "field target is required for AugAssign"); |
| 1115 | return NULL; |
| 1116 | } |
| 1117 | if (!op) { |
| 1118 | PyErr_SetString(PyExc_ValueError, |
| 1119 | "field op is required for AugAssign"); |
| 1120 | return NULL; |
| 1121 | } |
| 1122 | if (!value) { |
| 1123 | PyErr_SetString(PyExc_ValueError, |
| 1124 | "field value is required for AugAssign"); |
| 1125 | return NULL; |
| 1126 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1127 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1128 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1129 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1130 | p->kind = AugAssign_kind; |
| 1131 | p->v.AugAssign.target = target; |
| 1132 | p->v.AugAssign.op = op; |
| 1133 | p->v.AugAssign.value = value; |
| 1134 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1135 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1136 | return p; |
| 1137 | } |
| 1138 | |
| 1139 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1140 | Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int col_offset, |
| 1141 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1142 | { |
| 1143 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1144 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1145 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1146 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1147 | p->kind = Print_kind; |
| 1148 | p->v.Print.dest = dest; |
| 1149 | p->v.Print.values = values; |
| 1150 | p->v.Print.nl = nl; |
| 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 |
| 1157 | 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] | 1158 | lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1159 | { |
| 1160 | stmt_ty p; |
| 1161 | if (!target) { |
| 1162 | PyErr_SetString(PyExc_ValueError, |
| 1163 | "field target is required for For"); |
| 1164 | return NULL; |
| 1165 | } |
| 1166 | if (!iter) { |
| 1167 | PyErr_SetString(PyExc_ValueError, |
| 1168 | "field iter is required for For"); |
| 1169 | return NULL; |
| 1170 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1171 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1172 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1173 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1174 | p->kind = For_kind; |
| 1175 | p->v.For.target = target; |
| 1176 | p->v.For.iter = iter; |
| 1177 | p->v.For.body = body; |
| 1178 | p->v.For.orelse = orelse; |
| 1179 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1180 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1181 | return p; |
| 1182 | } |
| 1183 | |
| 1184 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1185 | While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1186 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1187 | { |
| 1188 | stmt_ty p; |
| 1189 | if (!test) { |
| 1190 | PyErr_SetString(PyExc_ValueError, |
| 1191 | "field test is required for While"); |
| 1192 | return NULL; |
| 1193 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1194 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1195 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1196 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1197 | p->kind = While_kind; |
| 1198 | p->v.While.test = test; |
| 1199 | p->v.While.body = body; |
| 1200 | p->v.While.orelse = orelse; |
| 1201 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1202 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1203 | return p; |
| 1204 | } |
| 1205 | |
| 1206 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1207 | If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1208 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1209 | { |
| 1210 | stmt_ty p; |
| 1211 | if (!test) { |
| 1212 | PyErr_SetString(PyExc_ValueError, |
| 1213 | "field test is required for If"); |
| 1214 | return NULL; |
| 1215 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1216 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1217 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1218 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1219 | p->kind = If_kind; |
| 1220 | p->v.If.test = test; |
| 1221 | p->v.If.body = body; |
| 1222 | p->v.If.orelse = orelse; |
| 1223 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1224 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1225 | return p; |
| 1226 | } |
| 1227 | |
| 1228 | stmt_ty |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1229 | 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] | 1230 | int col_offset, PyArena *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1231 | { |
| 1232 | stmt_ty p; |
| 1233 | if (!context_expr) { |
| 1234 | PyErr_SetString(PyExc_ValueError, |
| 1235 | "field context_expr is required for With"); |
| 1236 | return NULL; |
| 1237 | } |
| 1238 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1239 | if (!p) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1240 | return NULL; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1241 | p->kind = With_kind; |
| 1242 | p->v.With.context_expr = context_expr; |
| 1243 | p->v.With.optional_vars = optional_vars; |
| 1244 | p->v.With.body = body; |
| 1245 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1246 | p->col_offset = col_offset; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1247 | return p; |
| 1248 | } |
| 1249 | |
| 1250 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1251 | Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset, |
| 1252 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1253 | { |
| 1254 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1255 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1256 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1257 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1258 | p->kind = Raise_kind; |
| 1259 | p->v.Raise.type = type; |
| 1260 | p->v.Raise.inst = inst; |
| 1261 | p->v.Raise.tback = tback; |
| 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 |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1268 | 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] | 1269 | int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1270 | { |
| 1271 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1272 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1273 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1274 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1275 | p->kind = TryExcept_kind; |
| 1276 | p->v.TryExcept.body = body; |
| 1277 | p->v.TryExcept.handlers = handlers; |
| 1278 | p->v.TryExcept.orelse = orelse; |
| 1279 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1280 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1281 | return p; |
| 1282 | } |
| 1283 | |
| 1284 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1285 | TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset, |
| 1286 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1287 | { |
| 1288 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1289 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1290 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1291 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1292 | p->kind = TryFinally_kind; |
| 1293 | p->v.TryFinally.body = body; |
| 1294 | p->v.TryFinally.finalbody = finalbody; |
| 1295 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1296 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1297 | return p; |
| 1298 | } |
| 1299 | |
| 1300 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1301 | 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] | 1302 | { |
| 1303 | stmt_ty p; |
| 1304 | if (!test) { |
| 1305 | PyErr_SetString(PyExc_ValueError, |
| 1306 | "field test is required for Assert"); |
| 1307 | return NULL; |
| 1308 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1309 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1310 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1311 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1312 | p->kind = Assert_kind; |
| 1313 | p->v.Assert.test = test; |
| 1314 | p->v.Assert.msg = msg; |
| 1315 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1316 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1317 | return p; |
| 1318 | } |
| 1319 | |
| 1320 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1321 | Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1322 | { |
| 1323 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1324 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1325 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1326 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1327 | p->kind = Import_kind; |
| 1328 | p->v.Import.names = names; |
| 1329 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1330 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1331 | return p; |
| 1332 | } |
| 1333 | |
| 1334 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1335 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
| 1336 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1337 | { |
| 1338 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1339 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1340 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1341 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1342 | p->kind = ImportFrom_kind; |
| 1343 | p->v.ImportFrom.module = module; |
| 1344 | p->v.ImportFrom.names = names; |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 1345 | p->v.ImportFrom.level = level; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1346 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1347 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1348 | return p; |
| 1349 | } |
| 1350 | |
| 1351 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1352 | Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, int col_offset, |
| 1353 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1354 | { |
| 1355 | stmt_ty p; |
| 1356 | if (!body) { |
| 1357 | PyErr_SetString(PyExc_ValueError, |
| 1358 | "field body is required for Exec"); |
| 1359 | return NULL; |
| 1360 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1361 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1362 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1363 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1364 | p->kind = Exec_kind; |
| 1365 | p->v.Exec.body = body; |
| 1366 | p->v.Exec.globals = globals; |
| 1367 | p->v.Exec.locals = locals; |
| 1368 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1369 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1370 | return p; |
| 1371 | } |
| 1372 | |
| 1373 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1374 | Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1375 | { |
| 1376 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1377 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1378 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1379 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1380 | p->kind = Global_kind; |
| 1381 | p->v.Global.names = names; |
| 1382 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1383 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1384 | return p; |
| 1385 | } |
| 1386 | |
| 1387 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1388 | Expr(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1389 | { |
| 1390 | stmt_ty p; |
| 1391 | if (!value) { |
| 1392 | PyErr_SetString(PyExc_ValueError, |
| 1393 | "field value is required for Expr"); |
| 1394 | return NULL; |
| 1395 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1396 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1397 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1398 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1399 | p->kind = Expr_kind; |
| 1400 | p->v.Expr.value = value; |
| 1401 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1402 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1403 | return p; |
| 1404 | } |
| 1405 | |
| 1406 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1407 | Pass(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1408 | { |
| 1409 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1410 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1411 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1412 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1413 | p->kind = Pass_kind; |
| 1414 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1415 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1416 | return p; |
| 1417 | } |
| 1418 | |
| 1419 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1420 | Break(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1421 | { |
| 1422 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1423 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1424 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1425 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1426 | p->kind = Break_kind; |
| 1427 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1428 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1429 | return p; |
| 1430 | } |
| 1431 | |
| 1432 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1433 | Continue(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1434 | { |
| 1435 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1436 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1437 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1438 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1439 | p->kind = Continue_kind; |
| 1440 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1441 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1442 | return p; |
| 1443 | } |
| 1444 | |
| 1445 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1446 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1447 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1448 | { |
| 1449 | expr_ty p; |
| 1450 | if (!op) { |
| 1451 | PyErr_SetString(PyExc_ValueError, |
| 1452 | "field op is required for BoolOp"); |
| 1453 | return NULL; |
| 1454 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1455 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1456 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1457 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1458 | p->kind = BoolOp_kind; |
| 1459 | p->v.BoolOp.op = op; |
| 1460 | p->v.BoolOp.values = values; |
| 1461 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1462 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1463 | return p; |
| 1464 | } |
| 1465 | |
| 1466 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1467 | BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset, |
| 1468 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1469 | { |
| 1470 | expr_ty p; |
| 1471 | if (!left) { |
| 1472 | PyErr_SetString(PyExc_ValueError, |
| 1473 | "field left is required for BinOp"); |
| 1474 | return NULL; |
| 1475 | } |
| 1476 | if (!op) { |
| 1477 | PyErr_SetString(PyExc_ValueError, |
| 1478 | "field op is required for BinOp"); |
| 1479 | return NULL; |
| 1480 | } |
| 1481 | if (!right) { |
| 1482 | PyErr_SetString(PyExc_ValueError, |
| 1483 | "field right is required for BinOp"); |
| 1484 | return NULL; |
| 1485 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1486 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1487 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1488 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1489 | p->kind = BinOp_kind; |
| 1490 | p->v.BinOp.left = left; |
| 1491 | p->v.BinOp.op = op; |
| 1492 | p->v.BinOp.right = right; |
| 1493 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1494 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1495 | return p; |
| 1496 | } |
| 1497 | |
| 1498 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1499 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena |
| 1500 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1501 | { |
| 1502 | expr_ty p; |
| 1503 | if (!op) { |
| 1504 | PyErr_SetString(PyExc_ValueError, |
| 1505 | "field op is required for UnaryOp"); |
| 1506 | return NULL; |
| 1507 | } |
| 1508 | if (!operand) { |
| 1509 | PyErr_SetString(PyExc_ValueError, |
| 1510 | "field operand is required for UnaryOp"); |
| 1511 | return NULL; |
| 1512 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1513 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1514 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1515 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1516 | p->kind = UnaryOp_kind; |
| 1517 | p->v.UnaryOp.op = op; |
| 1518 | p->v.UnaryOp.operand = operand; |
| 1519 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1520 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1521 | return p; |
| 1522 | } |
| 1523 | |
| 1524 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1525 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena |
| 1526 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1527 | { |
| 1528 | expr_ty p; |
| 1529 | if (!args) { |
| 1530 | PyErr_SetString(PyExc_ValueError, |
| 1531 | "field args is required for Lambda"); |
| 1532 | return NULL; |
| 1533 | } |
| 1534 | if (!body) { |
| 1535 | PyErr_SetString(PyExc_ValueError, |
| 1536 | "field body is required for Lambda"); |
| 1537 | return NULL; |
| 1538 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1539 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1540 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1541 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1542 | p->kind = Lambda_kind; |
| 1543 | p->v.Lambda.args = args; |
| 1544 | p->v.Lambda.body = body; |
| 1545 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1546 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1547 | return p; |
| 1548 | } |
| 1549 | |
| 1550 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1551 | IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset, |
| 1552 | PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1553 | { |
| 1554 | expr_ty p; |
| 1555 | if (!test) { |
| 1556 | PyErr_SetString(PyExc_ValueError, |
| 1557 | "field test is required for IfExp"); |
| 1558 | return NULL; |
| 1559 | } |
| 1560 | if (!body) { |
| 1561 | PyErr_SetString(PyExc_ValueError, |
| 1562 | "field body is required for IfExp"); |
| 1563 | return NULL; |
| 1564 | } |
| 1565 | if (!orelse) { |
| 1566 | PyErr_SetString(PyExc_ValueError, |
| 1567 | "field orelse is required for IfExp"); |
| 1568 | return NULL; |
| 1569 | } |
| 1570 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1571 | if (!p) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1572 | return NULL; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1573 | p->kind = IfExp_kind; |
| 1574 | p->v.IfExp.test = test; |
| 1575 | p->v.IfExp.body = body; |
| 1576 | p->v.IfExp.orelse = orelse; |
| 1577 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1578 | p->col_offset = col_offset; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1579 | return p; |
| 1580 | } |
| 1581 | |
| 1582 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1583 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1584 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1585 | { |
| 1586 | expr_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1587 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1588 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1589 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1590 | p->kind = Dict_kind; |
| 1591 | p->v.Dict.keys = keys; |
| 1592 | p->v.Dict.values = values; |
| 1593 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1594 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1595 | return p; |
| 1596 | } |
| 1597 | |
| 1598 | expr_ty |
Alexandre Vassalotti | ee936a2 | 2010-01-09 23:35:54 +0000 | [diff] [blame] | 1599 | Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena) |
| 1600 | { |
| 1601 | expr_ty p; |
| 1602 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1603 | if (!p) |
| 1604 | return NULL; |
| 1605 | p->kind = Set_kind; |
| 1606 | p->v.Set.elts = elts; |
| 1607 | p->lineno = lineno; |
| 1608 | p->col_offset = col_offset; |
| 1609 | return p; |
| 1610 | } |
| 1611 | |
| 1612 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1613 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1614 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1615 | { |
| 1616 | expr_ty p; |
| 1617 | if (!elt) { |
| 1618 | PyErr_SetString(PyExc_ValueError, |
| 1619 | "field elt is required for ListComp"); |
| 1620 | return NULL; |
| 1621 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1622 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1623 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1624 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1625 | p->kind = ListComp_kind; |
| 1626 | p->v.ListComp.elt = elt; |
| 1627 | p->v.ListComp.generators = generators; |
| 1628 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1629 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1630 | return p; |
| 1631 | } |
| 1632 | |
| 1633 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1634 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1635 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1636 | { |
| 1637 | expr_ty p; |
| 1638 | if (!elt) { |
| 1639 | PyErr_SetString(PyExc_ValueError, |
| 1640 | "field elt is required for GeneratorExp"); |
| 1641 | return NULL; |
| 1642 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1643 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1644 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1645 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1646 | p->kind = GeneratorExp_kind; |
| 1647 | p->v.GeneratorExp.elt = elt; |
| 1648 | p->v.GeneratorExp.generators = generators; |
| 1649 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1650 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1651 | return p; |
| 1652 | } |
| 1653 | |
| 1654 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1655 | Yield(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1656 | { |
| 1657 | expr_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1658 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1659 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1660 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1661 | p->kind = Yield_kind; |
| 1662 | p->v.Yield.value = value; |
| 1663 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1664 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1665 | return p; |
| 1666 | } |
| 1667 | |
| 1668 | expr_ty |
Martin v. Löwis | 0cc56e5 | 2006-04-13 12:29:43 +0000 | [diff] [blame] | 1669 | Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno, |
| 1670 | int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1671 | { |
| 1672 | expr_ty p; |
| 1673 | if (!left) { |
| 1674 | PyErr_SetString(PyExc_ValueError, |
| 1675 | "field left is required for Compare"); |
| 1676 | return NULL; |
| 1677 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1678 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1679 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1680 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1681 | p->kind = Compare_kind; |
| 1682 | p->v.Compare.left = left; |
| 1683 | p->v.Compare.ops = ops; |
| 1684 | p->v.Compare.comparators = comparators; |
| 1685 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1686 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1687 | return p; |
| 1688 | } |
| 1689 | |
| 1690 | expr_ty |
| 1691 | 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] | 1692 | expr_ty kwargs, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1693 | { |
| 1694 | expr_ty p; |
| 1695 | if (!func) { |
| 1696 | PyErr_SetString(PyExc_ValueError, |
| 1697 | "field func is required for Call"); |
| 1698 | return NULL; |
| 1699 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1700 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1701 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1702 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1703 | p->kind = Call_kind; |
| 1704 | p->v.Call.func = func; |
| 1705 | p->v.Call.args = args; |
| 1706 | p->v.Call.keywords = keywords; |
| 1707 | p->v.Call.starargs = starargs; |
| 1708 | p->v.Call.kwargs = kwargs; |
| 1709 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1710 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1711 | return p; |
| 1712 | } |
| 1713 | |
| 1714 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1715 | Repr(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1716 | { |
| 1717 | expr_ty p; |
| 1718 | if (!value) { |
| 1719 | PyErr_SetString(PyExc_ValueError, |
| 1720 | "field value is required for Repr"); |
| 1721 | return NULL; |
| 1722 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1723 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1724 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1725 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1726 | p->kind = Repr_kind; |
| 1727 | p->v.Repr.value = value; |
| 1728 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1729 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1730 | return p; |
| 1731 | } |
| 1732 | |
| 1733 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1734 | Num(object n, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1735 | { |
| 1736 | expr_ty p; |
| 1737 | if (!n) { |
| 1738 | PyErr_SetString(PyExc_ValueError, |
| 1739 | "field n is required for Num"); |
| 1740 | return NULL; |
| 1741 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1742 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1743 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1744 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1745 | p->kind = Num_kind; |
| 1746 | p->v.Num.n = n; |
| 1747 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1748 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1749 | return p; |
| 1750 | } |
| 1751 | |
| 1752 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1753 | Str(string s, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1754 | { |
| 1755 | expr_ty p; |
| 1756 | if (!s) { |
| 1757 | PyErr_SetString(PyExc_ValueError, |
| 1758 | "field s is required for Str"); |
| 1759 | return NULL; |
| 1760 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1761 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1762 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1763 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1764 | p->kind = Str_kind; |
| 1765 | p->v.Str.s = s; |
| 1766 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1767 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1768 | return p; |
| 1769 | } |
| 1770 | |
| 1771 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1772 | Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int |
| 1773 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1774 | { |
| 1775 | expr_ty p; |
| 1776 | if (!value) { |
| 1777 | PyErr_SetString(PyExc_ValueError, |
| 1778 | "field value is required for Attribute"); |
| 1779 | return NULL; |
| 1780 | } |
| 1781 | if (!attr) { |
| 1782 | PyErr_SetString(PyExc_ValueError, |
| 1783 | "field attr is required for Attribute"); |
| 1784 | return NULL; |
| 1785 | } |
| 1786 | if (!ctx) { |
| 1787 | PyErr_SetString(PyExc_ValueError, |
| 1788 | "field ctx is required for Attribute"); |
| 1789 | return NULL; |
| 1790 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1791 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1792 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1793 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1794 | p->kind = Attribute_kind; |
| 1795 | p->v.Attribute.value = value; |
| 1796 | p->v.Attribute.attr = attr; |
| 1797 | p->v.Attribute.ctx = ctx; |
| 1798 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1799 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1800 | return p; |
| 1801 | } |
| 1802 | |
| 1803 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1804 | Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int |
| 1805 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1806 | { |
| 1807 | expr_ty p; |
| 1808 | if (!value) { |
| 1809 | PyErr_SetString(PyExc_ValueError, |
| 1810 | "field value is required for Subscript"); |
| 1811 | return NULL; |
| 1812 | } |
| 1813 | if (!slice) { |
| 1814 | PyErr_SetString(PyExc_ValueError, |
| 1815 | "field slice is required for Subscript"); |
| 1816 | return NULL; |
| 1817 | } |
| 1818 | if (!ctx) { |
| 1819 | PyErr_SetString(PyExc_ValueError, |
| 1820 | "field ctx is required for Subscript"); |
| 1821 | return NULL; |
| 1822 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1823 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1824 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1825 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1826 | p->kind = Subscript_kind; |
| 1827 | p->v.Subscript.value = value; |
| 1828 | p->v.Subscript.slice = slice; |
| 1829 | p->v.Subscript.ctx = ctx; |
| 1830 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1831 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1832 | return p; |
| 1833 | } |
| 1834 | |
| 1835 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1836 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1837 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1838 | { |
| 1839 | expr_ty p; |
| 1840 | if (!id) { |
| 1841 | PyErr_SetString(PyExc_ValueError, |
| 1842 | "field id is required for Name"); |
| 1843 | return NULL; |
| 1844 | } |
| 1845 | if (!ctx) { |
| 1846 | PyErr_SetString(PyExc_ValueError, |
| 1847 | "field ctx is required for Name"); |
| 1848 | return NULL; |
| 1849 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1850 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1851 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1852 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1853 | p->kind = Name_kind; |
| 1854 | p->v.Name.id = id; |
| 1855 | p->v.Name.ctx = ctx; |
| 1856 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1857 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1858 | return p; |
| 1859 | } |
| 1860 | |
| 1861 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1862 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1863 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1864 | { |
| 1865 | expr_ty p; |
| 1866 | if (!ctx) { |
| 1867 | PyErr_SetString(PyExc_ValueError, |
| 1868 | "field ctx is required for List"); |
| 1869 | return NULL; |
| 1870 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1871 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1872 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1873 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1874 | p->kind = List_kind; |
| 1875 | p->v.List.elts = elts; |
| 1876 | p->v.List.ctx = ctx; |
| 1877 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1878 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1879 | return p; |
| 1880 | } |
| 1881 | |
| 1882 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1883 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1884 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1885 | { |
| 1886 | expr_ty p; |
| 1887 | if (!ctx) { |
| 1888 | PyErr_SetString(PyExc_ValueError, |
| 1889 | "field ctx is required for Tuple"); |
| 1890 | return NULL; |
| 1891 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1892 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1893 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1894 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1895 | p->kind = Tuple_kind; |
| 1896 | p->v.Tuple.elts = elts; |
| 1897 | p->v.Tuple.ctx = ctx; |
| 1898 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1899 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1900 | return p; |
| 1901 | } |
| 1902 | |
| 1903 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1904 | Ellipsis(PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1905 | { |
| 1906 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1907 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1908 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1909 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1910 | p->kind = Ellipsis_kind; |
| 1911 | return p; |
| 1912 | } |
| 1913 | |
| 1914 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1915 | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1916 | { |
| 1917 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1918 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1919 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1920 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1921 | p->kind = Slice_kind; |
| 1922 | p->v.Slice.lower = lower; |
| 1923 | p->v.Slice.upper = upper; |
| 1924 | p->v.Slice.step = step; |
| 1925 | return p; |
| 1926 | } |
| 1927 | |
| 1928 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1929 | ExtSlice(asdl_seq * dims, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1930 | { |
| 1931 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1932 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1933 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1934 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1935 | p->kind = ExtSlice_kind; |
| 1936 | p->v.ExtSlice.dims = dims; |
| 1937 | return p; |
| 1938 | } |
| 1939 | |
| 1940 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1941 | Index(expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1942 | { |
| 1943 | slice_ty p; |
| 1944 | if (!value) { |
| 1945 | PyErr_SetString(PyExc_ValueError, |
| 1946 | "field value is required for Index"); |
| 1947 | return NULL; |
| 1948 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1949 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1950 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1951 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1952 | p->kind = Index_kind; |
| 1953 | p->v.Index.value = value; |
| 1954 | return p; |
| 1955 | } |
| 1956 | |
| 1957 | comprehension_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1958 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1959 | { |
| 1960 | comprehension_ty p; |
| 1961 | if (!target) { |
| 1962 | PyErr_SetString(PyExc_ValueError, |
| 1963 | "field target is required for comprehension"); |
| 1964 | return NULL; |
| 1965 | } |
| 1966 | if (!iter) { |
| 1967 | PyErr_SetString(PyExc_ValueError, |
| 1968 | "field iter is required for comprehension"); |
| 1969 | return NULL; |
| 1970 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1971 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1972 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1973 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1974 | p->target = target; |
| 1975 | p->iter = iter; |
| 1976 | p->ifs = ifs; |
| 1977 | return p; |
| 1978 | } |
| 1979 | |
| 1980 | excepthandler_ty |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame] | 1981 | ExceptHandler(expr_ty type, expr_ty name, asdl_seq * body, int lineno, int |
Jeremy Hylton | 2f327c1 | 2006-04-04 04:00:23 +0000 | [diff] [blame] | 1982 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1983 | { |
| 1984 | excepthandler_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1985 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1986 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1987 | return NULL; |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame] | 1988 | p->kind = ExceptHandler_kind; |
| 1989 | p->v.ExceptHandler.type = type; |
| 1990 | p->v.ExceptHandler.name = name; |
| 1991 | p->v.ExceptHandler.body = body; |
Jeremy Hylton | 2f327c1 | 2006-04-04 04:00:23 +0000 | [diff] [blame] | 1992 | p->lineno = lineno; |
| 1993 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1994 | return p; |
| 1995 | } |
| 1996 | |
| 1997 | arguments_ty |
| 1998 | arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq * |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1999 | defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2000 | { |
| 2001 | arguments_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2002 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 2003 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2004 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2005 | p->args = args; |
| 2006 | p->vararg = vararg; |
| 2007 | p->kwarg = kwarg; |
| 2008 | p->defaults = defaults; |
| 2009 | return p; |
| 2010 | } |
| 2011 | |
| 2012 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2013 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2014 | { |
| 2015 | keyword_ty p; |
| 2016 | if (!arg) { |
| 2017 | PyErr_SetString(PyExc_ValueError, |
| 2018 | "field arg is required for keyword"); |
| 2019 | return NULL; |
| 2020 | } |
| 2021 | if (!value) { |
| 2022 | PyErr_SetString(PyExc_ValueError, |
| 2023 | "field value is required for keyword"); |
| 2024 | return NULL; |
| 2025 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2026 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 2027 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2028 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2029 | p->arg = arg; |
| 2030 | p->value = value; |
| 2031 | return p; |
| 2032 | } |
| 2033 | |
| 2034 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2035 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2036 | { |
| 2037 | alias_ty p; |
| 2038 | if (!name) { |
| 2039 | PyErr_SetString(PyExc_ValueError, |
| 2040 | "field name is required for alias"); |
| 2041 | return NULL; |
| 2042 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2043 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 2044 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2045 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2046 | p->name = name; |
| 2047 | p->asname = asname; |
| 2048 | return p; |
| 2049 | } |
| 2050 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2051 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2052 | PyObject* |
| 2053 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2054 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2055 | mod_ty o = (mod_ty)_o; |
| 2056 | PyObject *result = NULL, *value = NULL; |
| 2057 | if (!o) { |
| 2058 | Py_INCREF(Py_None); |
| 2059 | return Py_None; |
| 2060 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2061 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2062 | switch (o->kind) { |
| 2063 | case Module_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2064 | result = PyType_GenericNew(Module_type, NULL, NULL); |
| 2065 | if (!result) goto failed; |
| 2066 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 2067 | if (!value) goto failed; |
| 2068 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2069 | goto failed; |
| 2070 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2071 | break; |
| 2072 | case Interactive_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2073 | result = PyType_GenericNew(Interactive_type, NULL, NULL); |
| 2074 | if (!result) goto failed; |
| 2075 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 2076 | if (!value) goto failed; |
| 2077 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2078 | goto failed; |
| 2079 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2080 | break; |
| 2081 | case Expression_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2082 | result = PyType_GenericNew(Expression_type, NULL, NULL); |
| 2083 | if (!result) goto failed; |
| 2084 | value = ast2obj_expr(o->v.Expression.body); |
| 2085 | if (!value) goto failed; |
| 2086 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2087 | goto failed; |
| 2088 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2089 | break; |
| 2090 | case Suite_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2091 | result = PyType_GenericNew(Suite_type, NULL, NULL); |
| 2092 | if (!result) goto failed; |
| 2093 | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
| 2094 | if (!value) goto failed; |
| 2095 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2096 | goto failed; |
| 2097 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2098 | break; |
| 2099 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2100 | return result; |
| 2101 | failed: |
| 2102 | Py_XDECREF(value); |
| 2103 | Py_XDECREF(result); |
| 2104 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2105 | } |
| 2106 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2107 | PyObject* |
| 2108 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2109 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2110 | stmt_ty o = (stmt_ty)_o; |
| 2111 | PyObject *result = NULL, *value = NULL; |
| 2112 | if (!o) { |
| 2113 | Py_INCREF(Py_None); |
| 2114 | return Py_None; |
| 2115 | } |
| 2116 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2117 | switch (o->kind) { |
| 2118 | case FunctionDef_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2119 | result = PyType_GenericNew(FunctionDef_type, NULL, NULL); |
| 2120 | if (!result) goto failed; |
| 2121 | value = ast2obj_identifier(o->v.FunctionDef.name); |
| 2122 | if (!value) goto failed; |
| 2123 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 2124 | goto failed; |
| 2125 | Py_DECREF(value); |
| 2126 | value = ast2obj_arguments(o->v.FunctionDef.args); |
| 2127 | if (!value) goto failed; |
| 2128 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 2129 | goto failed; |
| 2130 | Py_DECREF(value); |
| 2131 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 2132 | if (!value) goto failed; |
| 2133 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2134 | goto failed; |
| 2135 | Py_DECREF(value); |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 2136 | value = ast2obj_list(o->v.FunctionDef.decorator_list, |
| 2137 | ast2obj_expr); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2138 | if (!value) goto failed; |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 2139 | if (PyObject_SetAttrString(result, "decorator_list", value) == |
| 2140 | -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2141 | goto failed; |
| 2142 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2143 | break; |
| 2144 | case ClassDef_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2145 | result = PyType_GenericNew(ClassDef_type, NULL, NULL); |
| 2146 | if (!result) goto failed; |
| 2147 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 2148 | if (!value) goto failed; |
| 2149 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 2150 | goto failed; |
| 2151 | Py_DECREF(value); |
| 2152 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 2153 | if (!value) goto failed; |
| 2154 | if (PyObject_SetAttrString(result, "bases", value) == -1) |
| 2155 | goto failed; |
| 2156 | Py_DECREF(value); |
| 2157 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 2158 | if (!value) goto failed; |
| 2159 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2160 | goto failed; |
| 2161 | Py_DECREF(value); |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 2162 | value = ast2obj_list(o->v.ClassDef.decorator_list, |
| 2163 | ast2obj_expr); |
| 2164 | if (!value) goto failed; |
| 2165 | if (PyObject_SetAttrString(result, "decorator_list", value) == |
| 2166 | -1) |
| 2167 | goto failed; |
| 2168 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2169 | break; |
| 2170 | case Return_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2171 | result = PyType_GenericNew(Return_type, NULL, NULL); |
| 2172 | if (!result) goto failed; |
| 2173 | value = ast2obj_expr(o->v.Return.value); |
| 2174 | if (!value) goto failed; |
| 2175 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2176 | goto failed; |
| 2177 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2178 | break; |
| 2179 | case Delete_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2180 | result = PyType_GenericNew(Delete_type, NULL, NULL); |
| 2181 | if (!result) goto failed; |
| 2182 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 2183 | if (!value) goto failed; |
| 2184 | if (PyObject_SetAttrString(result, "targets", value) == -1) |
| 2185 | goto failed; |
| 2186 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2187 | break; |
| 2188 | case Assign_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2189 | result = PyType_GenericNew(Assign_type, NULL, NULL); |
| 2190 | if (!result) goto failed; |
| 2191 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 2192 | if (!value) goto failed; |
| 2193 | if (PyObject_SetAttrString(result, "targets", value) == -1) |
| 2194 | goto failed; |
| 2195 | Py_DECREF(value); |
| 2196 | value = ast2obj_expr(o->v.Assign.value); |
| 2197 | if (!value) goto failed; |
| 2198 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2199 | goto failed; |
| 2200 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2201 | break; |
| 2202 | case AugAssign_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2203 | result = PyType_GenericNew(AugAssign_type, NULL, NULL); |
| 2204 | if (!result) goto failed; |
| 2205 | value = ast2obj_expr(o->v.AugAssign.target); |
| 2206 | if (!value) goto failed; |
| 2207 | if (PyObject_SetAttrString(result, "target", value) == -1) |
| 2208 | goto failed; |
| 2209 | Py_DECREF(value); |
| 2210 | value = ast2obj_operator(o->v.AugAssign.op); |
| 2211 | if (!value) goto failed; |
| 2212 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2213 | goto failed; |
| 2214 | Py_DECREF(value); |
| 2215 | value = ast2obj_expr(o->v.AugAssign.value); |
| 2216 | if (!value) goto failed; |
| 2217 | if (PyObject_SetAttrString(result, "value", 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 Print_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2222 | result = PyType_GenericNew(Print_type, NULL, NULL); |
| 2223 | if (!result) goto failed; |
| 2224 | value = ast2obj_expr(o->v.Print.dest); |
| 2225 | if (!value) goto failed; |
| 2226 | if (PyObject_SetAttrString(result, "dest", value) == -1) |
| 2227 | goto failed; |
| 2228 | Py_DECREF(value); |
| 2229 | value = ast2obj_list(o->v.Print.values, ast2obj_expr); |
| 2230 | if (!value) goto failed; |
| 2231 | if (PyObject_SetAttrString(result, "values", value) == -1) |
| 2232 | goto failed; |
| 2233 | Py_DECREF(value); |
| 2234 | value = ast2obj_bool(o->v.Print.nl); |
| 2235 | if (!value) goto failed; |
| 2236 | if (PyObject_SetAttrString(result, "nl", value) == -1) |
| 2237 | goto failed; |
| 2238 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2239 | break; |
| 2240 | case For_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2241 | result = PyType_GenericNew(For_type, NULL, NULL); |
| 2242 | if (!result) goto failed; |
| 2243 | value = ast2obj_expr(o->v.For.target); |
| 2244 | if (!value) goto failed; |
| 2245 | if (PyObject_SetAttrString(result, "target", value) == -1) |
| 2246 | goto failed; |
| 2247 | Py_DECREF(value); |
| 2248 | value = ast2obj_expr(o->v.For.iter); |
| 2249 | if (!value) goto failed; |
| 2250 | if (PyObject_SetAttrString(result, "iter", value) == -1) |
| 2251 | goto failed; |
| 2252 | Py_DECREF(value); |
| 2253 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 2254 | if (!value) goto failed; |
| 2255 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2256 | goto failed; |
| 2257 | Py_DECREF(value); |
| 2258 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 2259 | if (!value) goto failed; |
| 2260 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2261 | goto failed; |
| 2262 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2263 | break; |
| 2264 | case While_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2265 | result = PyType_GenericNew(While_type, NULL, NULL); |
| 2266 | if (!result) goto failed; |
| 2267 | value = ast2obj_expr(o->v.While.test); |
| 2268 | if (!value) goto failed; |
| 2269 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2270 | goto failed; |
| 2271 | Py_DECREF(value); |
| 2272 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 2273 | if (!value) goto failed; |
| 2274 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2275 | goto failed; |
| 2276 | Py_DECREF(value); |
| 2277 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 2278 | if (!value) goto failed; |
| 2279 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2280 | goto failed; |
| 2281 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2282 | break; |
| 2283 | case If_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2284 | result = PyType_GenericNew(If_type, NULL, NULL); |
| 2285 | if (!result) goto failed; |
| 2286 | value = ast2obj_expr(o->v.If.test); |
| 2287 | if (!value) goto failed; |
| 2288 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2289 | goto failed; |
| 2290 | Py_DECREF(value); |
| 2291 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 2292 | if (!value) goto failed; |
| 2293 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2294 | goto failed; |
| 2295 | Py_DECREF(value); |
| 2296 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 2297 | if (!value) goto failed; |
| 2298 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2299 | goto failed; |
| 2300 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2301 | break; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2302 | case With_kind: |
| 2303 | result = PyType_GenericNew(With_type, NULL, NULL); |
| 2304 | if (!result) goto failed; |
| 2305 | value = ast2obj_expr(o->v.With.context_expr); |
| 2306 | if (!value) goto failed; |
| 2307 | if (PyObject_SetAttrString(result, "context_expr", value) == -1) |
| 2308 | goto failed; |
| 2309 | Py_DECREF(value); |
| 2310 | value = ast2obj_expr(o->v.With.optional_vars); |
| 2311 | if (!value) goto failed; |
| 2312 | if (PyObject_SetAttrString(result, "optional_vars", value) == |
| 2313 | -1) |
| 2314 | goto failed; |
| 2315 | Py_DECREF(value); |
| 2316 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 2317 | if (!value) goto failed; |
| 2318 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2319 | goto failed; |
| 2320 | Py_DECREF(value); |
| 2321 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2322 | case Raise_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2323 | result = PyType_GenericNew(Raise_type, NULL, NULL); |
| 2324 | if (!result) goto failed; |
| 2325 | value = ast2obj_expr(o->v.Raise.type); |
| 2326 | if (!value) goto failed; |
| 2327 | if (PyObject_SetAttrString(result, "type", value) == -1) |
| 2328 | goto failed; |
| 2329 | Py_DECREF(value); |
| 2330 | value = ast2obj_expr(o->v.Raise.inst); |
| 2331 | if (!value) goto failed; |
| 2332 | if (PyObject_SetAttrString(result, "inst", value) == -1) |
| 2333 | goto failed; |
| 2334 | Py_DECREF(value); |
| 2335 | value = ast2obj_expr(o->v.Raise.tback); |
| 2336 | if (!value) goto failed; |
| 2337 | if (PyObject_SetAttrString(result, "tback", value) == -1) |
| 2338 | goto failed; |
| 2339 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2340 | break; |
| 2341 | case TryExcept_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2342 | result = PyType_GenericNew(TryExcept_type, NULL, NULL); |
| 2343 | if (!result) goto failed; |
| 2344 | value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt); |
| 2345 | if (!value) goto failed; |
| 2346 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2347 | goto failed; |
| 2348 | Py_DECREF(value); |
| 2349 | value = ast2obj_list(o->v.TryExcept.handlers, |
| 2350 | ast2obj_excepthandler); |
| 2351 | if (!value) goto failed; |
| 2352 | if (PyObject_SetAttrString(result, "handlers", value) == -1) |
| 2353 | goto failed; |
| 2354 | Py_DECREF(value); |
| 2355 | value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt); |
| 2356 | if (!value) goto failed; |
| 2357 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2358 | goto failed; |
| 2359 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2360 | break; |
| 2361 | case TryFinally_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2362 | result = PyType_GenericNew(TryFinally_type, NULL, NULL); |
| 2363 | if (!result) goto failed; |
| 2364 | value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt); |
| 2365 | if (!value) goto failed; |
| 2366 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2367 | goto failed; |
| 2368 | Py_DECREF(value); |
| 2369 | value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt); |
| 2370 | if (!value) goto failed; |
| 2371 | if (PyObject_SetAttrString(result, "finalbody", value) == -1) |
| 2372 | goto failed; |
| 2373 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2374 | break; |
| 2375 | case Assert_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2376 | result = PyType_GenericNew(Assert_type, NULL, NULL); |
| 2377 | if (!result) goto failed; |
| 2378 | value = ast2obj_expr(o->v.Assert.test); |
| 2379 | if (!value) goto failed; |
| 2380 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2381 | goto failed; |
| 2382 | Py_DECREF(value); |
| 2383 | value = ast2obj_expr(o->v.Assert.msg); |
| 2384 | if (!value) goto failed; |
| 2385 | if (PyObject_SetAttrString(result, "msg", value) == -1) |
| 2386 | goto failed; |
| 2387 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2388 | break; |
| 2389 | case Import_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2390 | result = PyType_GenericNew(Import_type, NULL, NULL); |
| 2391 | if (!result) goto failed; |
| 2392 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 2393 | if (!value) goto failed; |
| 2394 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2395 | goto failed; |
| 2396 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2397 | break; |
| 2398 | case ImportFrom_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2399 | result = PyType_GenericNew(ImportFrom_type, NULL, NULL); |
| 2400 | if (!result) goto failed; |
| 2401 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 2402 | if (!value) goto failed; |
| 2403 | if (PyObject_SetAttrString(result, "module", value) == -1) |
| 2404 | goto failed; |
| 2405 | Py_DECREF(value); |
| 2406 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 2407 | if (!value) goto failed; |
| 2408 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2409 | goto failed; |
| 2410 | Py_DECREF(value); |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 2411 | value = ast2obj_int(o->v.ImportFrom.level); |
| 2412 | if (!value) goto failed; |
| 2413 | if (PyObject_SetAttrString(result, "level", value) == -1) |
| 2414 | goto failed; |
| 2415 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2416 | break; |
| 2417 | case Exec_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2418 | result = PyType_GenericNew(Exec_type, NULL, NULL); |
| 2419 | if (!result) goto failed; |
| 2420 | value = ast2obj_expr(o->v.Exec.body); |
| 2421 | if (!value) goto failed; |
| 2422 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2423 | goto failed; |
| 2424 | Py_DECREF(value); |
| 2425 | value = ast2obj_expr(o->v.Exec.globals); |
| 2426 | if (!value) goto failed; |
| 2427 | if (PyObject_SetAttrString(result, "globals", value) == -1) |
| 2428 | goto failed; |
| 2429 | Py_DECREF(value); |
| 2430 | value = ast2obj_expr(o->v.Exec.locals); |
| 2431 | if (!value) goto failed; |
| 2432 | if (PyObject_SetAttrString(result, "locals", value) == -1) |
| 2433 | goto failed; |
| 2434 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2435 | break; |
| 2436 | case Global_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2437 | result = PyType_GenericNew(Global_type, NULL, NULL); |
| 2438 | if (!result) goto failed; |
| 2439 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 2440 | if (!value) goto failed; |
| 2441 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2442 | goto failed; |
| 2443 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2444 | break; |
| 2445 | case Expr_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2446 | result = PyType_GenericNew(Expr_type, NULL, NULL); |
| 2447 | if (!result) goto failed; |
| 2448 | value = ast2obj_expr(o->v.Expr.value); |
| 2449 | if (!value) goto failed; |
| 2450 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2451 | goto failed; |
| 2452 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2453 | break; |
| 2454 | case Pass_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2455 | result = PyType_GenericNew(Pass_type, NULL, NULL); |
| 2456 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2457 | break; |
| 2458 | case Break_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2459 | result = PyType_GenericNew(Break_type, NULL, NULL); |
| 2460 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2461 | break; |
| 2462 | case Continue_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2463 | result = PyType_GenericNew(Continue_type, NULL, NULL); |
| 2464 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2465 | break; |
| 2466 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2467 | value = ast2obj_int(o->lineno); |
| 2468 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2469 | if (PyObject_SetAttrString(result, "lineno", value) < 0) |
| 2470 | goto failed; |
| 2471 | Py_DECREF(value); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2472 | value = ast2obj_int(o->col_offset); |
| 2473 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2474 | if (PyObject_SetAttrString(result, "col_offset", value) < 0) |
| 2475 | goto failed; |
| 2476 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2477 | return result; |
| 2478 | failed: |
| 2479 | Py_XDECREF(value); |
| 2480 | Py_XDECREF(result); |
| 2481 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2482 | } |
| 2483 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2484 | PyObject* |
| 2485 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2486 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2487 | expr_ty o = (expr_ty)_o; |
| 2488 | PyObject *result = NULL, *value = NULL; |
| 2489 | if (!o) { |
| 2490 | Py_INCREF(Py_None); |
| 2491 | return Py_None; |
| 2492 | } |
| 2493 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2494 | switch (o->kind) { |
| 2495 | case BoolOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2496 | result = PyType_GenericNew(BoolOp_type, NULL, NULL); |
| 2497 | if (!result) goto failed; |
| 2498 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 2499 | if (!value) goto failed; |
| 2500 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2501 | goto failed; |
| 2502 | Py_DECREF(value); |
| 2503 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 2504 | if (!value) goto failed; |
| 2505 | if (PyObject_SetAttrString(result, "values", value) == -1) |
| 2506 | goto failed; |
| 2507 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2508 | break; |
| 2509 | case BinOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2510 | result = PyType_GenericNew(BinOp_type, NULL, NULL); |
| 2511 | if (!result) goto failed; |
| 2512 | value = ast2obj_expr(o->v.BinOp.left); |
| 2513 | if (!value) goto failed; |
| 2514 | if (PyObject_SetAttrString(result, "left", value) == -1) |
| 2515 | goto failed; |
| 2516 | Py_DECREF(value); |
| 2517 | value = ast2obj_operator(o->v.BinOp.op); |
| 2518 | if (!value) goto failed; |
| 2519 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2520 | goto failed; |
| 2521 | Py_DECREF(value); |
| 2522 | value = ast2obj_expr(o->v.BinOp.right); |
| 2523 | if (!value) goto failed; |
| 2524 | if (PyObject_SetAttrString(result, "right", 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 UnaryOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2529 | result = PyType_GenericNew(UnaryOp_type, NULL, NULL); |
| 2530 | if (!result) goto failed; |
| 2531 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 2532 | if (!value) goto failed; |
| 2533 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2534 | goto failed; |
| 2535 | Py_DECREF(value); |
| 2536 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 2537 | if (!value) goto failed; |
| 2538 | if (PyObject_SetAttrString(result, "operand", value) == -1) |
| 2539 | goto failed; |
| 2540 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2541 | break; |
| 2542 | case Lambda_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2543 | result = PyType_GenericNew(Lambda_type, NULL, NULL); |
| 2544 | if (!result) goto failed; |
| 2545 | value = ast2obj_arguments(o->v.Lambda.args); |
| 2546 | if (!value) goto failed; |
| 2547 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 2548 | goto failed; |
| 2549 | Py_DECREF(value); |
| 2550 | value = ast2obj_expr(o->v.Lambda.body); |
| 2551 | if (!value) goto failed; |
| 2552 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2553 | goto failed; |
| 2554 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2555 | break; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2556 | case IfExp_kind: |
| 2557 | result = PyType_GenericNew(IfExp_type, NULL, NULL); |
| 2558 | if (!result) goto failed; |
| 2559 | value = ast2obj_expr(o->v.IfExp.test); |
| 2560 | if (!value) goto failed; |
| 2561 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2562 | goto failed; |
| 2563 | Py_DECREF(value); |
| 2564 | value = ast2obj_expr(o->v.IfExp.body); |
| 2565 | if (!value) goto failed; |
| 2566 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2567 | goto failed; |
| 2568 | Py_DECREF(value); |
| 2569 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 2570 | if (!value) goto failed; |
| 2571 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2572 | goto failed; |
| 2573 | Py_DECREF(value); |
| 2574 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2575 | case Dict_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2576 | result = PyType_GenericNew(Dict_type, NULL, NULL); |
| 2577 | if (!result) goto failed; |
| 2578 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 2579 | if (!value) goto failed; |
| 2580 | if (PyObject_SetAttrString(result, "keys", value) == -1) |
| 2581 | goto failed; |
| 2582 | Py_DECREF(value); |
| 2583 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 2584 | if (!value) goto failed; |
| 2585 | if (PyObject_SetAttrString(result, "values", value) == -1) |
| 2586 | goto failed; |
| 2587 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2588 | break; |
Alexandre Vassalotti | ee936a2 | 2010-01-09 23:35:54 +0000 | [diff] [blame] | 2589 | case Set_kind: |
| 2590 | result = PyType_GenericNew(Set_type, NULL, NULL); |
| 2591 | if (!result) goto failed; |
| 2592 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 2593 | if (!value) goto failed; |
| 2594 | if (PyObject_SetAttrString(result, "elts", value) == -1) |
| 2595 | goto failed; |
| 2596 | Py_DECREF(value); |
| 2597 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2598 | case ListComp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2599 | result = PyType_GenericNew(ListComp_type, NULL, NULL); |
| 2600 | if (!result) goto failed; |
| 2601 | value = ast2obj_expr(o->v.ListComp.elt); |
| 2602 | if (!value) goto failed; |
| 2603 | if (PyObject_SetAttrString(result, "elt", value) == -1) |
| 2604 | goto failed; |
| 2605 | Py_DECREF(value); |
| 2606 | value = ast2obj_list(o->v.ListComp.generators, |
| 2607 | ast2obj_comprehension); |
| 2608 | if (!value) goto failed; |
| 2609 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2610 | goto failed; |
| 2611 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2612 | break; |
| 2613 | case GeneratorExp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2614 | result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); |
| 2615 | if (!result) goto failed; |
| 2616 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 2617 | if (!value) goto failed; |
| 2618 | if (PyObject_SetAttrString(result, "elt", value) == -1) |
| 2619 | goto failed; |
| 2620 | Py_DECREF(value); |
| 2621 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 2622 | ast2obj_comprehension); |
| 2623 | if (!value) goto failed; |
| 2624 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2625 | goto failed; |
| 2626 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2627 | break; |
| 2628 | case Yield_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2629 | result = PyType_GenericNew(Yield_type, NULL, NULL); |
| 2630 | if (!result) goto failed; |
| 2631 | value = ast2obj_expr(o->v.Yield.value); |
| 2632 | if (!value) goto failed; |
| 2633 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2634 | goto failed; |
| 2635 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2636 | break; |
| 2637 | case Compare_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2638 | result = PyType_GenericNew(Compare_type, NULL, NULL); |
| 2639 | if (!result) goto failed; |
| 2640 | value = ast2obj_expr(o->v.Compare.left); |
| 2641 | if (!value) goto failed; |
| 2642 | if (PyObject_SetAttrString(result, "left", value) == -1) |
| 2643 | goto failed; |
| 2644 | Py_DECREF(value); |
Martin v. Löwis | ce1d5d2 | 2006-02-26 20:51:25 +0000 | [diff] [blame] | 2645 | { |
| 2646 | int i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 2647 | value = PyList_New(n); |
| 2648 | if (!value) goto failed; |
| 2649 | for(i = 0; i < n; i++) |
Martin v. Löwis | 0cc56e5 | 2006-04-13 12:29:43 +0000 | [diff] [blame] | 2650 | 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] | 2651 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2652 | if (!value) goto failed; |
| 2653 | if (PyObject_SetAttrString(result, "ops", value) == -1) |
| 2654 | goto failed; |
| 2655 | Py_DECREF(value); |
| 2656 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
| 2657 | if (!value) goto failed; |
| 2658 | if (PyObject_SetAttrString(result, "comparators", value) == -1) |
| 2659 | goto failed; |
| 2660 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2661 | break; |
| 2662 | case Call_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2663 | result = PyType_GenericNew(Call_type, NULL, NULL); |
| 2664 | if (!result) goto failed; |
| 2665 | value = ast2obj_expr(o->v.Call.func); |
| 2666 | if (!value) goto failed; |
| 2667 | if (PyObject_SetAttrString(result, "func", value) == -1) |
| 2668 | goto failed; |
| 2669 | Py_DECREF(value); |
| 2670 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 2671 | if (!value) goto failed; |
| 2672 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 2673 | goto failed; |
| 2674 | Py_DECREF(value); |
| 2675 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 2676 | if (!value) goto failed; |
| 2677 | if (PyObject_SetAttrString(result, "keywords", value) == -1) |
| 2678 | goto failed; |
| 2679 | Py_DECREF(value); |
| 2680 | value = ast2obj_expr(o->v.Call.starargs); |
| 2681 | if (!value) goto failed; |
| 2682 | if (PyObject_SetAttrString(result, "starargs", value) == -1) |
| 2683 | goto failed; |
| 2684 | Py_DECREF(value); |
| 2685 | value = ast2obj_expr(o->v.Call.kwargs); |
| 2686 | if (!value) goto failed; |
| 2687 | if (PyObject_SetAttrString(result, "kwargs", value) == -1) |
| 2688 | goto failed; |
| 2689 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2690 | break; |
| 2691 | case Repr_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2692 | result = PyType_GenericNew(Repr_type, NULL, NULL); |
| 2693 | if (!result) goto failed; |
| 2694 | value = ast2obj_expr(o->v.Repr.value); |
| 2695 | if (!value) goto failed; |
| 2696 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2697 | goto failed; |
| 2698 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2699 | break; |
| 2700 | case Num_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2701 | result = PyType_GenericNew(Num_type, NULL, NULL); |
| 2702 | if (!result) goto failed; |
| 2703 | value = ast2obj_object(o->v.Num.n); |
| 2704 | if (!value) goto failed; |
| 2705 | if (PyObject_SetAttrString(result, "n", value) == -1) |
| 2706 | goto failed; |
| 2707 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2708 | break; |
| 2709 | case Str_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2710 | result = PyType_GenericNew(Str_type, NULL, NULL); |
| 2711 | if (!result) goto failed; |
| 2712 | value = ast2obj_string(o->v.Str.s); |
| 2713 | if (!value) goto failed; |
| 2714 | if (PyObject_SetAttrString(result, "s", value) == -1) |
| 2715 | goto failed; |
| 2716 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2717 | break; |
| 2718 | case Attribute_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2719 | result = PyType_GenericNew(Attribute_type, NULL, NULL); |
| 2720 | if (!result) goto failed; |
| 2721 | value = ast2obj_expr(o->v.Attribute.value); |
| 2722 | if (!value) goto failed; |
| 2723 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2724 | goto failed; |
| 2725 | Py_DECREF(value); |
| 2726 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 2727 | if (!value) goto failed; |
| 2728 | if (PyObject_SetAttrString(result, "attr", value) == -1) |
| 2729 | goto failed; |
| 2730 | Py_DECREF(value); |
| 2731 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 2732 | if (!value) goto failed; |
| 2733 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2734 | goto failed; |
| 2735 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2736 | break; |
| 2737 | case Subscript_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2738 | result = PyType_GenericNew(Subscript_type, NULL, NULL); |
| 2739 | if (!result) goto failed; |
| 2740 | value = ast2obj_expr(o->v.Subscript.value); |
| 2741 | if (!value) goto failed; |
| 2742 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2743 | goto failed; |
| 2744 | Py_DECREF(value); |
| 2745 | value = ast2obj_slice(o->v.Subscript.slice); |
| 2746 | if (!value) goto failed; |
| 2747 | if (PyObject_SetAttrString(result, "slice", value) == -1) |
| 2748 | goto failed; |
| 2749 | Py_DECREF(value); |
| 2750 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 2751 | if (!value) goto failed; |
| 2752 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2753 | goto failed; |
| 2754 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2755 | break; |
| 2756 | case Name_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2757 | result = PyType_GenericNew(Name_type, NULL, NULL); |
| 2758 | if (!result) goto failed; |
| 2759 | value = ast2obj_identifier(o->v.Name.id); |
| 2760 | if (!value) goto failed; |
| 2761 | if (PyObject_SetAttrString(result, "id", value) == -1) |
| 2762 | goto failed; |
| 2763 | Py_DECREF(value); |
| 2764 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 2765 | if (!value) goto failed; |
| 2766 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2767 | goto failed; |
| 2768 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2769 | break; |
| 2770 | case List_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2771 | result = PyType_GenericNew(List_type, NULL, NULL); |
| 2772 | if (!result) goto failed; |
| 2773 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 2774 | if (!value) goto failed; |
| 2775 | if (PyObject_SetAttrString(result, "elts", value) == -1) |
| 2776 | goto failed; |
| 2777 | Py_DECREF(value); |
| 2778 | value = ast2obj_expr_context(o->v.List.ctx); |
| 2779 | if (!value) goto failed; |
| 2780 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2781 | goto failed; |
| 2782 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2783 | break; |
| 2784 | case Tuple_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2785 | result = PyType_GenericNew(Tuple_type, NULL, NULL); |
| 2786 | if (!result) goto failed; |
| 2787 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 2788 | if (!value) goto failed; |
| 2789 | if (PyObject_SetAttrString(result, "elts", value) == -1) |
| 2790 | goto failed; |
| 2791 | Py_DECREF(value); |
| 2792 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 2793 | if (!value) goto failed; |
| 2794 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2795 | goto failed; |
| 2796 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2797 | break; |
| 2798 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2799 | value = ast2obj_int(o->lineno); |
| 2800 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2801 | if (PyObject_SetAttrString(result, "lineno", value) < 0) |
| 2802 | goto failed; |
| 2803 | Py_DECREF(value); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2804 | value = ast2obj_int(o->col_offset); |
| 2805 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2806 | if (PyObject_SetAttrString(result, "col_offset", value) < 0) |
| 2807 | goto failed; |
| 2808 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2809 | return result; |
| 2810 | failed: |
| 2811 | Py_XDECREF(value); |
| 2812 | Py_XDECREF(result); |
| 2813 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2814 | } |
| 2815 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2816 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2817 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2818 | switch(o) { |
| 2819 | case Load: |
| 2820 | Py_INCREF(Load_singleton); |
| 2821 | return Load_singleton; |
| 2822 | case Store: |
| 2823 | Py_INCREF(Store_singleton); |
| 2824 | return Store_singleton; |
| 2825 | case Del: |
| 2826 | Py_INCREF(Del_singleton); |
| 2827 | return Del_singleton; |
| 2828 | case AugLoad: |
| 2829 | Py_INCREF(AugLoad_singleton); |
| 2830 | return AugLoad_singleton; |
| 2831 | case AugStore: |
| 2832 | Py_INCREF(AugStore_singleton); |
| 2833 | return AugStore_singleton; |
| 2834 | case Param: |
| 2835 | Py_INCREF(Param_singleton); |
| 2836 | return Param_singleton; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 2837 | default: |
| 2838 | /* should never happen, but just in case ... */ |
| 2839 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 2840 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2841 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2842 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2843 | PyObject* |
| 2844 | ast2obj_slice(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2845 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2846 | slice_ty o = (slice_ty)_o; |
| 2847 | PyObject *result = NULL, *value = NULL; |
| 2848 | if (!o) { |
| 2849 | Py_INCREF(Py_None); |
| 2850 | return Py_None; |
| 2851 | } |
| 2852 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2853 | switch (o->kind) { |
| 2854 | case Ellipsis_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2855 | result = PyType_GenericNew(Ellipsis_type, NULL, NULL); |
| 2856 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2857 | break; |
| 2858 | case Slice_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2859 | result = PyType_GenericNew(Slice_type, NULL, NULL); |
| 2860 | if (!result) goto failed; |
| 2861 | value = ast2obj_expr(o->v.Slice.lower); |
| 2862 | if (!value) goto failed; |
| 2863 | if (PyObject_SetAttrString(result, "lower", value) == -1) |
| 2864 | goto failed; |
| 2865 | Py_DECREF(value); |
| 2866 | value = ast2obj_expr(o->v.Slice.upper); |
| 2867 | if (!value) goto failed; |
| 2868 | if (PyObject_SetAttrString(result, "upper", value) == -1) |
| 2869 | goto failed; |
| 2870 | Py_DECREF(value); |
| 2871 | value = ast2obj_expr(o->v.Slice.step); |
| 2872 | if (!value) goto failed; |
| 2873 | if (PyObject_SetAttrString(result, "step", value) == -1) |
| 2874 | goto failed; |
| 2875 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2876 | break; |
| 2877 | case ExtSlice_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2878 | result = PyType_GenericNew(ExtSlice_type, NULL, NULL); |
| 2879 | if (!result) goto failed; |
| 2880 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 2881 | if (!value) goto failed; |
| 2882 | if (PyObject_SetAttrString(result, "dims", value) == -1) |
| 2883 | goto failed; |
| 2884 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2885 | break; |
| 2886 | case Index_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2887 | result = PyType_GenericNew(Index_type, NULL, NULL); |
| 2888 | if (!result) goto failed; |
| 2889 | value = ast2obj_expr(o->v.Index.value); |
| 2890 | if (!value) goto failed; |
| 2891 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2892 | goto failed; |
| 2893 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2894 | break; |
| 2895 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2896 | return result; |
| 2897 | failed: |
| 2898 | Py_XDECREF(value); |
| 2899 | Py_XDECREF(result); |
| 2900 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2901 | } |
| 2902 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2903 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2904 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2905 | switch(o) { |
| 2906 | case And: |
| 2907 | Py_INCREF(And_singleton); |
| 2908 | return And_singleton; |
| 2909 | case Or: |
| 2910 | Py_INCREF(Or_singleton); |
| 2911 | return Or_singleton; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 2912 | default: |
| 2913 | /* should never happen, but just in case ... */ |
| 2914 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 2915 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2916 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2917 | } |
| 2918 | PyObject* ast2obj_operator(operator_ty o) |
| 2919 | { |
| 2920 | switch(o) { |
| 2921 | case Add: |
| 2922 | Py_INCREF(Add_singleton); |
| 2923 | return Add_singleton; |
| 2924 | case Sub: |
| 2925 | Py_INCREF(Sub_singleton); |
| 2926 | return Sub_singleton; |
| 2927 | case Mult: |
| 2928 | Py_INCREF(Mult_singleton); |
| 2929 | return Mult_singleton; |
| 2930 | case Div: |
| 2931 | Py_INCREF(Div_singleton); |
| 2932 | return Div_singleton; |
| 2933 | case Mod: |
| 2934 | Py_INCREF(Mod_singleton); |
| 2935 | return Mod_singleton; |
| 2936 | case Pow: |
| 2937 | Py_INCREF(Pow_singleton); |
| 2938 | return Pow_singleton; |
| 2939 | case LShift: |
| 2940 | Py_INCREF(LShift_singleton); |
| 2941 | return LShift_singleton; |
| 2942 | case RShift: |
| 2943 | Py_INCREF(RShift_singleton); |
| 2944 | return RShift_singleton; |
| 2945 | case BitOr: |
| 2946 | Py_INCREF(BitOr_singleton); |
| 2947 | return BitOr_singleton; |
| 2948 | case BitXor: |
| 2949 | Py_INCREF(BitXor_singleton); |
| 2950 | return BitXor_singleton; |
| 2951 | case BitAnd: |
| 2952 | Py_INCREF(BitAnd_singleton); |
| 2953 | return BitAnd_singleton; |
| 2954 | case FloorDiv: |
| 2955 | Py_INCREF(FloorDiv_singleton); |
| 2956 | return FloorDiv_singleton; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 2957 | default: |
| 2958 | /* should never happen, but just in case ... */ |
| 2959 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 2960 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2961 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2962 | } |
| 2963 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 2964 | { |
| 2965 | switch(o) { |
| 2966 | case Invert: |
| 2967 | Py_INCREF(Invert_singleton); |
| 2968 | return Invert_singleton; |
| 2969 | case Not: |
| 2970 | Py_INCREF(Not_singleton); |
| 2971 | return Not_singleton; |
| 2972 | case UAdd: |
| 2973 | Py_INCREF(UAdd_singleton); |
| 2974 | return UAdd_singleton; |
| 2975 | case USub: |
| 2976 | Py_INCREF(USub_singleton); |
| 2977 | return USub_singleton; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 2978 | default: |
| 2979 | /* should never happen, but just in case ... */ |
| 2980 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 2981 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2982 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2983 | } |
| 2984 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 2985 | { |
| 2986 | switch(o) { |
| 2987 | case Eq: |
| 2988 | Py_INCREF(Eq_singleton); |
| 2989 | return Eq_singleton; |
| 2990 | case NotEq: |
| 2991 | Py_INCREF(NotEq_singleton); |
| 2992 | return NotEq_singleton; |
| 2993 | case Lt: |
| 2994 | Py_INCREF(Lt_singleton); |
| 2995 | return Lt_singleton; |
| 2996 | case LtE: |
| 2997 | Py_INCREF(LtE_singleton); |
| 2998 | return LtE_singleton; |
| 2999 | case Gt: |
| 3000 | Py_INCREF(Gt_singleton); |
| 3001 | return Gt_singleton; |
| 3002 | case GtE: |
| 3003 | Py_INCREF(GtE_singleton); |
| 3004 | return GtE_singleton; |
| 3005 | case Is: |
| 3006 | Py_INCREF(Is_singleton); |
| 3007 | return Is_singleton; |
| 3008 | case IsNot: |
| 3009 | Py_INCREF(IsNot_singleton); |
| 3010 | return IsNot_singleton; |
| 3011 | case In: |
| 3012 | Py_INCREF(In_singleton); |
| 3013 | return In_singleton; |
| 3014 | case NotIn: |
| 3015 | Py_INCREF(NotIn_singleton); |
| 3016 | return NotIn_singleton; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3017 | default: |
| 3018 | /* should never happen, but just in case ... */ |
| 3019 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 3020 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3021 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3022 | } |
| 3023 | PyObject* |
| 3024 | ast2obj_comprehension(void* _o) |
| 3025 | { |
| 3026 | comprehension_ty o = (comprehension_ty)_o; |
| 3027 | PyObject *result = NULL, *value = NULL; |
| 3028 | if (!o) { |
| 3029 | Py_INCREF(Py_None); |
| 3030 | return Py_None; |
| 3031 | } |
| 3032 | |
| 3033 | result = PyType_GenericNew(comprehension_type, NULL, NULL); |
| 3034 | if (!result) return NULL; |
| 3035 | value = ast2obj_expr(o->target); |
| 3036 | if (!value) goto failed; |
| 3037 | if (PyObject_SetAttrString(result, "target", value) == -1) |
| 3038 | goto failed; |
| 3039 | Py_DECREF(value); |
| 3040 | value = ast2obj_expr(o->iter); |
| 3041 | if (!value) goto failed; |
| 3042 | if (PyObject_SetAttrString(result, "iter", value) == -1) |
| 3043 | goto failed; |
| 3044 | Py_DECREF(value); |
| 3045 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 3046 | if (!value) goto failed; |
| 3047 | if (PyObject_SetAttrString(result, "ifs", value) == -1) |
| 3048 | goto failed; |
| 3049 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3050 | return result; |
| 3051 | failed: |
| 3052 | Py_XDECREF(value); |
| 3053 | Py_XDECREF(result); |
| 3054 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3055 | } |
| 3056 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3057 | PyObject* |
| 3058 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3059 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3060 | excepthandler_ty o = (excepthandler_ty)_o; |
| 3061 | PyObject *result = NULL, *value = NULL; |
| 3062 | if (!o) { |
| 3063 | Py_INCREF(Py_None); |
| 3064 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3065 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3066 | |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame] | 3067 | switch (o->kind) { |
| 3068 | case ExceptHandler_kind: |
| 3069 | result = PyType_GenericNew(ExceptHandler_type, NULL, NULL); |
| 3070 | if (!result) goto failed; |
| 3071 | value = ast2obj_expr(o->v.ExceptHandler.type); |
| 3072 | if (!value) goto failed; |
| 3073 | if (PyObject_SetAttrString(result, "type", value) == -1) |
| 3074 | goto failed; |
| 3075 | Py_DECREF(value); |
| 3076 | value = ast2obj_expr(o->v.ExceptHandler.name); |
| 3077 | if (!value) goto failed; |
| 3078 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 3079 | goto failed; |
| 3080 | Py_DECREF(value); |
| 3081 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 3082 | if (!value) goto failed; |
| 3083 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 3084 | goto failed; |
| 3085 | Py_DECREF(value); |
| 3086 | break; |
| 3087 | } |
Jeremy Hylton | 2f327c1 | 2006-04-04 04:00:23 +0000 | [diff] [blame] | 3088 | value = ast2obj_int(o->lineno); |
| 3089 | if (!value) goto failed; |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame] | 3090 | if (PyObject_SetAttrString(result, "lineno", value) < 0) |
Jeremy Hylton | 2f327c1 | 2006-04-04 04:00:23 +0000 | [diff] [blame] | 3091 | goto failed; |
| 3092 | Py_DECREF(value); |
| 3093 | value = ast2obj_int(o->col_offset); |
| 3094 | if (!value) goto failed; |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame] | 3095 | if (PyObject_SetAttrString(result, "col_offset", value) < 0) |
Jeremy Hylton | 2f327c1 | 2006-04-04 04:00:23 +0000 | [diff] [blame] | 3096 | goto failed; |
| 3097 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3098 | return result; |
| 3099 | failed: |
| 3100 | Py_XDECREF(value); |
| 3101 | Py_XDECREF(result); |
| 3102 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3103 | } |
| 3104 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3105 | PyObject* |
| 3106 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3107 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3108 | arguments_ty o = (arguments_ty)_o; |
| 3109 | PyObject *result = NULL, *value = NULL; |
| 3110 | if (!o) { |
| 3111 | Py_INCREF(Py_None); |
| 3112 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3113 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3114 | |
| 3115 | result = PyType_GenericNew(arguments_type, NULL, NULL); |
| 3116 | if (!result) return NULL; |
| 3117 | value = ast2obj_list(o->args, ast2obj_expr); |
| 3118 | if (!value) goto failed; |
| 3119 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 3120 | goto failed; |
| 3121 | Py_DECREF(value); |
| 3122 | value = ast2obj_identifier(o->vararg); |
| 3123 | if (!value) goto failed; |
| 3124 | if (PyObject_SetAttrString(result, "vararg", value) == -1) |
| 3125 | goto failed; |
| 3126 | Py_DECREF(value); |
| 3127 | value = ast2obj_identifier(o->kwarg); |
| 3128 | if (!value) goto failed; |
| 3129 | if (PyObject_SetAttrString(result, "kwarg", value) == -1) |
| 3130 | goto failed; |
| 3131 | Py_DECREF(value); |
| 3132 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 3133 | if (!value) goto failed; |
| 3134 | if (PyObject_SetAttrString(result, "defaults", value) == -1) |
| 3135 | goto failed; |
| 3136 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3137 | return result; |
| 3138 | failed: |
| 3139 | Py_XDECREF(value); |
| 3140 | Py_XDECREF(result); |
| 3141 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3142 | } |
| 3143 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3144 | PyObject* |
| 3145 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3146 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3147 | keyword_ty o = (keyword_ty)_o; |
| 3148 | PyObject *result = NULL, *value = NULL; |
| 3149 | if (!o) { |
| 3150 | Py_INCREF(Py_None); |
| 3151 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3152 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3153 | |
| 3154 | result = PyType_GenericNew(keyword_type, NULL, NULL); |
| 3155 | if (!result) return NULL; |
| 3156 | value = ast2obj_identifier(o->arg); |
| 3157 | if (!value) goto failed; |
| 3158 | if (PyObject_SetAttrString(result, "arg", value) == -1) |
| 3159 | goto failed; |
| 3160 | Py_DECREF(value); |
| 3161 | value = ast2obj_expr(o->value); |
| 3162 | if (!value) goto failed; |
| 3163 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 3164 | goto failed; |
| 3165 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3166 | return result; |
| 3167 | failed: |
| 3168 | Py_XDECREF(value); |
| 3169 | Py_XDECREF(result); |
| 3170 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3171 | } |
| 3172 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3173 | PyObject* |
| 3174 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3175 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3176 | alias_ty o = (alias_ty)_o; |
| 3177 | PyObject *result = NULL, *value = NULL; |
| 3178 | if (!o) { |
| 3179 | Py_INCREF(Py_None); |
| 3180 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3181 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3182 | |
| 3183 | result = PyType_GenericNew(alias_type, NULL, NULL); |
| 3184 | if (!result) return NULL; |
| 3185 | value = ast2obj_identifier(o->name); |
| 3186 | if (!value) goto failed; |
| 3187 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 3188 | goto failed; |
| 3189 | Py_DECREF(value); |
| 3190 | value = ast2obj_identifier(o->asname); |
| 3191 | if (!value) goto failed; |
| 3192 | if (PyObject_SetAttrString(result, "asname", value) == -1) |
| 3193 | goto failed; |
| 3194 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3195 | return result; |
| 3196 | failed: |
| 3197 | Py_XDECREF(value); |
| 3198 | Py_XDECREF(result); |
| 3199 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3200 | } |
| 3201 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3202 | |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3203 | int |
| 3204 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 3205 | { |
| 3206 | PyObject* tmp = NULL; |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 3207 | int isinstance; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3208 | |
| 3209 | |
| 3210 | if (obj == Py_None) { |
| 3211 | *out = NULL; |
| 3212 | return 0; |
| 3213 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 3214 | isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type); |
| 3215 | if (isinstance == -1) { |
| 3216 | return 1; |
| 3217 | } |
| 3218 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3219 | asdl_seq* body; |
| 3220 | |
| 3221 | if (PyObject_HasAttrString(obj, "body")) { |
| 3222 | int res; |
| 3223 | Py_ssize_t len; |
| 3224 | Py_ssize_t i; |
| 3225 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3226 | if (tmp == NULL) goto failed; |
| 3227 | if (!PyList_Check(tmp)) { |
| 3228 | PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3229 | goto failed; |
| 3230 | } |
| 3231 | len = PyList_GET_SIZE(tmp); |
| 3232 | body = asdl_seq_new(len, arena); |
| 3233 | if (body == NULL) goto failed; |
| 3234 | for (i = 0; i < len; i++) { |
| 3235 | stmt_ty value; |
| 3236 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3237 | if (res != 0) goto failed; |
| 3238 | asdl_seq_SET(body, i, value); |
| 3239 | } |
| 3240 | Py_XDECREF(tmp); |
| 3241 | tmp = NULL; |
| 3242 | } else { |
| 3243 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 3244 | return 1; |
| 3245 | } |
| 3246 | *out = Module(body, arena); |
| 3247 | if (*out == NULL) goto failed; |
| 3248 | return 0; |
| 3249 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 3250 | isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type); |
| 3251 | if (isinstance == -1) { |
| 3252 | return 1; |
| 3253 | } |
| 3254 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3255 | asdl_seq* body; |
| 3256 | |
| 3257 | if (PyObject_HasAttrString(obj, "body")) { |
| 3258 | int res; |
| 3259 | Py_ssize_t len; |
| 3260 | Py_ssize_t i; |
| 3261 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3262 | if (tmp == NULL) goto failed; |
| 3263 | if (!PyList_Check(tmp)) { |
| 3264 | PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3265 | goto failed; |
| 3266 | } |
| 3267 | len = PyList_GET_SIZE(tmp); |
| 3268 | body = asdl_seq_new(len, arena); |
| 3269 | if (body == NULL) goto failed; |
| 3270 | for (i = 0; i < len; i++) { |
| 3271 | stmt_ty value; |
| 3272 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3273 | if (res != 0) goto failed; |
| 3274 | asdl_seq_SET(body, i, value); |
| 3275 | } |
| 3276 | Py_XDECREF(tmp); |
| 3277 | tmp = NULL; |
| 3278 | } else { |
| 3279 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 3280 | return 1; |
| 3281 | } |
| 3282 | *out = Interactive(body, arena); |
| 3283 | if (*out == NULL) goto failed; |
| 3284 | return 0; |
| 3285 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 3286 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type); |
| 3287 | if (isinstance == -1) { |
| 3288 | return 1; |
| 3289 | } |
| 3290 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3291 | expr_ty body; |
| 3292 | |
| 3293 | if (PyObject_HasAttrString(obj, "body")) { |
| 3294 | int res; |
| 3295 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3296 | if (tmp == NULL) goto failed; |
| 3297 | res = obj2ast_expr(tmp, &body, arena); |
| 3298 | if (res != 0) goto failed; |
| 3299 | Py_XDECREF(tmp); |
| 3300 | tmp = NULL; |
| 3301 | } else { |
| 3302 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 3303 | return 1; |
| 3304 | } |
| 3305 | *out = Expression(body, arena); |
| 3306 | if (*out == NULL) goto failed; |
| 3307 | return 0; |
| 3308 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 3309 | isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type); |
| 3310 | if (isinstance == -1) { |
| 3311 | return 1; |
| 3312 | } |
| 3313 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3314 | asdl_seq* body; |
| 3315 | |
| 3316 | if (PyObject_HasAttrString(obj, "body")) { |
| 3317 | int res; |
| 3318 | Py_ssize_t len; |
| 3319 | Py_ssize_t i; |
| 3320 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3321 | if (tmp == NULL) goto failed; |
| 3322 | if (!PyList_Check(tmp)) { |
| 3323 | PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3324 | goto failed; |
| 3325 | } |
| 3326 | len = PyList_GET_SIZE(tmp); |
| 3327 | body = asdl_seq_new(len, arena); |
| 3328 | if (body == NULL) goto failed; |
| 3329 | for (i = 0; i < len; i++) { |
| 3330 | stmt_ty value; |
| 3331 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3332 | if (res != 0) goto failed; |
| 3333 | asdl_seq_SET(body, i, value); |
| 3334 | } |
| 3335 | Py_XDECREF(tmp); |
| 3336 | tmp = NULL; |
| 3337 | } else { |
| 3338 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite"); |
| 3339 | return 1; |
| 3340 | } |
| 3341 | *out = Suite(body, arena); |
| 3342 | if (*out == NULL) goto failed; |
| 3343 | return 0; |
| 3344 | } |
| 3345 | |
| 3346 | tmp = PyObject_Repr(obj); |
| 3347 | if (tmp == NULL) goto failed; |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 3348 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %.400s", PyString_AS_STRING(tmp)); |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3349 | failed: |
| 3350 | Py_XDECREF(tmp); |
| 3351 | return 1; |
| 3352 | } |
| 3353 | |
| 3354 | int |
| 3355 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 3356 | { |
| 3357 | PyObject* tmp = NULL; |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 3358 | int isinstance; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3359 | |
| 3360 | int lineno; |
| 3361 | int col_offset; |
| 3362 | |
| 3363 | if (obj == Py_None) { |
| 3364 | *out = NULL; |
| 3365 | return 0; |
| 3366 | } |
| 3367 | if (PyObject_HasAttrString(obj, "lineno")) { |
| 3368 | int res; |
| 3369 | tmp = PyObject_GetAttrString(obj, "lineno"); |
| 3370 | if (tmp == NULL) goto failed; |
| 3371 | res = obj2ast_int(tmp, &lineno, arena); |
| 3372 | if (res != 0) goto failed; |
| 3373 | Py_XDECREF(tmp); |
| 3374 | tmp = NULL; |
| 3375 | } else { |
| 3376 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 3377 | return 1; |
| 3378 | } |
| 3379 | if (PyObject_HasAttrString(obj, "col_offset")) { |
| 3380 | int res; |
| 3381 | tmp = PyObject_GetAttrString(obj, "col_offset"); |
| 3382 | if (tmp == NULL) goto failed; |
| 3383 | res = obj2ast_int(tmp, &col_offset, arena); |
| 3384 | if (res != 0) goto failed; |
| 3385 | Py_XDECREF(tmp); |
| 3386 | tmp = NULL; |
| 3387 | } else { |
| 3388 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 3389 | return 1; |
| 3390 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 3391 | isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type); |
| 3392 | if (isinstance == -1) { |
| 3393 | return 1; |
| 3394 | } |
| 3395 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3396 | identifier name; |
| 3397 | arguments_ty args; |
| 3398 | asdl_seq* body; |
| 3399 | asdl_seq* decorator_list; |
| 3400 | |
| 3401 | if (PyObject_HasAttrString(obj, "name")) { |
| 3402 | int res; |
| 3403 | tmp = PyObject_GetAttrString(obj, "name"); |
| 3404 | if (tmp == NULL) goto failed; |
| 3405 | res = obj2ast_identifier(tmp, &name, arena); |
| 3406 | if (res != 0) goto failed; |
| 3407 | Py_XDECREF(tmp); |
| 3408 | tmp = NULL; |
| 3409 | } else { |
| 3410 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 3411 | return 1; |
| 3412 | } |
| 3413 | if (PyObject_HasAttrString(obj, "args")) { |
| 3414 | int res; |
| 3415 | tmp = PyObject_GetAttrString(obj, "args"); |
| 3416 | if (tmp == NULL) goto failed; |
| 3417 | res = obj2ast_arguments(tmp, &args, arena); |
| 3418 | if (res != 0) goto failed; |
| 3419 | Py_XDECREF(tmp); |
| 3420 | tmp = NULL; |
| 3421 | } else { |
| 3422 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 3423 | return 1; |
| 3424 | } |
| 3425 | if (PyObject_HasAttrString(obj, "body")) { |
| 3426 | int res; |
| 3427 | Py_ssize_t len; |
| 3428 | Py_ssize_t i; |
| 3429 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3430 | if (tmp == NULL) goto failed; |
| 3431 | if (!PyList_Check(tmp)) { |
| 3432 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3433 | goto failed; |
| 3434 | } |
| 3435 | len = PyList_GET_SIZE(tmp); |
| 3436 | body = asdl_seq_new(len, arena); |
| 3437 | if (body == NULL) goto failed; |
| 3438 | for (i = 0; i < len; i++) { |
| 3439 | stmt_ty value; |
| 3440 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3441 | if (res != 0) goto failed; |
| 3442 | asdl_seq_SET(body, i, value); |
| 3443 | } |
| 3444 | Py_XDECREF(tmp); |
| 3445 | tmp = NULL; |
| 3446 | } else { |
| 3447 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 3448 | return 1; |
| 3449 | } |
| 3450 | if (PyObject_HasAttrString(obj, "decorator_list")) { |
| 3451 | int res; |
| 3452 | Py_ssize_t len; |
| 3453 | Py_ssize_t i; |
| 3454 | tmp = PyObject_GetAttrString(obj, "decorator_list"); |
| 3455 | if (tmp == NULL) goto failed; |
| 3456 | if (!PyList_Check(tmp)) { |
| 3457 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3458 | goto failed; |
| 3459 | } |
| 3460 | len = PyList_GET_SIZE(tmp); |
| 3461 | decorator_list = asdl_seq_new(len, arena); |
| 3462 | if (decorator_list == NULL) goto failed; |
| 3463 | for (i = 0; i < len; i++) { |
| 3464 | expr_ty value; |
| 3465 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3466 | if (res != 0) goto failed; |
| 3467 | asdl_seq_SET(decorator_list, i, value); |
| 3468 | } |
| 3469 | Py_XDECREF(tmp); |
| 3470 | tmp = NULL; |
| 3471 | } else { |
| 3472 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 3473 | return 1; |
| 3474 | } |
| 3475 | *out = FunctionDef(name, args, body, decorator_list, lineno, |
| 3476 | col_offset, arena); |
| 3477 | if (*out == NULL) goto failed; |
| 3478 | return 0; |
| 3479 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 3480 | isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type); |
| 3481 | if (isinstance == -1) { |
| 3482 | return 1; |
| 3483 | } |
| 3484 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3485 | identifier name; |
| 3486 | asdl_seq* bases; |
| 3487 | asdl_seq* body; |
| 3488 | asdl_seq* decorator_list; |
| 3489 | |
| 3490 | if (PyObject_HasAttrString(obj, "name")) { |
| 3491 | int res; |
| 3492 | tmp = PyObject_GetAttrString(obj, "name"); |
| 3493 | if (tmp == NULL) goto failed; |
| 3494 | res = obj2ast_identifier(tmp, &name, arena); |
| 3495 | if (res != 0) goto failed; |
| 3496 | Py_XDECREF(tmp); |
| 3497 | tmp = NULL; |
| 3498 | } else { |
| 3499 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 3500 | return 1; |
| 3501 | } |
| 3502 | if (PyObject_HasAttrString(obj, "bases")) { |
| 3503 | int res; |
| 3504 | Py_ssize_t len; |
| 3505 | Py_ssize_t i; |
| 3506 | tmp = PyObject_GetAttrString(obj, "bases"); |
| 3507 | if (tmp == NULL) goto failed; |
| 3508 | if (!PyList_Check(tmp)) { |
| 3509 | PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3510 | goto failed; |
| 3511 | } |
| 3512 | len = PyList_GET_SIZE(tmp); |
| 3513 | bases = asdl_seq_new(len, arena); |
| 3514 | if (bases == NULL) goto failed; |
| 3515 | for (i = 0; i < len; i++) { |
| 3516 | expr_ty value; |
| 3517 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3518 | if (res != 0) goto failed; |
| 3519 | asdl_seq_SET(bases, i, value); |
| 3520 | } |
| 3521 | Py_XDECREF(tmp); |
| 3522 | tmp = NULL; |
| 3523 | } else { |
| 3524 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 3525 | return 1; |
| 3526 | } |
| 3527 | if (PyObject_HasAttrString(obj, "body")) { |
| 3528 | int res; |
| 3529 | Py_ssize_t len; |
| 3530 | Py_ssize_t i; |
| 3531 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3532 | if (tmp == NULL) goto failed; |
| 3533 | if (!PyList_Check(tmp)) { |
| 3534 | PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3535 | goto failed; |
| 3536 | } |
| 3537 | len = PyList_GET_SIZE(tmp); |
| 3538 | body = asdl_seq_new(len, arena); |
| 3539 | if (body == NULL) goto failed; |
| 3540 | for (i = 0; i < len; i++) { |
| 3541 | stmt_ty value; |
| 3542 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3543 | if (res != 0) goto failed; |
| 3544 | asdl_seq_SET(body, i, value); |
| 3545 | } |
| 3546 | Py_XDECREF(tmp); |
| 3547 | tmp = NULL; |
| 3548 | } else { |
| 3549 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 3550 | return 1; |
| 3551 | } |
| 3552 | if (PyObject_HasAttrString(obj, "decorator_list")) { |
| 3553 | int res; |
| 3554 | Py_ssize_t len; |
| 3555 | Py_ssize_t i; |
| 3556 | tmp = PyObject_GetAttrString(obj, "decorator_list"); |
| 3557 | if (tmp == NULL) goto failed; |
| 3558 | if (!PyList_Check(tmp)) { |
| 3559 | PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3560 | goto failed; |
| 3561 | } |
| 3562 | len = PyList_GET_SIZE(tmp); |
| 3563 | decorator_list = asdl_seq_new(len, arena); |
| 3564 | if (decorator_list == NULL) goto failed; |
| 3565 | for (i = 0; i < len; i++) { |
| 3566 | expr_ty value; |
| 3567 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3568 | if (res != 0) goto failed; |
| 3569 | asdl_seq_SET(decorator_list, i, value); |
| 3570 | } |
| 3571 | Py_XDECREF(tmp); |
| 3572 | tmp = NULL; |
| 3573 | } else { |
| 3574 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 3575 | return 1; |
| 3576 | } |
| 3577 | *out = ClassDef(name, bases, body, decorator_list, lineno, |
| 3578 | col_offset, arena); |
| 3579 | if (*out == NULL) goto failed; |
| 3580 | return 0; |
| 3581 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 3582 | isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type); |
| 3583 | if (isinstance == -1) { |
| 3584 | return 1; |
| 3585 | } |
| 3586 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3587 | expr_ty value; |
| 3588 | |
| 3589 | if (PyObject_HasAttrString(obj, "value")) { |
| 3590 | int res; |
| 3591 | tmp = PyObject_GetAttrString(obj, "value"); |
| 3592 | if (tmp == NULL) goto failed; |
| 3593 | res = obj2ast_expr(tmp, &value, arena); |
| 3594 | if (res != 0) goto failed; |
| 3595 | Py_XDECREF(tmp); |
| 3596 | tmp = NULL; |
| 3597 | } else { |
| 3598 | value = NULL; |
| 3599 | } |
| 3600 | *out = Return(value, lineno, col_offset, arena); |
| 3601 | if (*out == NULL) goto failed; |
| 3602 | return 0; |
| 3603 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 3604 | isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type); |
| 3605 | if (isinstance == -1) { |
| 3606 | return 1; |
| 3607 | } |
| 3608 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3609 | asdl_seq* targets; |
| 3610 | |
| 3611 | if (PyObject_HasAttrString(obj, "targets")) { |
| 3612 | int res; |
| 3613 | Py_ssize_t len; |
| 3614 | Py_ssize_t i; |
| 3615 | tmp = PyObject_GetAttrString(obj, "targets"); |
| 3616 | if (tmp == NULL) goto failed; |
| 3617 | if (!PyList_Check(tmp)) { |
| 3618 | PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3619 | goto failed; |
| 3620 | } |
| 3621 | len = PyList_GET_SIZE(tmp); |
| 3622 | targets = asdl_seq_new(len, arena); |
| 3623 | if (targets == NULL) goto failed; |
| 3624 | for (i = 0; i < len; i++) { |
| 3625 | expr_ty value; |
| 3626 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3627 | if (res != 0) goto failed; |
| 3628 | asdl_seq_SET(targets, i, value); |
| 3629 | } |
| 3630 | Py_XDECREF(tmp); |
| 3631 | tmp = NULL; |
| 3632 | } else { |
| 3633 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 3634 | return 1; |
| 3635 | } |
| 3636 | *out = Delete(targets, lineno, col_offset, arena); |
| 3637 | if (*out == NULL) goto failed; |
| 3638 | return 0; |
| 3639 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 3640 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type); |
| 3641 | if (isinstance == -1) { |
| 3642 | return 1; |
| 3643 | } |
| 3644 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3645 | asdl_seq* targets; |
| 3646 | expr_ty value; |
| 3647 | |
| 3648 | if (PyObject_HasAttrString(obj, "targets")) { |
| 3649 | int res; |
| 3650 | Py_ssize_t len; |
| 3651 | Py_ssize_t i; |
| 3652 | tmp = PyObject_GetAttrString(obj, "targets"); |
| 3653 | if (tmp == NULL) goto failed; |
| 3654 | if (!PyList_Check(tmp)) { |
| 3655 | PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3656 | goto failed; |
| 3657 | } |
| 3658 | len = PyList_GET_SIZE(tmp); |
| 3659 | targets = asdl_seq_new(len, arena); |
| 3660 | if (targets == NULL) goto failed; |
| 3661 | for (i = 0; i < len; i++) { |
| 3662 | expr_ty value; |
| 3663 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3664 | if (res != 0) goto failed; |
| 3665 | asdl_seq_SET(targets, i, value); |
| 3666 | } |
| 3667 | Py_XDECREF(tmp); |
| 3668 | tmp = NULL; |
| 3669 | } else { |
| 3670 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 3671 | return 1; |
| 3672 | } |
| 3673 | if (PyObject_HasAttrString(obj, "value")) { |
| 3674 | int res; |
| 3675 | tmp = PyObject_GetAttrString(obj, "value"); |
| 3676 | if (tmp == NULL) goto failed; |
| 3677 | res = obj2ast_expr(tmp, &value, arena); |
| 3678 | if (res != 0) goto failed; |
| 3679 | Py_XDECREF(tmp); |
| 3680 | tmp = NULL; |
| 3681 | } else { |
| 3682 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 3683 | return 1; |
| 3684 | } |
| 3685 | *out = Assign(targets, value, lineno, col_offset, arena); |
| 3686 | if (*out == NULL) goto failed; |
| 3687 | return 0; |
| 3688 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 3689 | isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type); |
| 3690 | if (isinstance == -1) { |
| 3691 | return 1; |
| 3692 | } |
| 3693 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3694 | expr_ty target; |
| 3695 | operator_ty op; |
| 3696 | expr_ty value; |
| 3697 | |
| 3698 | if (PyObject_HasAttrString(obj, "target")) { |
| 3699 | int res; |
| 3700 | tmp = PyObject_GetAttrString(obj, "target"); |
| 3701 | if (tmp == NULL) goto failed; |
| 3702 | res = obj2ast_expr(tmp, &target, arena); |
| 3703 | if (res != 0) goto failed; |
| 3704 | Py_XDECREF(tmp); |
| 3705 | tmp = NULL; |
| 3706 | } else { |
| 3707 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 3708 | return 1; |
| 3709 | } |
| 3710 | if (PyObject_HasAttrString(obj, "op")) { |
| 3711 | int res; |
| 3712 | tmp = PyObject_GetAttrString(obj, "op"); |
| 3713 | if (tmp == NULL) goto failed; |
| 3714 | res = obj2ast_operator(tmp, &op, arena); |
| 3715 | if (res != 0) goto failed; |
| 3716 | Py_XDECREF(tmp); |
| 3717 | tmp = NULL; |
| 3718 | } else { |
| 3719 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 3720 | return 1; |
| 3721 | } |
| 3722 | if (PyObject_HasAttrString(obj, "value")) { |
| 3723 | int res; |
| 3724 | tmp = PyObject_GetAttrString(obj, "value"); |
| 3725 | if (tmp == NULL) goto failed; |
| 3726 | res = obj2ast_expr(tmp, &value, arena); |
| 3727 | if (res != 0) goto failed; |
| 3728 | Py_XDECREF(tmp); |
| 3729 | tmp = NULL; |
| 3730 | } else { |
| 3731 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 3732 | return 1; |
| 3733 | } |
| 3734 | *out = AugAssign(target, op, value, lineno, col_offset, arena); |
| 3735 | if (*out == NULL) goto failed; |
| 3736 | return 0; |
| 3737 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 3738 | isinstance = PyObject_IsInstance(obj, (PyObject*)Print_type); |
| 3739 | if (isinstance == -1) { |
| 3740 | return 1; |
| 3741 | } |
| 3742 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3743 | expr_ty dest; |
| 3744 | asdl_seq* values; |
| 3745 | bool nl; |
| 3746 | |
| 3747 | if (PyObject_HasAttrString(obj, "dest")) { |
| 3748 | int res; |
| 3749 | tmp = PyObject_GetAttrString(obj, "dest"); |
| 3750 | if (tmp == NULL) goto failed; |
| 3751 | res = obj2ast_expr(tmp, &dest, arena); |
| 3752 | if (res != 0) goto failed; |
| 3753 | Py_XDECREF(tmp); |
| 3754 | tmp = NULL; |
| 3755 | } else { |
| 3756 | dest = NULL; |
| 3757 | } |
| 3758 | if (PyObject_HasAttrString(obj, "values")) { |
| 3759 | int res; |
| 3760 | Py_ssize_t len; |
| 3761 | Py_ssize_t i; |
| 3762 | tmp = PyObject_GetAttrString(obj, "values"); |
| 3763 | if (tmp == NULL) goto failed; |
| 3764 | if (!PyList_Check(tmp)) { |
| 3765 | PyErr_Format(PyExc_TypeError, "Print field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3766 | goto failed; |
| 3767 | } |
| 3768 | len = PyList_GET_SIZE(tmp); |
| 3769 | values = asdl_seq_new(len, arena); |
| 3770 | if (values == NULL) goto failed; |
| 3771 | for (i = 0; i < len; i++) { |
| 3772 | expr_ty value; |
| 3773 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3774 | if (res != 0) goto failed; |
| 3775 | asdl_seq_SET(values, i, value); |
| 3776 | } |
| 3777 | Py_XDECREF(tmp); |
| 3778 | tmp = NULL; |
| 3779 | } else { |
| 3780 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Print"); |
| 3781 | return 1; |
| 3782 | } |
| 3783 | if (PyObject_HasAttrString(obj, "nl")) { |
| 3784 | int res; |
| 3785 | tmp = PyObject_GetAttrString(obj, "nl"); |
| 3786 | if (tmp == NULL) goto failed; |
| 3787 | res = obj2ast_bool(tmp, &nl, arena); |
| 3788 | if (res != 0) goto failed; |
| 3789 | Py_XDECREF(tmp); |
| 3790 | tmp = NULL; |
| 3791 | } else { |
| 3792 | PyErr_SetString(PyExc_TypeError, "required field \"nl\" missing from Print"); |
| 3793 | return 1; |
| 3794 | } |
| 3795 | *out = Print(dest, values, nl, lineno, col_offset, arena); |
| 3796 | if (*out == NULL) goto failed; |
| 3797 | return 0; |
| 3798 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 3799 | isinstance = PyObject_IsInstance(obj, (PyObject*)For_type); |
| 3800 | if (isinstance == -1) { |
| 3801 | return 1; |
| 3802 | } |
| 3803 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3804 | expr_ty target; |
| 3805 | expr_ty iter; |
| 3806 | asdl_seq* body; |
| 3807 | asdl_seq* orelse; |
| 3808 | |
| 3809 | if (PyObject_HasAttrString(obj, "target")) { |
| 3810 | int res; |
| 3811 | tmp = PyObject_GetAttrString(obj, "target"); |
| 3812 | if (tmp == NULL) goto failed; |
| 3813 | res = obj2ast_expr(tmp, &target, arena); |
| 3814 | if (res != 0) goto failed; |
| 3815 | Py_XDECREF(tmp); |
| 3816 | tmp = NULL; |
| 3817 | } else { |
| 3818 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 3819 | return 1; |
| 3820 | } |
| 3821 | if (PyObject_HasAttrString(obj, "iter")) { |
| 3822 | int res; |
| 3823 | tmp = PyObject_GetAttrString(obj, "iter"); |
| 3824 | if (tmp == NULL) goto failed; |
| 3825 | res = obj2ast_expr(tmp, &iter, arena); |
| 3826 | if (res != 0) goto failed; |
| 3827 | Py_XDECREF(tmp); |
| 3828 | tmp = NULL; |
| 3829 | } else { |
| 3830 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 3831 | return 1; |
| 3832 | } |
| 3833 | if (PyObject_HasAttrString(obj, "body")) { |
| 3834 | int res; |
| 3835 | Py_ssize_t len; |
| 3836 | Py_ssize_t i; |
| 3837 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3838 | if (tmp == NULL) goto failed; |
| 3839 | if (!PyList_Check(tmp)) { |
| 3840 | PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3841 | goto failed; |
| 3842 | } |
| 3843 | len = PyList_GET_SIZE(tmp); |
| 3844 | body = asdl_seq_new(len, arena); |
| 3845 | if (body == NULL) goto failed; |
| 3846 | for (i = 0; i < len; i++) { |
| 3847 | stmt_ty value; |
| 3848 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3849 | if (res != 0) goto failed; |
| 3850 | asdl_seq_SET(body, i, value); |
| 3851 | } |
| 3852 | Py_XDECREF(tmp); |
| 3853 | tmp = NULL; |
| 3854 | } else { |
| 3855 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 3856 | return 1; |
| 3857 | } |
| 3858 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 3859 | int res; |
| 3860 | Py_ssize_t len; |
| 3861 | Py_ssize_t i; |
| 3862 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 3863 | if (tmp == NULL) goto failed; |
| 3864 | if (!PyList_Check(tmp)) { |
| 3865 | PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3866 | goto failed; |
| 3867 | } |
| 3868 | len = PyList_GET_SIZE(tmp); |
| 3869 | orelse = asdl_seq_new(len, arena); |
| 3870 | if (orelse == NULL) goto failed; |
| 3871 | for (i = 0; i < len; i++) { |
| 3872 | stmt_ty value; |
| 3873 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3874 | if (res != 0) goto failed; |
| 3875 | asdl_seq_SET(orelse, i, value); |
| 3876 | } |
| 3877 | Py_XDECREF(tmp); |
| 3878 | tmp = NULL; |
| 3879 | } else { |
| 3880 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 3881 | return 1; |
| 3882 | } |
| 3883 | *out = For(target, iter, body, orelse, lineno, col_offset, |
| 3884 | arena); |
| 3885 | if (*out == NULL) goto failed; |
| 3886 | return 0; |
| 3887 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 3888 | isinstance = PyObject_IsInstance(obj, (PyObject*)While_type); |
| 3889 | if (isinstance == -1) { |
| 3890 | return 1; |
| 3891 | } |
| 3892 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3893 | expr_ty test; |
| 3894 | asdl_seq* body; |
| 3895 | asdl_seq* orelse; |
| 3896 | |
| 3897 | if (PyObject_HasAttrString(obj, "test")) { |
| 3898 | int res; |
| 3899 | tmp = PyObject_GetAttrString(obj, "test"); |
| 3900 | if (tmp == NULL) goto failed; |
| 3901 | res = obj2ast_expr(tmp, &test, arena); |
| 3902 | if (res != 0) goto failed; |
| 3903 | Py_XDECREF(tmp); |
| 3904 | tmp = NULL; |
| 3905 | } else { |
| 3906 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 3907 | return 1; |
| 3908 | } |
| 3909 | if (PyObject_HasAttrString(obj, "body")) { |
| 3910 | int res; |
| 3911 | Py_ssize_t len; |
| 3912 | Py_ssize_t i; |
| 3913 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3914 | if (tmp == NULL) goto failed; |
| 3915 | if (!PyList_Check(tmp)) { |
| 3916 | PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3917 | goto failed; |
| 3918 | } |
| 3919 | len = PyList_GET_SIZE(tmp); |
| 3920 | body = asdl_seq_new(len, arena); |
| 3921 | if (body == NULL) goto failed; |
| 3922 | for (i = 0; i < len; i++) { |
| 3923 | stmt_ty value; |
| 3924 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3925 | if (res != 0) goto failed; |
| 3926 | asdl_seq_SET(body, i, value); |
| 3927 | } |
| 3928 | Py_XDECREF(tmp); |
| 3929 | tmp = NULL; |
| 3930 | } else { |
| 3931 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 3932 | return 1; |
| 3933 | } |
| 3934 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 3935 | int res; |
| 3936 | Py_ssize_t len; |
| 3937 | Py_ssize_t i; |
| 3938 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 3939 | if (tmp == NULL) goto failed; |
| 3940 | if (!PyList_Check(tmp)) { |
| 3941 | PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3942 | goto failed; |
| 3943 | } |
| 3944 | len = PyList_GET_SIZE(tmp); |
| 3945 | orelse = asdl_seq_new(len, arena); |
| 3946 | if (orelse == NULL) goto failed; |
| 3947 | for (i = 0; i < len; i++) { |
| 3948 | stmt_ty value; |
| 3949 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3950 | if (res != 0) goto failed; |
| 3951 | asdl_seq_SET(orelse, i, value); |
| 3952 | } |
| 3953 | Py_XDECREF(tmp); |
| 3954 | tmp = NULL; |
| 3955 | } else { |
| 3956 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 3957 | return 1; |
| 3958 | } |
| 3959 | *out = While(test, body, orelse, lineno, col_offset, arena); |
| 3960 | if (*out == NULL) goto failed; |
| 3961 | return 0; |
| 3962 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 3963 | isinstance = PyObject_IsInstance(obj, (PyObject*)If_type); |
| 3964 | if (isinstance == -1) { |
| 3965 | return 1; |
| 3966 | } |
| 3967 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 3968 | expr_ty test; |
| 3969 | asdl_seq* body; |
| 3970 | asdl_seq* orelse; |
| 3971 | |
| 3972 | if (PyObject_HasAttrString(obj, "test")) { |
| 3973 | int res; |
| 3974 | tmp = PyObject_GetAttrString(obj, "test"); |
| 3975 | if (tmp == NULL) goto failed; |
| 3976 | res = obj2ast_expr(tmp, &test, arena); |
| 3977 | if (res != 0) goto failed; |
| 3978 | Py_XDECREF(tmp); |
| 3979 | tmp = NULL; |
| 3980 | } else { |
| 3981 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 3982 | return 1; |
| 3983 | } |
| 3984 | if (PyObject_HasAttrString(obj, "body")) { |
| 3985 | int res; |
| 3986 | Py_ssize_t len; |
| 3987 | Py_ssize_t i; |
| 3988 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3989 | if (tmp == NULL) goto failed; |
| 3990 | if (!PyList_Check(tmp)) { |
| 3991 | PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3992 | goto failed; |
| 3993 | } |
| 3994 | len = PyList_GET_SIZE(tmp); |
| 3995 | body = asdl_seq_new(len, arena); |
| 3996 | if (body == NULL) goto failed; |
| 3997 | for (i = 0; i < len; i++) { |
| 3998 | stmt_ty value; |
| 3999 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4000 | if (res != 0) goto failed; |
| 4001 | asdl_seq_SET(body, i, value); |
| 4002 | } |
| 4003 | Py_XDECREF(tmp); |
| 4004 | tmp = NULL; |
| 4005 | } else { |
| 4006 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 4007 | return 1; |
| 4008 | } |
| 4009 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4010 | int res; |
| 4011 | Py_ssize_t len; |
| 4012 | Py_ssize_t i; |
| 4013 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4014 | if (tmp == NULL) goto failed; |
| 4015 | if (!PyList_Check(tmp)) { |
| 4016 | PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4017 | goto failed; |
| 4018 | } |
| 4019 | len = PyList_GET_SIZE(tmp); |
| 4020 | orelse = asdl_seq_new(len, arena); |
| 4021 | if (orelse == NULL) goto failed; |
| 4022 | for (i = 0; i < len; i++) { |
| 4023 | stmt_ty value; |
| 4024 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4025 | if (res != 0) goto failed; |
| 4026 | asdl_seq_SET(orelse, i, value); |
| 4027 | } |
| 4028 | Py_XDECREF(tmp); |
| 4029 | tmp = NULL; |
| 4030 | } else { |
| 4031 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 4032 | return 1; |
| 4033 | } |
| 4034 | *out = If(test, body, orelse, lineno, col_offset, arena); |
| 4035 | if (*out == NULL) goto failed; |
| 4036 | return 0; |
| 4037 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 4038 | isinstance = PyObject_IsInstance(obj, (PyObject*)With_type); |
| 4039 | if (isinstance == -1) { |
| 4040 | return 1; |
| 4041 | } |
| 4042 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4043 | expr_ty context_expr; |
| 4044 | expr_ty optional_vars; |
| 4045 | asdl_seq* body; |
| 4046 | |
| 4047 | if (PyObject_HasAttrString(obj, "context_expr")) { |
| 4048 | int res; |
| 4049 | tmp = PyObject_GetAttrString(obj, "context_expr"); |
| 4050 | if (tmp == NULL) goto failed; |
| 4051 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 4052 | if (res != 0) goto failed; |
| 4053 | Py_XDECREF(tmp); |
| 4054 | tmp = NULL; |
| 4055 | } else { |
| 4056 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from With"); |
| 4057 | return 1; |
| 4058 | } |
| 4059 | if (PyObject_HasAttrString(obj, "optional_vars")) { |
| 4060 | int res; |
| 4061 | tmp = PyObject_GetAttrString(obj, "optional_vars"); |
| 4062 | if (tmp == NULL) goto failed; |
| 4063 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 4064 | if (res != 0) goto failed; |
| 4065 | Py_XDECREF(tmp); |
| 4066 | tmp = NULL; |
| 4067 | } else { |
| 4068 | optional_vars = NULL; |
| 4069 | } |
| 4070 | if (PyObject_HasAttrString(obj, "body")) { |
| 4071 | int res; |
| 4072 | Py_ssize_t len; |
| 4073 | Py_ssize_t i; |
| 4074 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4075 | if (tmp == NULL) goto failed; |
| 4076 | if (!PyList_Check(tmp)) { |
| 4077 | PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4078 | goto failed; |
| 4079 | } |
| 4080 | len = PyList_GET_SIZE(tmp); |
| 4081 | body = asdl_seq_new(len, arena); |
| 4082 | if (body == NULL) goto failed; |
| 4083 | for (i = 0; i < len; i++) { |
| 4084 | stmt_ty value; |
| 4085 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4086 | if (res != 0) goto failed; |
| 4087 | asdl_seq_SET(body, i, value); |
| 4088 | } |
| 4089 | Py_XDECREF(tmp); |
| 4090 | tmp = NULL; |
| 4091 | } else { |
| 4092 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 4093 | return 1; |
| 4094 | } |
| 4095 | *out = With(context_expr, optional_vars, body, lineno, |
| 4096 | col_offset, arena); |
| 4097 | if (*out == NULL) goto failed; |
| 4098 | return 0; |
| 4099 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 4100 | isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type); |
| 4101 | if (isinstance == -1) { |
| 4102 | return 1; |
| 4103 | } |
| 4104 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4105 | expr_ty type; |
| 4106 | expr_ty inst; |
| 4107 | expr_ty tback; |
| 4108 | |
| 4109 | if (PyObject_HasAttrString(obj, "type")) { |
| 4110 | int res; |
| 4111 | tmp = PyObject_GetAttrString(obj, "type"); |
| 4112 | if (tmp == NULL) goto failed; |
| 4113 | res = obj2ast_expr(tmp, &type, arena); |
| 4114 | if (res != 0) goto failed; |
| 4115 | Py_XDECREF(tmp); |
| 4116 | tmp = NULL; |
| 4117 | } else { |
| 4118 | type = NULL; |
| 4119 | } |
| 4120 | if (PyObject_HasAttrString(obj, "inst")) { |
| 4121 | int res; |
| 4122 | tmp = PyObject_GetAttrString(obj, "inst"); |
| 4123 | if (tmp == NULL) goto failed; |
| 4124 | res = obj2ast_expr(tmp, &inst, arena); |
| 4125 | if (res != 0) goto failed; |
| 4126 | Py_XDECREF(tmp); |
| 4127 | tmp = NULL; |
| 4128 | } else { |
| 4129 | inst = NULL; |
| 4130 | } |
| 4131 | if (PyObject_HasAttrString(obj, "tback")) { |
| 4132 | int res; |
| 4133 | tmp = PyObject_GetAttrString(obj, "tback"); |
| 4134 | if (tmp == NULL) goto failed; |
| 4135 | res = obj2ast_expr(tmp, &tback, arena); |
| 4136 | if (res != 0) goto failed; |
| 4137 | Py_XDECREF(tmp); |
| 4138 | tmp = NULL; |
| 4139 | } else { |
| 4140 | tback = NULL; |
| 4141 | } |
| 4142 | *out = Raise(type, inst, tback, lineno, col_offset, arena); |
| 4143 | if (*out == NULL) goto failed; |
| 4144 | return 0; |
| 4145 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 4146 | isinstance = PyObject_IsInstance(obj, (PyObject*)TryExcept_type); |
| 4147 | if (isinstance == -1) { |
| 4148 | return 1; |
| 4149 | } |
| 4150 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4151 | asdl_seq* body; |
| 4152 | asdl_seq* handlers; |
| 4153 | asdl_seq* orelse; |
| 4154 | |
| 4155 | if (PyObject_HasAttrString(obj, "body")) { |
| 4156 | int res; |
| 4157 | Py_ssize_t len; |
| 4158 | Py_ssize_t i; |
| 4159 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4160 | if (tmp == NULL) goto failed; |
| 4161 | if (!PyList_Check(tmp)) { |
| 4162 | PyErr_Format(PyExc_TypeError, "TryExcept field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4163 | goto failed; |
| 4164 | } |
| 4165 | len = PyList_GET_SIZE(tmp); |
| 4166 | body = asdl_seq_new(len, arena); |
| 4167 | if (body == NULL) goto failed; |
| 4168 | for (i = 0; i < len; i++) { |
| 4169 | stmt_ty value; |
| 4170 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4171 | if (res != 0) goto failed; |
| 4172 | asdl_seq_SET(body, i, value); |
| 4173 | } |
| 4174 | Py_XDECREF(tmp); |
| 4175 | tmp = NULL; |
| 4176 | } else { |
| 4177 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryExcept"); |
| 4178 | return 1; |
| 4179 | } |
| 4180 | if (PyObject_HasAttrString(obj, "handlers")) { |
| 4181 | int res; |
| 4182 | Py_ssize_t len; |
| 4183 | Py_ssize_t i; |
| 4184 | tmp = PyObject_GetAttrString(obj, "handlers"); |
| 4185 | if (tmp == NULL) goto failed; |
| 4186 | if (!PyList_Check(tmp)) { |
| 4187 | PyErr_Format(PyExc_TypeError, "TryExcept field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4188 | goto failed; |
| 4189 | } |
| 4190 | len = PyList_GET_SIZE(tmp); |
| 4191 | handlers = asdl_seq_new(len, arena); |
| 4192 | if (handlers == NULL) goto failed; |
| 4193 | for (i = 0; i < len; i++) { |
| 4194 | excepthandler_ty value; |
| 4195 | res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4196 | if (res != 0) goto failed; |
| 4197 | asdl_seq_SET(handlers, i, value); |
| 4198 | } |
| 4199 | Py_XDECREF(tmp); |
| 4200 | tmp = NULL; |
| 4201 | } else { |
| 4202 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from TryExcept"); |
| 4203 | return 1; |
| 4204 | } |
| 4205 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4206 | int res; |
| 4207 | Py_ssize_t len; |
| 4208 | Py_ssize_t i; |
| 4209 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4210 | if (tmp == NULL) goto failed; |
| 4211 | if (!PyList_Check(tmp)) { |
| 4212 | PyErr_Format(PyExc_TypeError, "TryExcept field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4213 | goto failed; |
| 4214 | } |
| 4215 | len = PyList_GET_SIZE(tmp); |
| 4216 | orelse = asdl_seq_new(len, arena); |
| 4217 | if (orelse == NULL) goto failed; |
| 4218 | for (i = 0; i < len; i++) { |
| 4219 | stmt_ty value; |
| 4220 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4221 | if (res != 0) goto failed; |
| 4222 | asdl_seq_SET(orelse, i, value); |
| 4223 | } |
| 4224 | Py_XDECREF(tmp); |
| 4225 | tmp = NULL; |
| 4226 | } else { |
| 4227 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from TryExcept"); |
| 4228 | return 1; |
| 4229 | } |
| 4230 | *out = TryExcept(body, handlers, orelse, lineno, col_offset, |
| 4231 | arena); |
| 4232 | if (*out == NULL) goto failed; |
| 4233 | return 0; |
| 4234 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 4235 | isinstance = PyObject_IsInstance(obj, (PyObject*)TryFinally_type); |
| 4236 | if (isinstance == -1) { |
| 4237 | return 1; |
| 4238 | } |
| 4239 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4240 | asdl_seq* body; |
| 4241 | asdl_seq* finalbody; |
| 4242 | |
| 4243 | if (PyObject_HasAttrString(obj, "body")) { |
| 4244 | int res; |
| 4245 | Py_ssize_t len; |
| 4246 | Py_ssize_t i; |
| 4247 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4248 | if (tmp == NULL) goto failed; |
| 4249 | if (!PyList_Check(tmp)) { |
| 4250 | PyErr_Format(PyExc_TypeError, "TryFinally field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4251 | goto failed; |
| 4252 | } |
| 4253 | len = PyList_GET_SIZE(tmp); |
| 4254 | body = asdl_seq_new(len, arena); |
| 4255 | if (body == NULL) goto failed; |
| 4256 | for (i = 0; i < len; i++) { |
| 4257 | stmt_ty value; |
| 4258 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4259 | if (res != 0) goto failed; |
| 4260 | asdl_seq_SET(body, i, value); |
| 4261 | } |
| 4262 | Py_XDECREF(tmp); |
| 4263 | tmp = NULL; |
| 4264 | } else { |
| 4265 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryFinally"); |
| 4266 | return 1; |
| 4267 | } |
| 4268 | if (PyObject_HasAttrString(obj, "finalbody")) { |
| 4269 | int res; |
| 4270 | Py_ssize_t len; |
| 4271 | Py_ssize_t i; |
| 4272 | tmp = PyObject_GetAttrString(obj, "finalbody"); |
| 4273 | if (tmp == NULL) goto failed; |
| 4274 | if (!PyList_Check(tmp)) { |
| 4275 | PyErr_Format(PyExc_TypeError, "TryFinally field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4276 | goto failed; |
| 4277 | } |
| 4278 | len = PyList_GET_SIZE(tmp); |
| 4279 | finalbody = asdl_seq_new(len, arena); |
| 4280 | if (finalbody == NULL) goto failed; |
| 4281 | for (i = 0; i < len; i++) { |
| 4282 | stmt_ty value; |
| 4283 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4284 | if (res != 0) goto failed; |
| 4285 | asdl_seq_SET(finalbody, i, value); |
| 4286 | } |
| 4287 | Py_XDECREF(tmp); |
| 4288 | tmp = NULL; |
| 4289 | } else { |
| 4290 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from TryFinally"); |
| 4291 | return 1; |
| 4292 | } |
| 4293 | *out = TryFinally(body, finalbody, lineno, col_offset, arena); |
| 4294 | if (*out == NULL) goto failed; |
| 4295 | return 0; |
| 4296 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 4297 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type); |
| 4298 | if (isinstance == -1) { |
| 4299 | return 1; |
| 4300 | } |
| 4301 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4302 | expr_ty test; |
| 4303 | expr_ty msg; |
| 4304 | |
| 4305 | if (PyObject_HasAttrString(obj, "test")) { |
| 4306 | int res; |
| 4307 | tmp = PyObject_GetAttrString(obj, "test"); |
| 4308 | if (tmp == NULL) goto failed; |
| 4309 | res = obj2ast_expr(tmp, &test, arena); |
| 4310 | if (res != 0) goto failed; |
| 4311 | Py_XDECREF(tmp); |
| 4312 | tmp = NULL; |
| 4313 | } else { |
| 4314 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 4315 | return 1; |
| 4316 | } |
| 4317 | if (PyObject_HasAttrString(obj, "msg")) { |
| 4318 | int res; |
| 4319 | tmp = PyObject_GetAttrString(obj, "msg"); |
| 4320 | if (tmp == NULL) goto failed; |
| 4321 | res = obj2ast_expr(tmp, &msg, arena); |
| 4322 | if (res != 0) goto failed; |
| 4323 | Py_XDECREF(tmp); |
| 4324 | tmp = NULL; |
| 4325 | } else { |
| 4326 | msg = NULL; |
| 4327 | } |
| 4328 | *out = Assert(test, msg, lineno, col_offset, arena); |
| 4329 | if (*out == NULL) goto failed; |
| 4330 | return 0; |
| 4331 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 4332 | isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type); |
| 4333 | if (isinstance == -1) { |
| 4334 | return 1; |
| 4335 | } |
| 4336 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4337 | asdl_seq* names; |
| 4338 | |
| 4339 | if (PyObject_HasAttrString(obj, "names")) { |
| 4340 | int res; |
| 4341 | Py_ssize_t len; |
| 4342 | Py_ssize_t i; |
| 4343 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4344 | if (tmp == NULL) goto failed; |
| 4345 | if (!PyList_Check(tmp)) { |
| 4346 | PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4347 | goto failed; |
| 4348 | } |
| 4349 | len = PyList_GET_SIZE(tmp); |
| 4350 | names = asdl_seq_new(len, arena); |
| 4351 | if (names == NULL) goto failed; |
| 4352 | for (i = 0; i < len; i++) { |
| 4353 | alias_ty value; |
| 4354 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4355 | if (res != 0) goto failed; |
| 4356 | asdl_seq_SET(names, i, value); |
| 4357 | } |
| 4358 | Py_XDECREF(tmp); |
| 4359 | tmp = NULL; |
| 4360 | } else { |
| 4361 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 4362 | return 1; |
| 4363 | } |
| 4364 | *out = Import(names, lineno, col_offset, arena); |
| 4365 | if (*out == NULL) goto failed; |
| 4366 | return 0; |
| 4367 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 4368 | isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type); |
| 4369 | if (isinstance == -1) { |
| 4370 | return 1; |
| 4371 | } |
| 4372 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4373 | identifier module; |
| 4374 | asdl_seq* names; |
| 4375 | int level; |
| 4376 | |
| 4377 | if (PyObject_HasAttrString(obj, "module")) { |
| 4378 | int res; |
| 4379 | tmp = PyObject_GetAttrString(obj, "module"); |
| 4380 | if (tmp == NULL) goto failed; |
| 4381 | res = obj2ast_identifier(tmp, &module, arena); |
| 4382 | if (res != 0) goto failed; |
| 4383 | Py_XDECREF(tmp); |
| 4384 | tmp = NULL; |
| 4385 | } else { |
Benjamin Peterson | a72be3b | 2009-06-13 20:23:33 +0000 | [diff] [blame] | 4386 | module = NULL; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4387 | } |
| 4388 | if (PyObject_HasAttrString(obj, "names")) { |
| 4389 | int res; |
| 4390 | Py_ssize_t len; |
| 4391 | Py_ssize_t i; |
| 4392 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4393 | if (tmp == NULL) goto failed; |
| 4394 | if (!PyList_Check(tmp)) { |
| 4395 | PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4396 | goto failed; |
| 4397 | } |
| 4398 | len = PyList_GET_SIZE(tmp); |
| 4399 | names = asdl_seq_new(len, arena); |
| 4400 | if (names == NULL) goto failed; |
| 4401 | for (i = 0; i < len; i++) { |
| 4402 | alias_ty value; |
| 4403 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4404 | if (res != 0) goto failed; |
| 4405 | asdl_seq_SET(names, i, value); |
| 4406 | } |
| 4407 | Py_XDECREF(tmp); |
| 4408 | tmp = NULL; |
| 4409 | } else { |
| 4410 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 4411 | return 1; |
| 4412 | } |
| 4413 | if (PyObject_HasAttrString(obj, "level")) { |
| 4414 | int res; |
| 4415 | tmp = PyObject_GetAttrString(obj, "level"); |
| 4416 | if (tmp == NULL) goto failed; |
| 4417 | res = obj2ast_int(tmp, &level, arena); |
| 4418 | if (res != 0) goto failed; |
| 4419 | Py_XDECREF(tmp); |
| 4420 | tmp = NULL; |
| 4421 | } else { |
| 4422 | level = 0; |
| 4423 | } |
| 4424 | *out = ImportFrom(module, names, level, lineno, col_offset, |
| 4425 | arena); |
| 4426 | if (*out == NULL) goto failed; |
| 4427 | return 0; |
| 4428 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 4429 | isinstance = PyObject_IsInstance(obj, (PyObject*)Exec_type); |
| 4430 | if (isinstance == -1) { |
| 4431 | return 1; |
| 4432 | } |
| 4433 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4434 | expr_ty body; |
| 4435 | expr_ty globals; |
| 4436 | expr_ty locals; |
| 4437 | |
| 4438 | if (PyObject_HasAttrString(obj, "body")) { |
| 4439 | int res; |
| 4440 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4441 | if (tmp == NULL) goto failed; |
| 4442 | res = obj2ast_expr(tmp, &body, arena); |
| 4443 | if (res != 0) goto failed; |
| 4444 | Py_XDECREF(tmp); |
| 4445 | tmp = NULL; |
| 4446 | } else { |
| 4447 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Exec"); |
| 4448 | return 1; |
| 4449 | } |
| 4450 | if (PyObject_HasAttrString(obj, "globals")) { |
| 4451 | int res; |
| 4452 | tmp = PyObject_GetAttrString(obj, "globals"); |
| 4453 | if (tmp == NULL) goto failed; |
| 4454 | res = obj2ast_expr(tmp, &globals, arena); |
| 4455 | if (res != 0) goto failed; |
| 4456 | Py_XDECREF(tmp); |
| 4457 | tmp = NULL; |
| 4458 | } else { |
| 4459 | globals = NULL; |
| 4460 | } |
| 4461 | if (PyObject_HasAttrString(obj, "locals")) { |
| 4462 | int res; |
| 4463 | tmp = PyObject_GetAttrString(obj, "locals"); |
| 4464 | if (tmp == NULL) goto failed; |
| 4465 | res = obj2ast_expr(tmp, &locals, arena); |
| 4466 | if (res != 0) goto failed; |
| 4467 | Py_XDECREF(tmp); |
| 4468 | tmp = NULL; |
| 4469 | } else { |
| 4470 | locals = NULL; |
| 4471 | } |
| 4472 | *out = Exec(body, globals, locals, lineno, col_offset, arena); |
| 4473 | if (*out == NULL) goto failed; |
| 4474 | return 0; |
| 4475 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 4476 | isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type); |
| 4477 | if (isinstance == -1) { |
| 4478 | return 1; |
| 4479 | } |
| 4480 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4481 | asdl_seq* names; |
| 4482 | |
| 4483 | if (PyObject_HasAttrString(obj, "names")) { |
| 4484 | int res; |
| 4485 | Py_ssize_t len; |
| 4486 | Py_ssize_t i; |
| 4487 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4488 | if (tmp == NULL) goto failed; |
| 4489 | if (!PyList_Check(tmp)) { |
| 4490 | PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4491 | goto failed; |
| 4492 | } |
| 4493 | len = PyList_GET_SIZE(tmp); |
| 4494 | names = asdl_seq_new(len, arena); |
| 4495 | if (names == NULL) goto failed; |
| 4496 | for (i = 0; i < len; i++) { |
| 4497 | identifier value; |
| 4498 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4499 | if (res != 0) goto failed; |
| 4500 | asdl_seq_SET(names, i, value); |
| 4501 | } |
| 4502 | Py_XDECREF(tmp); |
| 4503 | tmp = NULL; |
| 4504 | } else { |
| 4505 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 4506 | return 1; |
| 4507 | } |
| 4508 | *out = Global(names, lineno, col_offset, arena); |
| 4509 | if (*out == NULL) goto failed; |
| 4510 | return 0; |
| 4511 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 4512 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type); |
| 4513 | if (isinstance == -1) { |
| 4514 | return 1; |
| 4515 | } |
| 4516 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4517 | expr_ty value; |
| 4518 | |
| 4519 | if (PyObject_HasAttrString(obj, "value")) { |
| 4520 | int res; |
| 4521 | tmp = PyObject_GetAttrString(obj, "value"); |
| 4522 | if (tmp == NULL) goto failed; |
| 4523 | res = obj2ast_expr(tmp, &value, arena); |
| 4524 | if (res != 0) goto failed; |
| 4525 | Py_XDECREF(tmp); |
| 4526 | tmp = NULL; |
| 4527 | } else { |
| 4528 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 4529 | return 1; |
| 4530 | } |
| 4531 | *out = Expr(value, lineno, col_offset, arena); |
| 4532 | if (*out == NULL) goto failed; |
| 4533 | return 0; |
| 4534 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 4535 | isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type); |
| 4536 | if (isinstance == -1) { |
| 4537 | return 1; |
| 4538 | } |
| 4539 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4540 | |
| 4541 | *out = Pass(lineno, col_offset, arena); |
| 4542 | if (*out == NULL) goto failed; |
| 4543 | return 0; |
| 4544 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 4545 | isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type); |
| 4546 | if (isinstance == -1) { |
| 4547 | return 1; |
| 4548 | } |
| 4549 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4550 | |
| 4551 | *out = Break(lineno, col_offset, arena); |
| 4552 | if (*out == NULL) goto failed; |
| 4553 | return 0; |
| 4554 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 4555 | isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type); |
| 4556 | if (isinstance == -1) { |
| 4557 | return 1; |
| 4558 | } |
| 4559 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4560 | |
| 4561 | *out = Continue(lineno, col_offset, arena); |
| 4562 | if (*out == NULL) goto failed; |
| 4563 | return 0; |
| 4564 | } |
| 4565 | |
| 4566 | tmp = PyObject_Repr(obj); |
| 4567 | if (tmp == NULL) goto failed; |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 4568 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %.400s", PyString_AS_STRING(tmp)); |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4569 | failed: |
| 4570 | Py_XDECREF(tmp); |
| 4571 | return 1; |
| 4572 | } |
| 4573 | |
| 4574 | int |
| 4575 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 4576 | { |
| 4577 | PyObject* tmp = NULL; |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 4578 | int isinstance; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4579 | |
| 4580 | int lineno; |
| 4581 | int col_offset; |
| 4582 | |
| 4583 | if (obj == Py_None) { |
| 4584 | *out = NULL; |
| 4585 | return 0; |
| 4586 | } |
| 4587 | if (PyObject_HasAttrString(obj, "lineno")) { |
| 4588 | int res; |
| 4589 | tmp = PyObject_GetAttrString(obj, "lineno"); |
| 4590 | if (tmp == NULL) goto failed; |
| 4591 | res = obj2ast_int(tmp, &lineno, arena); |
| 4592 | if (res != 0) goto failed; |
| 4593 | Py_XDECREF(tmp); |
| 4594 | tmp = NULL; |
| 4595 | } else { |
| 4596 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 4597 | return 1; |
| 4598 | } |
| 4599 | if (PyObject_HasAttrString(obj, "col_offset")) { |
| 4600 | int res; |
| 4601 | tmp = PyObject_GetAttrString(obj, "col_offset"); |
| 4602 | if (tmp == NULL) goto failed; |
| 4603 | res = obj2ast_int(tmp, &col_offset, arena); |
| 4604 | if (res != 0) goto failed; |
| 4605 | Py_XDECREF(tmp); |
| 4606 | tmp = NULL; |
| 4607 | } else { |
| 4608 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 4609 | return 1; |
| 4610 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 4611 | isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type); |
| 4612 | if (isinstance == -1) { |
| 4613 | return 1; |
| 4614 | } |
| 4615 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4616 | boolop_ty op; |
| 4617 | asdl_seq* values; |
| 4618 | |
| 4619 | if (PyObject_HasAttrString(obj, "op")) { |
| 4620 | int res; |
| 4621 | tmp = PyObject_GetAttrString(obj, "op"); |
| 4622 | if (tmp == NULL) goto failed; |
| 4623 | res = obj2ast_boolop(tmp, &op, arena); |
| 4624 | if (res != 0) goto failed; |
| 4625 | Py_XDECREF(tmp); |
| 4626 | tmp = NULL; |
| 4627 | } else { |
| 4628 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 4629 | return 1; |
| 4630 | } |
| 4631 | if (PyObject_HasAttrString(obj, "values")) { |
| 4632 | int res; |
| 4633 | Py_ssize_t len; |
| 4634 | Py_ssize_t i; |
| 4635 | tmp = PyObject_GetAttrString(obj, "values"); |
| 4636 | if (tmp == NULL) goto failed; |
| 4637 | if (!PyList_Check(tmp)) { |
| 4638 | PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4639 | goto failed; |
| 4640 | } |
| 4641 | len = PyList_GET_SIZE(tmp); |
| 4642 | values = asdl_seq_new(len, arena); |
| 4643 | if (values == NULL) goto failed; |
| 4644 | for (i = 0; i < len; i++) { |
| 4645 | expr_ty value; |
| 4646 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4647 | if (res != 0) goto failed; |
| 4648 | asdl_seq_SET(values, i, value); |
| 4649 | } |
| 4650 | Py_XDECREF(tmp); |
| 4651 | tmp = NULL; |
| 4652 | } else { |
| 4653 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 4654 | return 1; |
| 4655 | } |
| 4656 | *out = BoolOp(op, values, lineno, col_offset, arena); |
| 4657 | if (*out == NULL) goto failed; |
| 4658 | return 0; |
| 4659 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 4660 | isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type); |
| 4661 | if (isinstance == -1) { |
| 4662 | return 1; |
| 4663 | } |
| 4664 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4665 | expr_ty left; |
| 4666 | operator_ty op; |
| 4667 | expr_ty right; |
| 4668 | |
| 4669 | if (PyObject_HasAttrString(obj, "left")) { |
| 4670 | int res; |
| 4671 | tmp = PyObject_GetAttrString(obj, "left"); |
| 4672 | if (tmp == NULL) goto failed; |
| 4673 | res = obj2ast_expr(tmp, &left, arena); |
| 4674 | if (res != 0) goto failed; |
| 4675 | Py_XDECREF(tmp); |
| 4676 | tmp = NULL; |
| 4677 | } else { |
| 4678 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 4679 | return 1; |
| 4680 | } |
| 4681 | if (PyObject_HasAttrString(obj, "op")) { |
| 4682 | int res; |
| 4683 | tmp = PyObject_GetAttrString(obj, "op"); |
| 4684 | if (tmp == NULL) goto failed; |
| 4685 | res = obj2ast_operator(tmp, &op, arena); |
| 4686 | if (res != 0) goto failed; |
| 4687 | Py_XDECREF(tmp); |
| 4688 | tmp = NULL; |
| 4689 | } else { |
| 4690 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 4691 | return 1; |
| 4692 | } |
| 4693 | if (PyObject_HasAttrString(obj, "right")) { |
| 4694 | int res; |
| 4695 | tmp = PyObject_GetAttrString(obj, "right"); |
| 4696 | if (tmp == NULL) goto failed; |
| 4697 | res = obj2ast_expr(tmp, &right, arena); |
| 4698 | if (res != 0) goto failed; |
| 4699 | Py_XDECREF(tmp); |
| 4700 | tmp = NULL; |
| 4701 | } else { |
| 4702 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 4703 | return 1; |
| 4704 | } |
| 4705 | *out = BinOp(left, op, right, lineno, col_offset, arena); |
| 4706 | if (*out == NULL) goto failed; |
| 4707 | return 0; |
| 4708 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 4709 | isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type); |
| 4710 | if (isinstance == -1) { |
| 4711 | return 1; |
| 4712 | } |
| 4713 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4714 | unaryop_ty op; |
| 4715 | expr_ty operand; |
| 4716 | |
| 4717 | if (PyObject_HasAttrString(obj, "op")) { |
| 4718 | int res; |
| 4719 | tmp = PyObject_GetAttrString(obj, "op"); |
| 4720 | if (tmp == NULL) goto failed; |
| 4721 | res = obj2ast_unaryop(tmp, &op, arena); |
| 4722 | if (res != 0) goto failed; |
| 4723 | Py_XDECREF(tmp); |
| 4724 | tmp = NULL; |
| 4725 | } else { |
| 4726 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 4727 | return 1; |
| 4728 | } |
| 4729 | if (PyObject_HasAttrString(obj, "operand")) { |
| 4730 | int res; |
| 4731 | tmp = PyObject_GetAttrString(obj, "operand"); |
| 4732 | if (tmp == NULL) goto failed; |
| 4733 | res = obj2ast_expr(tmp, &operand, arena); |
| 4734 | if (res != 0) goto failed; |
| 4735 | Py_XDECREF(tmp); |
| 4736 | tmp = NULL; |
| 4737 | } else { |
| 4738 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 4739 | return 1; |
| 4740 | } |
| 4741 | *out = UnaryOp(op, operand, lineno, col_offset, arena); |
| 4742 | if (*out == NULL) goto failed; |
| 4743 | return 0; |
| 4744 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 4745 | isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type); |
| 4746 | if (isinstance == -1) { |
| 4747 | return 1; |
| 4748 | } |
| 4749 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4750 | arguments_ty args; |
| 4751 | expr_ty body; |
| 4752 | |
| 4753 | if (PyObject_HasAttrString(obj, "args")) { |
| 4754 | int res; |
| 4755 | tmp = PyObject_GetAttrString(obj, "args"); |
| 4756 | if (tmp == NULL) goto failed; |
| 4757 | res = obj2ast_arguments(tmp, &args, arena); |
| 4758 | if (res != 0) goto failed; |
| 4759 | Py_XDECREF(tmp); |
| 4760 | tmp = NULL; |
| 4761 | } else { |
| 4762 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 4763 | return 1; |
| 4764 | } |
| 4765 | if (PyObject_HasAttrString(obj, "body")) { |
| 4766 | int res; |
| 4767 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4768 | if (tmp == NULL) goto failed; |
| 4769 | res = obj2ast_expr(tmp, &body, arena); |
| 4770 | if (res != 0) goto failed; |
| 4771 | Py_XDECREF(tmp); |
| 4772 | tmp = NULL; |
| 4773 | } else { |
| 4774 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 4775 | return 1; |
| 4776 | } |
| 4777 | *out = Lambda(args, body, lineno, col_offset, arena); |
| 4778 | if (*out == NULL) goto failed; |
| 4779 | return 0; |
| 4780 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 4781 | isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type); |
| 4782 | if (isinstance == -1) { |
| 4783 | return 1; |
| 4784 | } |
| 4785 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4786 | expr_ty test; |
| 4787 | expr_ty body; |
| 4788 | expr_ty orelse; |
| 4789 | |
| 4790 | if (PyObject_HasAttrString(obj, "test")) { |
| 4791 | int res; |
| 4792 | tmp = PyObject_GetAttrString(obj, "test"); |
| 4793 | if (tmp == NULL) goto failed; |
| 4794 | res = obj2ast_expr(tmp, &test, arena); |
| 4795 | if (res != 0) goto failed; |
| 4796 | Py_XDECREF(tmp); |
| 4797 | tmp = NULL; |
| 4798 | } else { |
| 4799 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 4800 | return 1; |
| 4801 | } |
| 4802 | if (PyObject_HasAttrString(obj, "body")) { |
| 4803 | int res; |
| 4804 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4805 | if (tmp == NULL) goto failed; |
| 4806 | res = obj2ast_expr(tmp, &body, arena); |
| 4807 | if (res != 0) goto failed; |
| 4808 | Py_XDECREF(tmp); |
| 4809 | tmp = NULL; |
| 4810 | } else { |
| 4811 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 4812 | return 1; |
| 4813 | } |
| 4814 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4815 | int res; |
| 4816 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4817 | if (tmp == NULL) goto failed; |
| 4818 | res = obj2ast_expr(tmp, &orelse, arena); |
| 4819 | if (res != 0) goto failed; |
| 4820 | Py_XDECREF(tmp); |
| 4821 | tmp = NULL; |
| 4822 | } else { |
| 4823 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 4824 | return 1; |
| 4825 | } |
| 4826 | *out = IfExp(test, body, orelse, lineno, col_offset, arena); |
| 4827 | if (*out == NULL) goto failed; |
| 4828 | return 0; |
| 4829 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 4830 | isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type); |
| 4831 | if (isinstance == -1) { |
| 4832 | return 1; |
| 4833 | } |
| 4834 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4835 | asdl_seq* keys; |
| 4836 | asdl_seq* values; |
| 4837 | |
| 4838 | if (PyObject_HasAttrString(obj, "keys")) { |
| 4839 | int res; |
| 4840 | Py_ssize_t len; |
| 4841 | Py_ssize_t i; |
| 4842 | tmp = PyObject_GetAttrString(obj, "keys"); |
| 4843 | if (tmp == NULL) goto failed; |
| 4844 | if (!PyList_Check(tmp)) { |
| 4845 | PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4846 | goto failed; |
| 4847 | } |
| 4848 | len = PyList_GET_SIZE(tmp); |
| 4849 | keys = asdl_seq_new(len, arena); |
| 4850 | if (keys == NULL) goto failed; |
| 4851 | for (i = 0; i < len; i++) { |
| 4852 | expr_ty value; |
| 4853 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4854 | if (res != 0) goto failed; |
| 4855 | asdl_seq_SET(keys, i, value); |
| 4856 | } |
| 4857 | Py_XDECREF(tmp); |
| 4858 | tmp = NULL; |
| 4859 | } else { |
| 4860 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 4861 | return 1; |
| 4862 | } |
| 4863 | if (PyObject_HasAttrString(obj, "values")) { |
| 4864 | int res; |
| 4865 | Py_ssize_t len; |
| 4866 | Py_ssize_t i; |
| 4867 | tmp = PyObject_GetAttrString(obj, "values"); |
| 4868 | if (tmp == NULL) goto failed; |
| 4869 | if (!PyList_Check(tmp)) { |
| 4870 | PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4871 | goto failed; |
| 4872 | } |
| 4873 | len = PyList_GET_SIZE(tmp); |
| 4874 | values = asdl_seq_new(len, arena); |
| 4875 | if (values == NULL) goto failed; |
| 4876 | for (i = 0; i < len; i++) { |
| 4877 | expr_ty value; |
| 4878 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4879 | if (res != 0) goto failed; |
| 4880 | asdl_seq_SET(values, i, value); |
| 4881 | } |
| 4882 | Py_XDECREF(tmp); |
| 4883 | tmp = NULL; |
| 4884 | } else { |
| 4885 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 4886 | return 1; |
| 4887 | } |
| 4888 | *out = Dict(keys, values, lineno, col_offset, arena); |
| 4889 | if (*out == NULL) goto failed; |
| 4890 | return 0; |
| 4891 | } |
Alexandre Vassalotti | ee936a2 | 2010-01-09 23:35:54 +0000 | [diff] [blame] | 4892 | isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type); |
| 4893 | if (isinstance == -1) { |
| 4894 | return 1; |
| 4895 | } |
| 4896 | if (isinstance) { |
| 4897 | asdl_seq* elts; |
| 4898 | |
| 4899 | if (PyObject_HasAttrString(obj, "elts")) { |
| 4900 | int res; |
| 4901 | Py_ssize_t len; |
| 4902 | Py_ssize_t i; |
| 4903 | tmp = PyObject_GetAttrString(obj, "elts"); |
| 4904 | if (tmp == NULL) goto failed; |
| 4905 | if (!PyList_Check(tmp)) { |
| 4906 | PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4907 | goto failed; |
| 4908 | } |
| 4909 | len = PyList_GET_SIZE(tmp); |
| 4910 | elts = asdl_seq_new(len, arena); |
| 4911 | if (elts == NULL) goto failed; |
| 4912 | for (i = 0; i < len; i++) { |
| 4913 | expr_ty value; |
| 4914 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4915 | if (res != 0) goto failed; |
| 4916 | asdl_seq_SET(elts, i, value); |
| 4917 | } |
| 4918 | Py_XDECREF(tmp); |
| 4919 | tmp = NULL; |
| 4920 | } else { |
| 4921 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 4922 | return 1; |
| 4923 | } |
| 4924 | *out = Set(elts, lineno, col_offset, arena); |
| 4925 | if (*out == NULL) goto failed; |
| 4926 | return 0; |
| 4927 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 4928 | isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type); |
| 4929 | if (isinstance == -1) { |
| 4930 | return 1; |
| 4931 | } |
| 4932 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4933 | expr_ty elt; |
| 4934 | asdl_seq* generators; |
| 4935 | |
| 4936 | if (PyObject_HasAttrString(obj, "elt")) { |
| 4937 | int res; |
| 4938 | tmp = PyObject_GetAttrString(obj, "elt"); |
| 4939 | if (tmp == NULL) goto failed; |
| 4940 | res = obj2ast_expr(tmp, &elt, arena); |
| 4941 | if (res != 0) goto failed; |
| 4942 | Py_XDECREF(tmp); |
| 4943 | tmp = NULL; |
| 4944 | } else { |
| 4945 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 4946 | return 1; |
| 4947 | } |
| 4948 | if (PyObject_HasAttrString(obj, "generators")) { |
| 4949 | int res; |
| 4950 | Py_ssize_t len; |
| 4951 | Py_ssize_t i; |
| 4952 | tmp = PyObject_GetAttrString(obj, "generators"); |
| 4953 | if (tmp == NULL) goto failed; |
| 4954 | if (!PyList_Check(tmp)) { |
| 4955 | PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4956 | goto failed; |
| 4957 | } |
| 4958 | len = PyList_GET_SIZE(tmp); |
| 4959 | generators = asdl_seq_new(len, arena); |
| 4960 | if (generators == NULL) goto failed; |
| 4961 | for (i = 0; i < len; i++) { |
| 4962 | comprehension_ty value; |
| 4963 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4964 | if (res != 0) goto failed; |
| 4965 | asdl_seq_SET(generators, i, value); |
| 4966 | } |
| 4967 | Py_XDECREF(tmp); |
| 4968 | tmp = NULL; |
| 4969 | } else { |
| 4970 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 4971 | return 1; |
| 4972 | } |
| 4973 | *out = ListComp(elt, generators, lineno, col_offset, arena); |
| 4974 | if (*out == NULL) goto failed; |
| 4975 | return 0; |
| 4976 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 4977 | isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type); |
| 4978 | if (isinstance == -1) { |
| 4979 | return 1; |
| 4980 | } |
| 4981 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 4982 | expr_ty elt; |
| 4983 | asdl_seq* generators; |
| 4984 | |
| 4985 | if (PyObject_HasAttrString(obj, "elt")) { |
| 4986 | int res; |
| 4987 | tmp = PyObject_GetAttrString(obj, "elt"); |
| 4988 | if (tmp == NULL) goto failed; |
| 4989 | res = obj2ast_expr(tmp, &elt, arena); |
| 4990 | if (res != 0) goto failed; |
| 4991 | Py_XDECREF(tmp); |
| 4992 | tmp = NULL; |
| 4993 | } else { |
| 4994 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 4995 | return 1; |
| 4996 | } |
| 4997 | if (PyObject_HasAttrString(obj, "generators")) { |
| 4998 | int res; |
| 4999 | Py_ssize_t len; |
| 5000 | Py_ssize_t i; |
| 5001 | tmp = PyObject_GetAttrString(obj, "generators"); |
| 5002 | if (tmp == NULL) goto failed; |
| 5003 | if (!PyList_Check(tmp)) { |
| 5004 | PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5005 | goto failed; |
| 5006 | } |
| 5007 | len = PyList_GET_SIZE(tmp); |
| 5008 | generators = asdl_seq_new(len, arena); |
| 5009 | if (generators == NULL) goto failed; |
| 5010 | for (i = 0; i < len; i++) { |
| 5011 | comprehension_ty value; |
| 5012 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5013 | if (res != 0) goto failed; |
| 5014 | asdl_seq_SET(generators, i, value); |
| 5015 | } |
| 5016 | Py_XDECREF(tmp); |
| 5017 | tmp = NULL; |
| 5018 | } else { |
| 5019 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 5020 | return 1; |
| 5021 | } |
| 5022 | *out = GeneratorExp(elt, generators, lineno, col_offset, arena); |
| 5023 | if (*out == NULL) goto failed; |
| 5024 | return 0; |
| 5025 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5026 | isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); |
| 5027 | if (isinstance == -1) { |
| 5028 | return 1; |
| 5029 | } |
| 5030 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5031 | expr_ty value; |
| 5032 | |
| 5033 | if (PyObject_HasAttrString(obj, "value")) { |
| 5034 | int res; |
| 5035 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5036 | if (tmp == NULL) goto failed; |
| 5037 | res = obj2ast_expr(tmp, &value, arena); |
| 5038 | if (res != 0) goto failed; |
| 5039 | Py_XDECREF(tmp); |
| 5040 | tmp = NULL; |
| 5041 | } else { |
| 5042 | value = NULL; |
| 5043 | } |
| 5044 | *out = Yield(value, lineno, col_offset, arena); |
| 5045 | if (*out == NULL) goto failed; |
| 5046 | return 0; |
| 5047 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5048 | isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); |
| 5049 | if (isinstance == -1) { |
| 5050 | return 1; |
| 5051 | } |
| 5052 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5053 | expr_ty left; |
| 5054 | asdl_int_seq* ops; |
| 5055 | asdl_seq* comparators; |
| 5056 | |
| 5057 | if (PyObject_HasAttrString(obj, "left")) { |
| 5058 | int res; |
| 5059 | tmp = PyObject_GetAttrString(obj, "left"); |
| 5060 | if (tmp == NULL) goto failed; |
| 5061 | res = obj2ast_expr(tmp, &left, arena); |
| 5062 | if (res != 0) goto failed; |
| 5063 | Py_XDECREF(tmp); |
| 5064 | tmp = NULL; |
| 5065 | } else { |
| 5066 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 5067 | return 1; |
| 5068 | } |
| 5069 | if (PyObject_HasAttrString(obj, "ops")) { |
| 5070 | int res; |
| 5071 | Py_ssize_t len; |
| 5072 | Py_ssize_t i; |
| 5073 | tmp = PyObject_GetAttrString(obj, "ops"); |
| 5074 | if (tmp == NULL) goto failed; |
| 5075 | if (!PyList_Check(tmp)) { |
| 5076 | PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5077 | goto failed; |
| 5078 | } |
| 5079 | len = PyList_GET_SIZE(tmp); |
| 5080 | ops = asdl_int_seq_new(len, arena); |
| 5081 | if (ops == NULL) goto failed; |
| 5082 | for (i = 0; i < len; i++) { |
| 5083 | cmpop_ty value; |
| 5084 | res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5085 | if (res != 0) goto failed; |
| 5086 | asdl_seq_SET(ops, i, value); |
| 5087 | } |
| 5088 | Py_XDECREF(tmp); |
| 5089 | tmp = NULL; |
| 5090 | } else { |
| 5091 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 5092 | return 1; |
| 5093 | } |
| 5094 | if (PyObject_HasAttrString(obj, "comparators")) { |
| 5095 | int res; |
| 5096 | Py_ssize_t len; |
| 5097 | Py_ssize_t i; |
| 5098 | tmp = PyObject_GetAttrString(obj, "comparators"); |
| 5099 | if (tmp == NULL) goto failed; |
| 5100 | if (!PyList_Check(tmp)) { |
| 5101 | PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5102 | goto failed; |
| 5103 | } |
| 5104 | len = PyList_GET_SIZE(tmp); |
| 5105 | comparators = asdl_seq_new(len, arena); |
| 5106 | if (comparators == NULL) goto failed; |
| 5107 | for (i = 0; i < len; i++) { |
| 5108 | expr_ty value; |
| 5109 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5110 | if (res != 0) goto failed; |
| 5111 | asdl_seq_SET(comparators, i, value); |
| 5112 | } |
| 5113 | Py_XDECREF(tmp); |
| 5114 | tmp = NULL; |
| 5115 | } else { |
| 5116 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 5117 | return 1; |
| 5118 | } |
| 5119 | *out = Compare(left, ops, comparators, lineno, col_offset, |
| 5120 | arena); |
| 5121 | if (*out == NULL) goto failed; |
| 5122 | return 0; |
| 5123 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5124 | isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type); |
| 5125 | if (isinstance == -1) { |
| 5126 | return 1; |
| 5127 | } |
| 5128 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5129 | expr_ty func; |
| 5130 | asdl_seq* args; |
| 5131 | asdl_seq* keywords; |
| 5132 | expr_ty starargs; |
| 5133 | expr_ty kwargs; |
| 5134 | |
| 5135 | if (PyObject_HasAttrString(obj, "func")) { |
| 5136 | int res; |
| 5137 | tmp = PyObject_GetAttrString(obj, "func"); |
| 5138 | if (tmp == NULL) goto failed; |
| 5139 | res = obj2ast_expr(tmp, &func, arena); |
| 5140 | if (res != 0) goto failed; |
| 5141 | Py_XDECREF(tmp); |
| 5142 | tmp = NULL; |
| 5143 | } else { |
| 5144 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 5145 | return 1; |
| 5146 | } |
| 5147 | if (PyObject_HasAttrString(obj, "args")) { |
| 5148 | int res; |
| 5149 | Py_ssize_t len; |
| 5150 | Py_ssize_t i; |
| 5151 | tmp = PyObject_GetAttrString(obj, "args"); |
| 5152 | if (tmp == NULL) goto failed; |
| 5153 | if (!PyList_Check(tmp)) { |
| 5154 | PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5155 | goto failed; |
| 5156 | } |
| 5157 | len = PyList_GET_SIZE(tmp); |
| 5158 | args = asdl_seq_new(len, arena); |
| 5159 | if (args == NULL) goto failed; |
| 5160 | for (i = 0; i < len; i++) { |
| 5161 | expr_ty value; |
| 5162 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5163 | if (res != 0) goto failed; |
| 5164 | asdl_seq_SET(args, i, value); |
| 5165 | } |
| 5166 | Py_XDECREF(tmp); |
| 5167 | tmp = NULL; |
| 5168 | } else { |
| 5169 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 5170 | return 1; |
| 5171 | } |
| 5172 | if (PyObject_HasAttrString(obj, "keywords")) { |
| 5173 | int res; |
| 5174 | Py_ssize_t len; |
| 5175 | Py_ssize_t i; |
| 5176 | tmp = PyObject_GetAttrString(obj, "keywords"); |
| 5177 | if (tmp == NULL) goto failed; |
| 5178 | if (!PyList_Check(tmp)) { |
| 5179 | PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5180 | goto failed; |
| 5181 | } |
| 5182 | len = PyList_GET_SIZE(tmp); |
| 5183 | keywords = asdl_seq_new(len, arena); |
| 5184 | if (keywords == NULL) goto failed; |
| 5185 | for (i = 0; i < len; i++) { |
| 5186 | keyword_ty value; |
| 5187 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5188 | if (res != 0) goto failed; |
| 5189 | asdl_seq_SET(keywords, i, value); |
| 5190 | } |
| 5191 | Py_XDECREF(tmp); |
| 5192 | tmp = NULL; |
| 5193 | } else { |
| 5194 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 5195 | return 1; |
| 5196 | } |
| 5197 | if (PyObject_HasAttrString(obj, "starargs")) { |
| 5198 | int res; |
| 5199 | tmp = PyObject_GetAttrString(obj, "starargs"); |
| 5200 | if (tmp == NULL) goto failed; |
| 5201 | res = obj2ast_expr(tmp, &starargs, arena); |
| 5202 | if (res != 0) goto failed; |
| 5203 | Py_XDECREF(tmp); |
| 5204 | tmp = NULL; |
| 5205 | } else { |
| 5206 | starargs = NULL; |
| 5207 | } |
| 5208 | if (PyObject_HasAttrString(obj, "kwargs")) { |
| 5209 | int res; |
| 5210 | tmp = PyObject_GetAttrString(obj, "kwargs"); |
| 5211 | if (tmp == NULL) goto failed; |
| 5212 | res = obj2ast_expr(tmp, &kwargs, arena); |
| 5213 | if (res != 0) goto failed; |
| 5214 | Py_XDECREF(tmp); |
| 5215 | tmp = NULL; |
| 5216 | } else { |
| 5217 | kwargs = NULL; |
| 5218 | } |
| 5219 | *out = Call(func, args, keywords, starargs, kwargs, lineno, |
| 5220 | col_offset, arena); |
| 5221 | if (*out == NULL) goto failed; |
| 5222 | return 0; |
| 5223 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5224 | isinstance = PyObject_IsInstance(obj, (PyObject*)Repr_type); |
| 5225 | if (isinstance == -1) { |
| 5226 | return 1; |
| 5227 | } |
| 5228 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5229 | expr_ty value; |
| 5230 | |
| 5231 | if (PyObject_HasAttrString(obj, "value")) { |
| 5232 | int res; |
| 5233 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5234 | if (tmp == NULL) goto failed; |
| 5235 | res = obj2ast_expr(tmp, &value, arena); |
| 5236 | if (res != 0) goto failed; |
| 5237 | Py_XDECREF(tmp); |
| 5238 | tmp = NULL; |
| 5239 | } else { |
| 5240 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Repr"); |
| 5241 | return 1; |
| 5242 | } |
| 5243 | *out = Repr(value, lineno, col_offset, arena); |
| 5244 | if (*out == NULL) goto failed; |
| 5245 | return 0; |
| 5246 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5247 | isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type); |
| 5248 | if (isinstance == -1) { |
| 5249 | return 1; |
| 5250 | } |
| 5251 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5252 | object n; |
| 5253 | |
| 5254 | if (PyObject_HasAttrString(obj, "n")) { |
| 5255 | int res; |
| 5256 | tmp = PyObject_GetAttrString(obj, "n"); |
| 5257 | if (tmp == NULL) goto failed; |
| 5258 | res = obj2ast_object(tmp, &n, arena); |
| 5259 | if (res != 0) goto failed; |
| 5260 | Py_XDECREF(tmp); |
| 5261 | tmp = NULL; |
| 5262 | } else { |
| 5263 | PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num"); |
| 5264 | return 1; |
| 5265 | } |
| 5266 | *out = Num(n, lineno, col_offset, arena); |
| 5267 | if (*out == NULL) goto failed; |
| 5268 | return 0; |
| 5269 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5270 | isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type); |
| 5271 | if (isinstance == -1) { |
| 5272 | return 1; |
| 5273 | } |
| 5274 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5275 | string s; |
| 5276 | |
| 5277 | if (PyObject_HasAttrString(obj, "s")) { |
| 5278 | int res; |
| 5279 | tmp = PyObject_GetAttrString(obj, "s"); |
| 5280 | if (tmp == NULL) goto failed; |
| 5281 | res = obj2ast_string(tmp, &s, arena); |
| 5282 | if (res != 0) goto failed; |
| 5283 | Py_XDECREF(tmp); |
| 5284 | tmp = NULL; |
| 5285 | } else { |
| 5286 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str"); |
| 5287 | return 1; |
| 5288 | } |
| 5289 | *out = Str(s, lineno, col_offset, arena); |
| 5290 | if (*out == NULL) goto failed; |
| 5291 | return 0; |
| 5292 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5293 | isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type); |
| 5294 | if (isinstance == -1) { |
| 5295 | return 1; |
| 5296 | } |
| 5297 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5298 | expr_ty value; |
| 5299 | identifier attr; |
| 5300 | expr_context_ty ctx; |
| 5301 | |
| 5302 | if (PyObject_HasAttrString(obj, "value")) { |
| 5303 | int res; |
| 5304 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5305 | if (tmp == NULL) goto failed; |
| 5306 | res = obj2ast_expr(tmp, &value, arena); |
| 5307 | if (res != 0) goto failed; |
| 5308 | Py_XDECREF(tmp); |
| 5309 | tmp = NULL; |
| 5310 | } else { |
| 5311 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 5312 | return 1; |
| 5313 | } |
| 5314 | if (PyObject_HasAttrString(obj, "attr")) { |
| 5315 | int res; |
| 5316 | tmp = PyObject_GetAttrString(obj, "attr"); |
| 5317 | if (tmp == NULL) goto failed; |
| 5318 | res = obj2ast_identifier(tmp, &attr, arena); |
| 5319 | if (res != 0) goto failed; |
| 5320 | Py_XDECREF(tmp); |
| 5321 | tmp = NULL; |
| 5322 | } else { |
| 5323 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 5324 | return 1; |
| 5325 | } |
| 5326 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5327 | int res; |
| 5328 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5329 | if (tmp == NULL) goto failed; |
| 5330 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5331 | if (res != 0) goto failed; |
| 5332 | Py_XDECREF(tmp); |
| 5333 | tmp = NULL; |
| 5334 | } else { |
| 5335 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 5336 | return 1; |
| 5337 | } |
| 5338 | *out = Attribute(value, attr, ctx, lineno, col_offset, arena); |
| 5339 | if (*out == NULL) goto failed; |
| 5340 | return 0; |
| 5341 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5342 | isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type); |
| 5343 | if (isinstance == -1) { |
| 5344 | return 1; |
| 5345 | } |
| 5346 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5347 | expr_ty value; |
| 5348 | slice_ty slice; |
| 5349 | expr_context_ty ctx; |
| 5350 | |
| 5351 | if (PyObject_HasAttrString(obj, "value")) { |
| 5352 | int res; |
| 5353 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5354 | if (tmp == NULL) goto failed; |
| 5355 | res = obj2ast_expr(tmp, &value, arena); |
| 5356 | if (res != 0) goto failed; |
| 5357 | Py_XDECREF(tmp); |
| 5358 | tmp = NULL; |
| 5359 | } else { |
| 5360 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 5361 | return 1; |
| 5362 | } |
| 5363 | if (PyObject_HasAttrString(obj, "slice")) { |
| 5364 | int res; |
| 5365 | tmp = PyObject_GetAttrString(obj, "slice"); |
| 5366 | if (tmp == NULL) goto failed; |
| 5367 | res = obj2ast_slice(tmp, &slice, arena); |
| 5368 | if (res != 0) goto failed; |
| 5369 | Py_XDECREF(tmp); |
| 5370 | tmp = NULL; |
| 5371 | } else { |
| 5372 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 5373 | return 1; |
| 5374 | } |
| 5375 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5376 | int res; |
| 5377 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5378 | if (tmp == NULL) goto failed; |
| 5379 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5380 | if (res != 0) goto failed; |
| 5381 | Py_XDECREF(tmp); |
| 5382 | tmp = NULL; |
| 5383 | } else { |
| 5384 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 5385 | return 1; |
| 5386 | } |
| 5387 | *out = Subscript(value, slice, ctx, lineno, col_offset, arena); |
| 5388 | if (*out == NULL) goto failed; |
| 5389 | return 0; |
| 5390 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5391 | isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type); |
| 5392 | if (isinstance == -1) { |
| 5393 | return 1; |
| 5394 | } |
| 5395 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5396 | identifier id; |
| 5397 | expr_context_ty ctx; |
| 5398 | |
| 5399 | if (PyObject_HasAttrString(obj, "id")) { |
| 5400 | int res; |
| 5401 | tmp = PyObject_GetAttrString(obj, "id"); |
| 5402 | if (tmp == NULL) goto failed; |
| 5403 | res = obj2ast_identifier(tmp, &id, arena); |
| 5404 | if (res != 0) goto failed; |
| 5405 | Py_XDECREF(tmp); |
| 5406 | tmp = NULL; |
| 5407 | } else { |
| 5408 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 5409 | return 1; |
| 5410 | } |
| 5411 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5412 | int res; |
| 5413 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5414 | if (tmp == NULL) goto failed; |
| 5415 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5416 | if (res != 0) goto failed; |
| 5417 | Py_XDECREF(tmp); |
| 5418 | tmp = NULL; |
| 5419 | } else { |
| 5420 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 5421 | return 1; |
| 5422 | } |
| 5423 | *out = Name(id, ctx, lineno, col_offset, arena); |
| 5424 | if (*out == NULL) goto failed; |
| 5425 | return 0; |
| 5426 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5427 | isinstance = PyObject_IsInstance(obj, (PyObject*)List_type); |
| 5428 | if (isinstance == -1) { |
| 5429 | return 1; |
| 5430 | } |
| 5431 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5432 | asdl_seq* elts; |
| 5433 | expr_context_ty ctx; |
| 5434 | |
| 5435 | if (PyObject_HasAttrString(obj, "elts")) { |
| 5436 | int res; |
| 5437 | Py_ssize_t len; |
| 5438 | Py_ssize_t i; |
| 5439 | tmp = PyObject_GetAttrString(obj, "elts"); |
| 5440 | if (tmp == NULL) goto failed; |
| 5441 | if (!PyList_Check(tmp)) { |
| 5442 | PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5443 | goto failed; |
| 5444 | } |
| 5445 | len = PyList_GET_SIZE(tmp); |
| 5446 | elts = asdl_seq_new(len, arena); |
| 5447 | if (elts == NULL) goto failed; |
| 5448 | for (i = 0; i < len; i++) { |
| 5449 | expr_ty value; |
| 5450 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5451 | if (res != 0) goto failed; |
| 5452 | asdl_seq_SET(elts, i, value); |
| 5453 | } |
| 5454 | Py_XDECREF(tmp); |
| 5455 | tmp = NULL; |
| 5456 | } else { |
| 5457 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 5458 | return 1; |
| 5459 | } |
| 5460 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5461 | int res; |
| 5462 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5463 | if (tmp == NULL) goto failed; |
| 5464 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5465 | if (res != 0) goto failed; |
| 5466 | Py_XDECREF(tmp); |
| 5467 | tmp = NULL; |
| 5468 | } else { |
| 5469 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 5470 | return 1; |
| 5471 | } |
| 5472 | *out = List(elts, ctx, lineno, col_offset, arena); |
| 5473 | if (*out == NULL) goto failed; |
| 5474 | return 0; |
| 5475 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5476 | isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type); |
| 5477 | if (isinstance == -1) { |
| 5478 | return 1; |
| 5479 | } |
| 5480 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5481 | asdl_seq* elts; |
| 5482 | expr_context_ty ctx; |
| 5483 | |
| 5484 | if (PyObject_HasAttrString(obj, "elts")) { |
| 5485 | int res; |
| 5486 | Py_ssize_t len; |
| 5487 | Py_ssize_t i; |
| 5488 | tmp = PyObject_GetAttrString(obj, "elts"); |
| 5489 | if (tmp == NULL) goto failed; |
| 5490 | if (!PyList_Check(tmp)) { |
| 5491 | PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5492 | goto failed; |
| 5493 | } |
| 5494 | len = PyList_GET_SIZE(tmp); |
| 5495 | elts = asdl_seq_new(len, arena); |
| 5496 | if (elts == NULL) goto failed; |
| 5497 | for (i = 0; i < len; i++) { |
| 5498 | expr_ty value; |
| 5499 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5500 | if (res != 0) goto failed; |
| 5501 | asdl_seq_SET(elts, i, value); |
| 5502 | } |
| 5503 | Py_XDECREF(tmp); |
| 5504 | tmp = NULL; |
| 5505 | } else { |
| 5506 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 5507 | return 1; |
| 5508 | } |
| 5509 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5510 | int res; |
| 5511 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5512 | if (tmp == NULL) goto failed; |
| 5513 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5514 | if (res != 0) goto failed; |
| 5515 | Py_XDECREF(tmp); |
| 5516 | tmp = NULL; |
| 5517 | } else { |
| 5518 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 5519 | return 1; |
| 5520 | } |
| 5521 | *out = Tuple(elts, ctx, lineno, col_offset, arena); |
| 5522 | if (*out == NULL) goto failed; |
| 5523 | return 0; |
| 5524 | } |
| 5525 | |
| 5526 | tmp = PyObject_Repr(obj); |
| 5527 | if (tmp == NULL) goto failed; |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 5528 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %.400s", PyString_AS_STRING(tmp)); |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5529 | failed: |
| 5530 | Py_XDECREF(tmp); |
| 5531 | return 1; |
| 5532 | } |
| 5533 | |
| 5534 | int |
| 5535 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 5536 | { |
| 5537 | PyObject* tmp = NULL; |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5538 | int isinstance; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5539 | |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5540 | isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); |
| 5541 | if (isinstance == -1) { |
| 5542 | return 1; |
| 5543 | } |
| 5544 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5545 | *out = Load; |
| 5546 | return 0; |
| 5547 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5548 | isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type); |
| 5549 | if (isinstance == -1) { |
| 5550 | return 1; |
| 5551 | } |
| 5552 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5553 | *out = Store; |
| 5554 | return 0; |
| 5555 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5556 | isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type); |
| 5557 | if (isinstance == -1) { |
| 5558 | return 1; |
| 5559 | } |
| 5560 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5561 | *out = Del; |
| 5562 | return 0; |
| 5563 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5564 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type); |
| 5565 | if (isinstance == -1) { |
| 5566 | return 1; |
| 5567 | } |
| 5568 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5569 | *out = AugLoad; |
| 5570 | return 0; |
| 5571 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5572 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type); |
| 5573 | if (isinstance == -1) { |
| 5574 | return 1; |
| 5575 | } |
| 5576 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5577 | *out = AugStore; |
| 5578 | return 0; |
| 5579 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5580 | isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type); |
| 5581 | if (isinstance == -1) { |
| 5582 | return 1; |
| 5583 | } |
| 5584 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5585 | *out = Param; |
| 5586 | return 0; |
| 5587 | } |
| 5588 | |
| 5589 | tmp = PyObject_Repr(obj); |
| 5590 | if (tmp == NULL) goto failed; |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 5591 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %.400s", PyString_AS_STRING(tmp)); |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5592 | failed: |
| 5593 | Py_XDECREF(tmp); |
| 5594 | return 1; |
| 5595 | } |
| 5596 | |
| 5597 | int |
| 5598 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
| 5599 | { |
| 5600 | PyObject* tmp = NULL; |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5601 | int isinstance; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5602 | |
| 5603 | |
| 5604 | if (obj == Py_None) { |
| 5605 | *out = NULL; |
| 5606 | return 0; |
| 5607 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5608 | isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type); |
| 5609 | if (isinstance == -1) { |
| 5610 | return 1; |
| 5611 | } |
| 5612 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5613 | |
| 5614 | *out = Ellipsis(arena); |
| 5615 | if (*out == NULL) goto failed; |
| 5616 | return 0; |
| 5617 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5618 | isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type); |
| 5619 | if (isinstance == -1) { |
| 5620 | return 1; |
| 5621 | } |
| 5622 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5623 | expr_ty lower; |
| 5624 | expr_ty upper; |
| 5625 | expr_ty step; |
| 5626 | |
| 5627 | if (PyObject_HasAttrString(obj, "lower")) { |
| 5628 | int res; |
| 5629 | tmp = PyObject_GetAttrString(obj, "lower"); |
| 5630 | if (tmp == NULL) goto failed; |
| 5631 | res = obj2ast_expr(tmp, &lower, arena); |
| 5632 | if (res != 0) goto failed; |
| 5633 | Py_XDECREF(tmp); |
| 5634 | tmp = NULL; |
| 5635 | } else { |
| 5636 | lower = NULL; |
| 5637 | } |
| 5638 | if (PyObject_HasAttrString(obj, "upper")) { |
| 5639 | int res; |
| 5640 | tmp = PyObject_GetAttrString(obj, "upper"); |
| 5641 | if (tmp == NULL) goto failed; |
| 5642 | res = obj2ast_expr(tmp, &upper, arena); |
| 5643 | if (res != 0) goto failed; |
| 5644 | Py_XDECREF(tmp); |
| 5645 | tmp = NULL; |
| 5646 | } else { |
| 5647 | upper = NULL; |
| 5648 | } |
| 5649 | if (PyObject_HasAttrString(obj, "step")) { |
| 5650 | int res; |
| 5651 | tmp = PyObject_GetAttrString(obj, "step"); |
| 5652 | if (tmp == NULL) goto failed; |
| 5653 | res = obj2ast_expr(tmp, &step, arena); |
| 5654 | if (res != 0) goto failed; |
| 5655 | Py_XDECREF(tmp); |
| 5656 | tmp = NULL; |
| 5657 | } else { |
| 5658 | step = NULL; |
| 5659 | } |
| 5660 | *out = Slice(lower, upper, step, arena); |
| 5661 | if (*out == NULL) goto failed; |
| 5662 | return 0; |
| 5663 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5664 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type); |
| 5665 | if (isinstance == -1) { |
| 5666 | return 1; |
| 5667 | } |
| 5668 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5669 | asdl_seq* dims; |
| 5670 | |
| 5671 | if (PyObject_HasAttrString(obj, "dims")) { |
| 5672 | int res; |
| 5673 | Py_ssize_t len; |
| 5674 | Py_ssize_t i; |
| 5675 | tmp = PyObject_GetAttrString(obj, "dims"); |
| 5676 | if (tmp == NULL) goto failed; |
| 5677 | if (!PyList_Check(tmp)) { |
| 5678 | PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5679 | goto failed; |
| 5680 | } |
| 5681 | len = PyList_GET_SIZE(tmp); |
| 5682 | dims = asdl_seq_new(len, arena); |
| 5683 | if (dims == NULL) goto failed; |
| 5684 | for (i = 0; i < len; i++) { |
| 5685 | slice_ty value; |
| 5686 | res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5687 | if (res != 0) goto failed; |
| 5688 | asdl_seq_SET(dims, i, value); |
| 5689 | } |
| 5690 | Py_XDECREF(tmp); |
| 5691 | tmp = NULL; |
| 5692 | } else { |
| 5693 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
| 5694 | return 1; |
| 5695 | } |
| 5696 | *out = ExtSlice(dims, arena); |
| 5697 | if (*out == NULL) goto failed; |
| 5698 | return 0; |
| 5699 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5700 | isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type); |
| 5701 | if (isinstance == -1) { |
| 5702 | return 1; |
| 5703 | } |
| 5704 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5705 | expr_ty value; |
| 5706 | |
| 5707 | if (PyObject_HasAttrString(obj, "value")) { |
| 5708 | int res; |
| 5709 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5710 | if (tmp == NULL) goto failed; |
| 5711 | res = obj2ast_expr(tmp, &value, arena); |
| 5712 | if (res != 0) goto failed; |
| 5713 | Py_XDECREF(tmp); |
| 5714 | tmp = NULL; |
| 5715 | } else { |
| 5716 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
| 5717 | return 1; |
| 5718 | } |
| 5719 | *out = Index(value, arena); |
| 5720 | if (*out == NULL) goto failed; |
| 5721 | return 0; |
| 5722 | } |
| 5723 | |
| 5724 | tmp = PyObject_Repr(obj); |
| 5725 | if (tmp == NULL) goto failed; |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 5726 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %.400s", PyString_AS_STRING(tmp)); |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5727 | failed: |
| 5728 | Py_XDECREF(tmp); |
| 5729 | return 1; |
| 5730 | } |
| 5731 | |
| 5732 | int |
| 5733 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 5734 | { |
| 5735 | PyObject* tmp = NULL; |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5736 | int isinstance; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5737 | |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5738 | isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); |
| 5739 | if (isinstance == -1) { |
| 5740 | return 1; |
| 5741 | } |
| 5742 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5743 | *out = And; |
| 5744 | return 0; |
| 5745 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5746 | isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type); |
| 5747 | if (isinstance == -1) { |
| 5748 | return 1; |
| 5749 | } |
| 5750 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5751 | *out = Or; |
| 5752 | return 0; |
| 5753 | } |
| 5754 | |
| 5755 | tmp = PyObject_Repr(obj); |
| 5756 | if (tmp == NULL) goto failed; |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 5757 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %.400s", PyString_AS_STRING(tmp)); |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5758 | failed: |
| 5759 | Py_XDECREF(tmp); |
| 5760 | return 1; |
| 5761 | } |
| 5762 | |
| 5763 | int |
| 5764 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 5765 | { |
| 5766 | PyObject* tmp = NULL; |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5767 | int isinstance; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5768 | |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5769 | isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); |
| 5770 | if (isinstance == -1) { |
| 5771 | return 1; |
| 5772 | } |
| 5773 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5774 | *out = Add; |
| 5775 | return 0; |
| 5776 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5777 | isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type); |
| 5778 | if (isinstance == -1) { |
| 5779 | return 1; |
| 5780 | } |
| 5781 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5782 | *out = Sub; |
| 5783 | return 0; |
| 5784 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5785 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type); |
| 5786 | if (isinstance == -1) { |
| 5787 | return 1; |
| 5788 | } |
| 5789 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5790 | *out = Mult; |
| 5791 | return 0; |
| 5792 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5793 | isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type); |
| 5794 | if (isinstance == -1) { |
| 5795 | return 1; |
| 5796 | } |
| 5797 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5798 | *out = Div; |
| 5799 | return 0; |
| 5800 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5801 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type); |
| 5802 | if (isinstance == -1) { |
| 5803 | return 1; |
| 5804 | } |
| 5805 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5806 | *out = Mod; |
| 5807 | return 0; |
| 5808 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5809 | isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type); |
| 5810 | if (isinstance == -1) { |
| 5811 | return 1; |
| 5812 | } |
| 5813 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5814 | *out = Pow; |
| 5815 | return 0; |
| 5816 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5817 | isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type); |
| 5818 | if (isinstance == -1) { |
| 5819 | return 1; |
| 5820 | } |
| 5821 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5822 | *out = LShift; |
| 5823 | return 0; |
| 5824 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5825 | isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type); |
| 5826 | if (isinstance == -1) { |
| 5827 | return 1; |
| 5828 | } |
| 5829 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5830 | *out = RShift; |
| 5831 | return 0; |
| 5832 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5833 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type); |
| 5834 | if (isinstance == -1) { |
| 5835 | return 1; |
| 5836 | } |
| 5837 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5838 | *out = BitOr; |
| 5839 | return 0; |
| 5840 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5841 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type); |
| 5842 | if (isinstance == -1) { |
| 5843 | return 1; |
| 5844 | } |
| 5845 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5846 | *out = BitXor; |
| 5847 | return 0; |
| 5848 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5849 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type); |
| 5850 | if (isinstance == -1) { |
| 5851 | return 1; |
| 5852 | } |
| 5853 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5854 | *out = BitAnd; |
| 5855 | return 0; |
| 5856 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5857 | isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type); |
| 5858 | if (isinstance == -1) { |
| 5859 | return 1; |
| 5860 | } |
| 5861 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5862 | *out = FloorDiv; |
| 5863 | return 0; |
| 5864 | } |
| 5865 | |
| 5866 | tmp = PyObject_Repr(obj); |
| 5867 | if (tmp == NULL) goto failed; |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 5868 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %.400s", PyString_AS_STRING(tmp)); |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5869 | failed: |
| 5870 | Py_XDECREF(tmp); |
| 5871 | return 1; |
| 5872 | } |
| 5873 | |
| 5874 | int |
| 5875 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 5876 | { |
| 5877 | PyObject* tmp = NULL; |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5878 | int isinstance; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5879 | |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5880 | isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); |
| 5881 | if (isinstance == -1) { |
| 5882 | return 1; |
| 5883 | } |
| 5884 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5885 | *out = Invert; |
| 5886 | return 0; |
| 5887 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5888 | isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type); |
| 5889 | if (isinstance == -1) { |
| 5890 | return 1; |
| 5891 | } |
| 5892 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5893 | *out = Not; |
| 5894 | return 0; |
| 5895 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5896 | isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type); |
| 5897 | if (isinstance == -1) { |
| 5898 | return 1; |
| 5899 | } |
| 5900 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5901 | *out = UAdd; |
| 5902 | return 0; |
| 5903 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5904 | isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type); |
| 5905 | if (isinstance == -1) { |
| 5906 | return 1; |
| 5907 | } |
| 5908 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5909 | *out = USub; |
| 5910 | return 0; |
| 5911 | } |
| 5912 | |
| 5913 | tmp = PyObject_Repr(obj); |
| 5914 | if (tmp == NULL) goto failed; |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 5915 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %.400s", PyString_AS_STRING(tmp)); |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5916 | failed: |
| 5917 | Py_XDECREF(tmp); |
| 5918 | return 1; |
| 5919 | } |
| 5920 | |
| 5921 | int |
| 5922 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 5923 | { |
| 5924 | PyObject* tmp = NULL; |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5925 | int isinstance; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5926 | |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5927 | isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); |
| 5928 | if (isinstance == -1) { |
| 5929 | return 1; |
| 5930 | } |
| 5931 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5932 | *out = Eq; |
| 5933 | return 0; |
| 5934 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5935 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type); |
| 5936 | if (isinstance == -1) { |
| 5937 | return 1; |
| 5938 | } |
| 5939 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5940 | *out = NotEq; |
| 5941 | return 0; |
| 5942 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5943 | isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type); |
| 5944 | if (isinstance == -1) { |
| 5945 | return 1; |
| 5946 | } |
| 5947 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5948 | *out = Lt; |
| 5949 | return 0; |
| 5950 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5951 | isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type); |
| 5952 | if (isinstance == -1) { |
| 5953 | return 1; |
| 5954 | } |
| 5955 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5956 | *out = LtE; |
| 5957 | return 0; |
| 5958 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5959 | isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type); |
| 5960 | if (isinstance == -1) { |
| 5961 | return 1; |
| 5962 | } |
| 5963 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5964 | *out = Gt; |
| 5965 | return 0; |
| 5966 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5967 | isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type); |
| 5968 | if (isinstance == -1) { |
| 5969 | return 1; |
| 5970 | } |
| 5971 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5972 | *out = GtE; |
| 5973 | return 0; |
| 5974 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5975 | isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type); |
| 5976 | if (isinstance == -1) { |
| 5977 | return 1; |
| 5978 | } |
| 5979 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5980 | *out = Is; |
| 5981 | return 0; |
| 5982 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5983 | isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type); |
| 5984 | if (isinstance == -1) { |
| 5985 | return 1; |
| 5986 | } |
| 5987 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5988 | *out = IsNot; |
| 5989 | return 0; |
| 5990 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5991 | isinstance = PyObject_IsInstance(obj, (PyObject *)In_type); |
| 5992 | if (isinstance == -1) { |
| 5993 | return 1; |
| 5994 | } |
| 5995 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 5996 | *out = In; |
| 5997 | return 0; |
| 5998 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 5999 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type); |
| 6000 | if (isinstance == -1) { |
| 6001 | return 1; |
| 6002 | } |
| 6003 | if (isinstance) { |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 6004 | *out = NotIn; |
| 6005 | return 0; |
| 6006 | } |
| 6007 | |
| 6008 | tmp = PyObject_Repr(obj); |
| 6009 | if (tmp == NULL) goto failed; |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 6010 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %.400s", PyString_AS_STRING(tmp)); |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 6011 | failed: |
| 6012 | Py_XDECREF(tmp); |
| 6013 | return 1; |
| 6014 | } |
| 6015 | |
| 6016 | int |
| 6017 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 6018 | { |
| 6019 | PyObject* tmp = NULL; |
| 6020 | expr_ty target; |
| 6021 | expr_ty iter; |
| 6022 | asdl_seq* ifs; |
| 6023 | |
| 6024 | if (PyObject_HasAttrString(obj, "target")) { |
| 6025 | int res; |
| 6026 | tmp = PyObject_GetAttrString(obj, "target"); |
| 6027 | if (tmp == NULL) goto failed; |
| 6028 | res = obj2ast_expr(tmp, &target, arena); |
| 6029 | if (res != 0) goto failed; |
| 6030 | Py_XDECREF(tmp); |
| 6031 | tmp = NULL; |
| 6032 | } else { |
| 6033 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 6034 | return 1; |
| 6035 | } |
| 6036 | if (PyObject_HasAttrString(obj, "iter")) { |
| 6037 | int res; |
| 6038 | tmp = PyObject_GetAttrString(obj, "iter"); |
| 6039 | if (tmp == NULL) goto failed; |
| 6040 | res = obj2ast_expr(tmp, &iter, arena); |
| 6041 | if (res != 0) goto failed; |
| 6042 | Py_XDECREF(tmp); |
| 6043 | tmp = NULL; |
| 6044 | } else { |
| 6045 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 6046 | return 1; |
| 6047 | } |
| 6048 | if (PyObject_HasAttrString(obj, "ifs")) { |
| 6049 | int res; |
| 6050 | Py_ssize_t len; |
| 6051 | Py_ssize_t i; |
| 6052 | tmp = PyObject_GetAttrString(obj, "ifs"); |
| 6053 | if (tmp == NULL) goto failed; |
| 6054 | if (!PyList_Check(tmp)) { |
| 6055 | PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6056 | goto failed; |
| 6057 | } |
| 6058 | len = PyList_GET_SIZE(tmp); |
| 6059 | ifs = asdl_seq_new(len, arena); |
| 6060 | if (ifs == NULL) goto failed; |
| 6061 | for (i = 0; i < len; i++) { |
| 6062 | expr_ty value; |
| 6063 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6064 | if (res != 0) goto failed; |
| 6065 | asdl_seq_SET(ifs, i, value); |
| 6066 | } |
| 6067 | Py_XDECREF(tmp); |
| 6068 | tmp = NULL; |
| 6069 | } else { |
| 6070 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 6071 | return 1; |
| 6072 | } |
| 6073 | *out = comprehension(target, iter, ifs, arena); |
| 6074 | return 0; |
| 6075 | failed: |
| 6076 | Py_XDECREF(tmp); |
| 6077 | return 1; |
| 6078 | } |
| 6079 | |
| 6080 | int |
| 6081 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 6082 | { |
| 6083 | PyObject* tmp = NULL; |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 6084 | int isinstance; |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame] | 6085 | |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 6086 | int lineno; |
| 6087 | int col_offset; |
| 6088 | |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame] | 6089 | if (obj == Py_None) { |
| 6090 | *out = NULL; |
| 6091 | return 0; |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 6092 | } |
| 6093 | if (PyObject_HasAttrString(obj, "lineno")) { |
| 6094 | int res; |
| 6095 | tmp = PyObject_GetAttrString(obj, "lineno"); |
| 6096 | if (tmp == NULL) goto failed; |
| 6097 | res = obj2ast_int(tmp, &lineno, arena); |
| 6098 | if (res != 0) goto failed; |
| 6099 | Py_XDECREF(tmp); |
| 6100 | tmp = NULL; |
| 6101 | } else { |
| 6102 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 6103 | return 1; |
| 6104 | } |
| 6105 | if (PyObject_HasAttrString(obj, "col_offset")) { |
| 6106 | int res; |
| 6107 | tmp = PyObject_GetAttrString(obj, "col_offset"); |
| 6108 | if (tmp == NULL) goto failed; |
| 6109 | res = obj2ast_int(tmp, &col_offset, arena); |
| 6110 | if (res != 0) goto failed; |
| 6111 | Py_XDECREF(tmp); |
| 6112 | tmp = NULL; |
| 6113 | } else { |
| 6114 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 6115 | return 1; |
| 6116 | } |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 6117 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type); |
| 6118 | if (isinstance == -1) { |
| 6119 | return 1; |
| 6120 | } |
| 6121 | if (isinstance) { |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame] | 6122 | expr_ty type; |
| 6123 | expr_ty name; |
| 6124 | asdl_seq* body; |
| 6125 | |
| 6126 | if (PyObject_HasAttrString(obj, "type")) { |
| 6127 | int res; |
| 6128 | tmp = PyObject_GetAttrString(obj, "type"); |
| 6129 | if (tmp == NULL) goto failed; |
| 6130 | res = obj2ast_expr(tmp, &type, arena); |
| 6131 | if (res != 0) goto failed; |
| 6132 | Py_XDECREF(tmp); |
| 6133 | tmp = NULL; |
| 6134 | } else { |
| 6135 | type = NULL; |
| 6136 | } |
| 6137 | if (PyObject_HasAttrString(obj, "name")) { |
| 6138 | int res; |
| 6139 | tmp = PyObject_GetAttrString(obj, "name"); |
| 6140 | if (tmp == NULL) goto failed; |
| 6141 | res = obj2ast_expr(tmp, &name, arena); |
| 6142 | if (res != 0) goto failed; |
| 6143 | Py_XDECREF(tmp); |
| 6144 | tmp = NULL; |
| 6145 | } else { |
| 6146 | name = NULL; |
| 6147 | } |
| 6148 | if (PyObject_HasAttrString(obj, "body")) { |
| 6149 | int res; |
| 6150 | Py_ssize_t len; |
| 6151 | Py_ssize_t i; |
| 6152 | tmp = PyObject_GetAttrString(obj, "body"); |
| 6153 | if (tmp == NULL) goto failed; |
| 6154 | if (!PyList_Check(tmp)) { |
| 6155 | PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6156 | goto failed; |
| 6157 | } |
| 6158 | len = PyList_GET_SIZE(tmp); |
| 6159 | body = asdl_seq_new(len, arena); |
| 6160 | if (body == NULL) goto failed; |
| 6161 | for (i = 0; i < len; i++) { |
| 6162 | stmt_ty value; |
| 6163 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6164 | if (res != 0) goto failed; |
| 6165 | asdl_seq_SET(body, i, value); |
| 6166 | } |
| 6167 | Py_XDECREF(tmp); |
| 6168 | tmp = NULL; |
| 6169 | } else { |
| 6170 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 6171 | return 1; |
| 6172 | } |
| 6173 | *out = ExceptHandler(type, name, body, lineno, col_offset, |
| 6174 | arena); |
| 6175 | if (*out == NULL) goto failed; |
| 6176 | return 0; |
| 6177 | } |
| 6178 | |
| 6179 | tmp = PyObject_Repr(obj); |
| 6180 | if (tmp == NULL) goto failed; |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 6181 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %.400s", PyString_AS_STRING(tmp)); |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 6182 | failed: |
| 6183 | Py_XDECREF(tmp); |
| 6184 | return 1; |
| 6185 | } |
| 6186 | |
| 6187 | int |
| 6188 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 6189 | { |
| 6190 | PyObject* tmp = NULL; |
| 6191 | asdl_seq* args; |
| 6192 | identifier vararg; |
| 6193 | identifier kwarg; |
| 6194 | asdl_seq* defaults; |
| 6195 | |
| 6196 | if (PyObject_HasAttrString(obj, "args")) { |
| 6197 | int res; |
| 6198 | Py_ssize_t len; |
| 6199 | Py_ssize_t i; |
| 6200 | tmp = PyObject_GetAttrString(obj, "args"); |
| 6201 | if (tmp == NULL) goto failed; |
| 6202 | if (!PyList_Check(tmp)) { |
| 6203 | PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6204 | goto failed; |
| 6205 | } |
| 6206 | len = PyList_GET_SIZE(tmp); |
| 6207 | args = asdl_seq_new(len, arena); |
| 6208 | if (args == NULL) goto failed; |
| 6209 | for (i = 0; i < len; i++) { |
| 6210 | expr_ty value; |
| 6211 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6212 | if (res != 0) goto failed; |
| 6213 | asdl_seq_SET(args, i, value); |
| 6214 | } |
| 6215 | Py_XDECREF(tmp); |
| 6216 | tmp = NULL; |
| 6217 | } else { |
| 6218 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 6219 | return 1; |
| 6220 | } |
| 6221 | if (PyObject_HasAttrString(obj, "vararg")) { |
| 6222 | int res; |
| 6223 | tmp = PyObject_GetAttrString(obj, "vararg"); |
| 6224 | if (tmp == NULL) goto failed; |
| 6225 | res = obj2ast_identifier(tmp, &vararg, arena); |
| 6226 | if (res != 0) goto failed; |
| 6227 | Py_XDECREF(tmp); |
| 6228 | tmp = NULL; |
| 6229 | } else { |
| 6230 | vararg = NULL; |
| 6231 | } |
| 6232 | if (PyObject_HasAttrString(obj, "kwarg")) { |
| 6233 | int res; |
| 6234 | tmp = PyObject_GetAttrString(obj, "kwarg"); |
| 6235 | if (tmp == NULL) goto failed; |
| 6236 | res = obj2ast_identifier(tmp, &kwarg, arena); |
| 6237 | if (res != 0) goto failed; |
| 6238 | Py_XDECREF(tmp); |
| 6239 | tmp = NULL; |
| 6240 | } else { |
| 6241 | kwarg = NULL; |
| 6242 | } |
| 6243 | if (PyObject_HasAttrString(obj, "defaults")) { |
| 6244 | int res; |
| 6245 | Py_ssize_t len; |
| 6246 | Py_ssize_t i; |
| 6247 | tmp = PyObject_GetAttrString(obj, "defaults"); |
| 6248 | if (tmp == NULL) goto failed; |
| 6249 | if (!PyList_Check(tmp)) { |
| 6250 | PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6251 | goto failed; |
| 6252 | } |
| 6253 | len = PyList_GET_SIZE(tmp); |
| 6254 | defaults = asdl_seq_new(len, arena); |
| 6255 | if (defaults == NULL) goto failed; |
| 6256 | for (i = 0; i < len; i++) { |
| 6257 | expr_ty value; |
| 6258 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6259 | if (res != 0) goto failed; |
| 6260 | asdl_seq_SET(defaults, i, value); |
| 6261 | } |
| 6262 | Py_XDECREF(tmp); |
| 6263 | tmp = NULL; |
| 6264 | } else { |
| 6265 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 6266 | return 1; |
| 6267 | } |
| 6268 | *out = arguments(args, vararg, kwarg, defaults, arena); |
| 6269 | return 0; |
| 6270 | failed: |
| 6271 | Py_XDECREF(tmp); |
| 6272 | return 1; |
| 6273 | } |
| 6274 | |
| 6275 | int |
| 6276 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 6277 | { |
| 6278 | PyObject* tmp = NULL; |
| 6279 | identifier arg; |
| 6280 | expr_ty value; |
| 6281 | |
| 6282 | if (PyObject_HasAttrString(obj, "arg")) { |
| 6283 | int res; |
| 6284 | tmp = PyObject_GetAttrString(obj, "arg"); |
| 6285 | if (tmp == NULL) goto failed; |
| 6286 | res = obj2ast_identifier(tmp, &arg, arena); |
| 6287 | if (res != 0) goto failed; |
| 6288 | Py_XDECREF(tmp); |
| 6289 | tmp = NULL; |
| 6290 | } else { |
| 6291 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from keyword"); |
| 6292 | return 1; |
| 6293 | } |
| 6294 | if (PyObject_HasAttrString(obj, "value")) { |
| 6295 | int res; |
| 6296 | tmp = PyObject_GetAttrString(obj, "value"); |
| 6297 | if (tmp == NULL) goto failed; |
| 6298 | res = obj2ast_expr(tmp, &value, arena); |
| 6299 | if (res != 0) goto failed; |
| 6300 | Py_XDECREF(tmp); |
| 6301 | tmp = NULL; |
| 6302 | } else { |
| 6303 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 6304 | return 1; |
| 6305 | } |
| 6306 | *out = keyword(arg, value, arena); |
| 6307 | return 0; |
| 6308 | failed: |
| 6309 | Py_XDECREF(tmp); |
| 6310 | return 1; |
| 6311 | } |
| 6312 | |
| 6313 | int |
| 6314 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 6315 | { |
| 6316 | PyObject* tmp = NULL; |
| 6317 | identifier name; |
| 6318 | identifier asname; |
| 6319 | |
| 6320 | if (PyObject_HasAttrString(obj, "name")) { |
| 6321 | int res; |
| 6322 | tmp = PyObject_GetAttrString(obj, "name"); |
| 6323 | if (tmp == NULL) goto failed; |
| 6324 | res = obj2ast_identifier(tmp, &name, arena); |
| 6325 | if (res != 0) goto failed; |
| 6326 | Py_XDECREF(tmp); |
| 6327 | tmp = NULL; |
| 6328 | } else { |
| 6329 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 6330 | return 1; |
| 6331 | } |
| 6332 | if (PyObject_HasAttrString(obj, "asname")) { |
| 6333 | int res; |
| 6334 | tmp = PyObject_GetAttrString(obj, "asname"); |
| 6335 | if (tmp == NULL) goto failed; |
| 6336 | res = obj2ast_identifier(tmp, &asname, arena); |
| 6337 | if (res != 0) goto failed; |
| 6338 | Py_XDECREF(tmp); |
| 6339 | tmp = NULL; |
| 6340 | } else { |
| 6341 | asname = NULL; |
| 6342 | } |
| 6343 | *out = alias(name, asname, arena); |
| 6344 | return 0; |
| 6345 | failed: |
| 6346 | Py_XDECREF(tmp); |
| 6347 | return 1; |
| 6348 | } |
| 6349 | |
| 6350 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6351 | PyMODINIT_FUNC |
| 6352 | init_ast(void) |
| 6353 | { |
| 6354 | PyObject *m, *d; |
| 6355 | if (!init_types()) return; |
| 6356 | m = Py_InitModule3("_ast", NULL, NULL); |
| 6357 | if (!m) return; |
| 6358 | d = PyModule_GetDict(m); |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 6359 | if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6360 | if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) |
| 6361 | return; |
Brett Cannon | 3ad57e2 | 2010-01-10 02:48:50 +0000 | [diff] [blame] | 6362 | if (PyModule_AddStringConstant(m, "__version__", "77400") < 0) |
Martin v. Löwis | ace990c | 2006-02-28 00:32:31 +0000 | [diff] [blame] | 6363 | return; |
Neal Norwitz | 19379f1 | 2006-04-03 04:50:58 +0000 | [diff] [blame] | 6364 | if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return; |
| 6365 | if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) |
| 6366 | return; |
| 6367 | if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) |
| 6368 | < 0) return; |
| 6369 | if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < |
| 6370 | 0) return; |
| 6371 | if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return; |
| 6372 | if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return; |
| 6373 | if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) |
| 6374 | < 0) return; |
| 6375 | if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) |
| 6376 | return; |
| 6377 | if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) |
| 6378 | return; |
| 6379 | if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) |
| 6380 | return; |
| 6381 | if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) |
| 6382 | return; |
| 6383 | if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < |
| 6384 | 0) return; |
| 6385 | if (PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return; |
| 6386 | if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return; |
| 6387 | if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return; |
| 6388 | if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return; |
| 6389 | if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return; |
| 6390 | if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return; |
| 6391 | if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) < |
| 6392 | 0) return; |
| 6393 | if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) < |
| 6394 | 0) return; |
| 6395 | if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) |
| 6396 | return; |
| 6397 | if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) |
| 6398 | return; |
| 6399 | if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < |
| 6400 | 0) return; |
| 6401 | if (PyDict_SetItemString(d, "Exec", (PyObject*)Exec_type) < 0) return; |
| 6402 | if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) |
| 6403 | return; |
| 6404 | if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return; |
| 6405 | if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return; |
| 6406 | if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return; |
| 6407 | if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) |
| 6408 | return; |
| 6409 | if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return; |
| 6410 | if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) |
| 6411 | return; |
| 6412 | if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return; |
| 6413 | if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) |
| 6414 | return; |
| 6415 | if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) |
| 6416 | return; |
| 6417 | if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return; |
| 6418 | if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return; |
Alexandre Vassalotti | ee936a2 | 2010-01-09 23:35:54 +0000 | [diff] [blame] | 6419 | if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return; |
Neal Norwitz | 19379f1 | 2006-04-03 04:50:58 +0000 | [diff] [blame] | 6420 | if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) |
| 6421 | return; |
| 6422 | if (PyDict_SetItemString(d, "GeneratorExp", |
| 6423 | (PyObject*)GeneratorExp_type) < 0) return; |
| 6424 | if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return; |
| 6425 | if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) |
| 6426 | return; |
| 6427 | if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return; |
| 6428 | if (PyDict_SetItemString(d, "Repr", (PyObject*)Repr_type) < 0) return; |
| 6429 | if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return; |
| 6430 | if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return; |
| 6431 | if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < |
| 6432 | 0) return; |
| 6433 | if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < |
| 6434 | 0) return; |
| 6435 | if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return; |
| 6436 | if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return; |
| 6437 | if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return; |
| 6438 | if (PyDict_SetItemString(d, "expr_context", |
| 6439 | (PyObject*)expr_context_type) < 0) return; |
| 6440 | if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return; |
| 6441 | if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return; |
| 6442 | if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return; |
| 6443 | if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) |
| 6444 | return; |
| 6445 | if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) |
| 6446 | return; |
| 6447 | if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return; |
| 6448 | if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return; |
| 6449 | if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0) |
| 6450 | return; |
| 6451 | if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return; |
| 6452 | if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) |
| 6453 | return; |
| 6454 | if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return; |
| 6455 | if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) |
| 6456 | return; |
| 6457 | if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return; |
| 6458 | if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return; |
| 6459 | if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) |
| 6460 | return; |
| 6461 | if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return; |
| 6462 | if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return; |
| 6463 | if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return; |
| 6464 | if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return; |
| 6465 | if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return; |
| 6466 | if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return; |
| 6467 | if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) |
| 6468 | return; |
| 6469 | if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) |
| 6470 | return; |
| 6471 | if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return; |
| 6472 | if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) |
| 6473 | return; |
| 6474 | if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) |
| 6475 | return; |
| 6476 | if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) |
| 6477 | return; |
| 6478 | if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) |
| 6479 | return; |
| 6480 | if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) |
| 6481 | return; |
| 6482 | if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return; |
| 6483 | if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return; |
| 6484 | if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return; |
| 6485 | if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return; |
| 6486 | if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return; |
| 6487 | if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return; |
| 6488 | if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return; |
| 6489 | if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return; |
| 6490 | if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return; |
| 6491 | if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return; |
| 6492 | if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return; |
| 6493 | if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return; |
| 6494 | if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return; |
| 6495 | if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return; |
| 6496 | if (PyDict_SetItemString(d, "comprehension", |
| 6497 | (PyObject*)comprehension_type) < 0) return; |
| 6498 | if (PyDict_SetItemString(d, "excepthandler", |
| 6499 | (PyObject*)excepthandler_type) < 0) return; |
Georg Brandl | a48f3ab | 2008-03-30 06:40:17 +0000 | [diff] [blame] | 6500 | if (PyDict_SetItemString(d, "ExceptHandler", |
| 6501 | (PyObject*)ExceptHandler_type) < 0) return; |
Neal Norwitz | 19379f1 | 2006-04-03 04:50:58 +0000 | [diff] [blame] | 6502 | if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < |
| 6503 | 0) return; |
| 6504 | if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) |
| 6505 | return; |
| 6506 | if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6507 | } |
| 6508 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 6509 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 6510 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 6511 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 6512 | init_types(); |
| 6513 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 6514 | } |
| 6515 | |
Georg Brandl | f2bfd54 | 2008-03-29 13:24:23 +0000 | [diff] [blame] | 6516 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 6517 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 6518 | { |
| 6519 | mod_ty res; |
Georg Brandl | f2bfd54 | 2008-03-29 13:24:23 +0000 | [diff] [blame] | 6520 | PyObject *req_type[] = {(PyObject*)Module_type, (PyObject*)Expression_type, |
| 6521 | (PyObject*)Interactive_type}; |
| 6522 | char *req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 6523 | int isinstance; |
Georg Brandl | f2bfd54 | 2008-03-29 13:24:23 +0000 | [diff] [blame] | 6524 | assert(0 <= mode && mode <= 2); |
| 6525 | |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 6526 | init_types(); |
Georg Brandl | f2bfd54 | 2008-03-29 13:24:23 +0000 | [diff] [blame] | 6527 | |
Benjamin Peterson | 5f429e0 | 2009-12-13 00:54:15 +0000 | [diff] [blame] | 6528 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 6529 | if (isinstance == -1) |
| 6530 | return NULL; |
| 6531 | if (!isinstance) { |
Georg Brandl | f2bfd54 | 2008-03-29 13:24:23 +0000 | [diff] [blame] | 6532 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
| 6533 | req_name[mode], Py_TYPE(ast)->tp_name); |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 6534 | return NULL; |
| 6535 | } |
| 6536 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 6537 | return NULL; |
| 6538 | else |
| 6539 | return res; |
| 6540 | } |
| 6541 | |
| 6542 | int PyAST_Check(PyObject* obj) |
| 6543 | { |
| 6544 | init_types(); |
Georg Brandl | c52ed59 | 2008-03-30 07:01:47 +0000 | [diff] [blame] | 6545 | return PyObject_IsInstance(obj, (PyObject*)&AST_type); |
Georg Brandl | fc8eef3 | 2008-03-28 12:11:56 +0000 | [diff] [blame] | 6546 | } |
| 6547 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 6548 | |