Brett Cannon | 0db62aa | 2007-02-12 03:51:02 +0000 | [diff] [blame] | 1 | /* File automatically generated by Parser/asdl_c.py. */ |
| 2 | |
| 3 | |
| 4 | /* |
Christian Heimes | 4034685 | 2008-02-23 17:52:07 +0000 | [diff] [blame] | 5 | __version__ 60978. |
Brett Cannon | 0db62aa | 2007-02-12 03:51:02 +0000 | [diff] [blame] | 6 | |
| 7 | This module must be committed separately after each AST grammar change; |
| 8 | The __version__ number is set to the revision number of the commit |
| 9 | containing the grammar change. |
| 10 | */ |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 11 | |
| 12 | #include "Python.h" |
| 13 | #include "Python-ast.h" |
| 14 | |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 15 | static PyTypeObject* AST_type; |
| 16 | static PyTypeObject *mod_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 17 | static PyObject* ast2obj_mod(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 18 | static PyTypeObject *Module_type; |
| 19 | static char *Module_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 20 | "body", |
| 21 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 22 | static PyTypeObject *Interactive_type; |
| 23 | static char *Interactive_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 24 | "body", |
| 25 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 26 | static PyTypeObject *Expression_type; |
| 27 | static char *Expression_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 28 | "body", |
| 29 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 30 | static PyTypeObject *Suite_type; |
| 31 | static char *Suite_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 32 | "body", |
| 33 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 34 | static PyTypeObject *stmt_type; |
| 35 | static char *stmt_attributes[] = { |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 36 | "lineno", |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 37 | "col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 38 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 39 | static PyObject* ast2obj_stmt(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 40 | static PyTypeObject *FunctionDef_type; |
| 41 | static char *FunctionDef_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 42 | "name", |
| 43 | "args", |
| 44 | "body", |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 45 | "decorator_list", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 46 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 47 | static PyTypeObject *ClassDef_type; |
| 48 | static char *ClassDef_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 49 | "name", |
| 50 | "bases", |
| 51 | "body", |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 52 | "decorator_list", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 53 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 54 | static PyTypeObject *Return_type; |
| 55 | static char *Return_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 56 | "value", |
| 57 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 58 | static PyTypeObject *Delete_type; |
| 59 | static char *Delete_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 60 | "targets", |
| 61 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 62 | static PyTypeObject *Assign_type; |
| 63 | static char *Assign_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 64 | "targets", |
| 65 | "value", |
| 66 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 67 | static PyTypeObject *AugAssign_type; |
| 68 | static char *AugAssign_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 69 | "target", |
| 70 | "op", |
| 71 | "value", |
| 72 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 73 | static PyTypeObject *Print_type; |
| 74 | static char *Print_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 75 | "dest", |
| 76 | "values", |
| 77 | "nl", |
| 78 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 79 | static PyTypeObject *For_type; |
| 80 | static char *For_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 81 | "target", |
| 82 | "iter", |
| 83 | "body", |
| 84 | "orelse", |
| 85 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 86 | static PyTypeObject *While_type; |
| 87 | static char *While_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 88 | "test", |
| 89 | "body", |
| 90 | "orelse", |
| 91 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 92 | static PyTypeObject *If_type; |
| 93 | static char *If_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 94 | "test", |
| 95 | "body", |
| 96 | "orelse", |
| 97 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 98 | static PyTypeObject *With_type; |
| 99 | static char *With_fields[]={ |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 100 | "context_expr", |
| 101 | "optional_vars", |
| 102 | "body", |
| 103 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 104 | static PyTypeObject *Raise_type; |
| 105 | static char *Raise_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 106 | "type", |
| 107 | "inst", |
| 108 | "tback", |
| 109 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 110 | static PyTypeObject *TryExcept_type; |
| 111 | static char *TryExcept_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 112 | "body", |
| 113 | "handlers", |
| 114 | "orelse", |
| 115 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 116 | static PyTypeObject *TryFinally_type; |
| 117 | static char *TryFinally_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 118 | "body", |
| 119 | "finalbody", |
| 120 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 121 | static PyTypeObject *Assert_type; |
| 122 | static char *Assert_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 123 | "test", |
| 124 | "msg", |
| 125 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 126 | static PyTypeObject *Import_type; |
| 127 | static char *Import_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 128 | "names", |
| 129 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 130 | static PyTypeObject *ImportFrom_type; |
| 131 | static char *ImportFrom_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 132 | "module", |
| 133 | "names", |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 134 | "level", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 135 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 136 | static PyTypeObject *Exec_type; |
| 137 | static char *Exec_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 138 | "body", |
| 139 | "globals", |
| 140 | "locals", |
| 141 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 142 | static PyTypeObject *Global_type; |
| 143 | static char *Global_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 144 | "names", |
| 145 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 146 | static PyTypeObject *Expr_type; |
| 147 | static char *Expr_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 148 | "value", |
| 149 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 150 | static PyTypeObject *Pass_type; |
| 151 | static PyTypeObject *Break_type; |
| 152 | static PyTypeObject *Continue_type; |
| 153 | static PyTypeObject *expr_type; |
| 154 | static char *expr_attributes[] = { |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 155 | "lineno", |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 156 | "col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 157 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 158 | static PyObject* ast2obj_expr(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 159 | static PyTypeObject *BoolOp_type; |
| 160 | static char *BoolOp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 161 | "op", |
| 162 | "values", |
| 163 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 164 | static PyTypeObject *BinOp_type; |
| 165 | static char *BinOp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 166 | "left", |
| 167 | "op", |
| 168 | "right", |
| 169 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 170 | static PyTypeObject *UnaryOp_type; |
| 171 | static char *UnaryOp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 172 | "op", |
| 173 | "operand", |
| 174 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 175 | static PyTypeObject *Lambda_type; |
| 176 | static char *Lambda_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 177 | "args", |
| 178 | "body", |
| 179 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 180 | static PyTypeObject *IfExp_type; |
| 181 | static char *IfExp_fields[]={ |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 182 | "test", |
| 183 | "body", |
| 184 | "orelse", |
| 185 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 186 | static PyTypeObject *Dict_type; |
| 187 | static char *Dict_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 188 | "keys", |
| 189 | "values", |
| 190 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 191 | static PyTypeObject *ListComp_type; |
| 192 | static char *ListComp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 193 | "elt", |
| 194 | "generators", |
| 195 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 196 | static PyTypeObject *GeneratorExp_type; |
| 197 | static char *GeneratorExp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 198 | "elt", |
| 199 | "generators", |
| 200 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 201 | static PyTypeObject *Yield_type; |
| 202 | static char *Yield_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 203 | "value", |
| 204 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 205 | static PyTypeObject *Compare_type; |
| 206 | static char *Compare_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 207 | "left", |
| 208 | "ops", |
| 209 | "comparators", |
| 210 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 211 | static PyTypeObject *Call_type; |
| 212 | static char *Call_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 213 | "func", |
| 214 | "args", |
| 215 | "keywords", |
| 216 | "starargs", |
| 217 | "kwargs", |
| 218 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 219 | static PyTypeObject *Repr_type; |
| 220 | static char *Repr_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 221 | "value", |
| 222 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 223 | static PyTypeObject *Num_type; |
| 224 | static char *Num_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 225 | "n", |
| 226 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 227 | static PyTypeObject *Str_type; |
| 228 | static char *Str_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 229 | "s", |
| 230 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 231 | static PyTypeObject *Attribute_type; |
| 232 | static char *Attribute_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 233 | "value", |
| 234 | "attr", |
| 235 | "ctx", |
| 236 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 237 | static PyTypeObject *Subscript_type; |
| 238 | static char *Subscript_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 239 | "value", |
| 240 | "slice", |
| 241 | "ctx", |
| 242 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 243 | static PyTypeObject *Name_type; |
| 244 | static char *Name_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 245 | "id", |
| 246 | "ctx", |
| 247 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 248 | static PyTypeObject *List_type; |
| 249 | static char *List_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 250 | "elts", |
| 251 | "ctx", |
| 252 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 253 | static PyTypeObject *Tuple_type; |
| 254 | static char *Tuple_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 255 | "elts", |
| 256 | "ctx", |
| 257 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 258 | static PyTypeObject *expr_context_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 259 | static PyObject *Load_singleton, *Store_singleton, *Del_singleton, |
| 260 | *AugLoad_singleton, *AugStore_singleton, *Param_singleton; |
| 261 | static PyObject* ast2obj_expr_context(expr_context_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 262 | static PyTypeObject *Load_type; |
| 263 | static PyTypeObject *Store_type; |
| 264 | static PyTypeObject *Del_type; |
| 265 | static PyTypeObject *AugLoad_type; |
| 266 | static PyTypeObject *AugStore_type; |
| 267 | static PyTypeObject *Param_type; |
| 268 | static PyTypeObject *slice_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 269 | static PyObject* ast2obj_slice(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 270 | static PyTypeObject *Ellipsis_type; |
| 271 | static PyTypeObject *Slice_type; |
| 272 | static char *Slice_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 273 | "lower", |
| 274 | "upper", |
| 275 | "step", |
| 276 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 277 | static PyTypeObject *ExtSlice_type; |
| 278 | static char *ExtSlice_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 279 | "dims", |
| 280 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 281 | static PyTypeObject *Index_type; |
| 282 | static char *Index_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 283 | "value", |
| 284 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 285 | static PyTypeObject *boolop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 286 | static PyObject *And_singleton, *Or_singleton; |
| 287 | static PyObject* ast2obj_boolop(boolop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 288 | static PyTypeObject *And_type; |
| 289 | static PyTypeObject *Or_type; |
| 290 | static PyTypeObject *operator_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 291 | static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton, |
| 292 | *Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton, |
| 293 | *RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton, |
| 294 | *FloorDiv_singleton; |
| 295 | static PyObject* ast2obj_operator(operator_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 296 | static PyTypeObject *Add_type; |
| 297 | static PyTypeObject *Sub_type; |
| 298 | static PyTypeObject *Mult_type; |
| 299 | static PyTypeObject *Div_type; |
| 300 | static PyTypeObject *Mod_type; |
| 301 | static PyTypeObject *Pow_type; |
| 302 | static PyTypeObject *LShift_type; |
| 303 | static PyTypeObject *RShift_type; |
| 304 | static PyTypeObject *BitOr_type; |
| 305 | static PyTypeObject *BitXor_type; |
| 306 | static PyTypeObject *BitAnd_type; |
| 307 | static PyTypeObject *FloorDiv_type; |
| 308 | static PyTypeObject *unaryop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 309 | static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton, |
| 310 | *USub_singleton; |
| 311 | static PyObject* ast2obj_unaryop(unaryop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 312 | static PyTypeObject *Invert_type; |
| 313 | static PyTypeObject *Not_type; |
| 314 | static PyTypeObject *UAdd_type; |
| 315 | static PyTypeObject *USub_type; |
| 316 | static PyTypeObject *cmpop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 317 | static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton, |
| 318 | *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton, |
| 319 | *NotIn_singleton; |
| 320 | static PyObject* ast2obj_cmpop(cmpop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 321 | static PyTypeObject *Eq_type; |
| 322 | static PyTypeObject *NotEq_type; |
| 323 | static PyTypeObject *Lt_type; |
| 324 | static PyTypeObject *LtE_type; |
| 325 | static PyTypeObject *Gt_type; |
| 326 | static PyTypeObject *GtE_type; |
| 327 | static PyTypeObject *Is_type; |
| 328 | static PyTypeObject *IsNot_type; |
| 329 | static PyTypeObject *In_type; |
| 330 | static PyTypeObject *NotIn_type; |
| 331 | static PyTypeObject *comprehension_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 332 | static PyObject* ast2obj_comprehension(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 333 | static char *comprehension_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 334 | "target", |
| 335 | "iter", |
| 336 | "ifs", |
| 337 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 338 | static PyTypeObject *excepthandler_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 339 | static PyObject* ast2obj_excepthandler(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 340 | static char *excepthandler_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 341 | "type", |
| 342 | "name", |
| 343 | "body", |
Jeremy Hylton | 2f327c1 | 2006-04-04 04:00:23 +0000 | [diff] [blame] | 344 | "lineno", |
| 345 | "col_offset", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 346 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 347 | static PyTypeObject *arguments_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 348 | static PyObject* ast2obj_arguments(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 349 | static char *arguments_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 350 | "args", |
| 351 | "vararg", |
| 352 | "kwarg", |
| 353 | "defaults", |
| 354 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 355 | static PyTypeObject *keyword_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 356 | static PyObject* ast2obj_keyword(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 357 | static char *keyword_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 358 | "arg", |
| 359 | "value", |
| 360 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 361 | static PyTypeObject *alias_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 362 | static PyObject* ast2obj_alias(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 363 | static char *alias_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 364 | "name", |
| 365 | "asname", |
| 366 | }; |
| 367 | |
| 368 | |
| 369 | static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields) |
| 370 | { |
| 371 | PyObject *fnames, *result; |
| 372 | int i; |
| 373 | if (num_fields) { |
| 374 | fnames = PyTuple_New(num_fields); |
| 375 | if (!fnames) return NULL; |
| 376 | } else { |
| 377 | fnames = Py_None; |
| 378 | Py_INCREF(Py_None); |
| 379 | } |
| 380 | for(i=0; i < num_fields; i++) { |
| 381 | PyObject *field = PyString_FromString(fields[i]); |
| 382 | if (!field) { |
| 383 | Py_DECREF(fnames); |
| 384 | return NULL; |
| 385 | } |
| 386 | PyTuple_SET_ITEM(fnames, i, field); |
| 387 | } |
Thomas Wouters | 34aa7ba | 2006-02-28 19:02:24 +0000 | [diff] [blame] | 388 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 389 | type, base, "_fields", fnames, "__module__", "_ast"); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 390 | Py_DECREF(fnames); |
| 391 | return (PyTypeObject*)result; |
| 392 | } |
| 393 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 394 | static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) |
| 395 | { |
Neal Norwitz | 19379f1 | 2006-04-03 04:50:58 +0000 | [diff] [blame] | 396 | int i, result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 397 | PyObject *s, *l = PyList_New(num_fields); |
| 398 | if (!l) return 0; |
Neal Norwitz | 19379f1 | 2006-04-03 04:50:58 +0000 | [diff] [blame] | 399 | for(i = 0; i < num_fields; i++) { |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 400 | s = PyString_FromString(attrs[i]); |
| 401 | if (!s) { |
| 402 | Py_DECREF(l); |
| 403 | return 0; |
| 404 | } |
| 405 | PyList_SET_ITEM(l, i, s); |
| 406 | } |
Neal Norwitz | 19379f1 | 2006-04-03 04:50:58 +0000 | [diff] [blame] | 407 | result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0; |
| 408 | Py_DECREF(l); |
| 409 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 410 | } |
| 411 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 412 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 413 | { |
| 414 | int i, n = asdl_seq_LEN(seq); |
| 415 | PyObject *result = PyList_New(n); |
| 416 | PyObject *value; |
| 417 | if (!result) |
| 418 | return NULL; |
| 419 | for (i = 0; i < n; i++) { |
| 420 | value = func(asdl_seq_GET(seq, i)); |
| 421 | if (!value) { |
| 422 | Py_DECREF(result); |
| 423 | return NULL; |
| 424 | } |
| 425 | PyList_SET_ITEM(result, i, value); |
| 426 | } |
| 427 | return result; |
| 428 | } |
| 429 | |
| 430 | static PyObject* ast2obj_object(void *o) |
| 431 | { |
| 432 | if (!o) |
| 433 | o = Py_None; |
| 434 | Py_INCREF((PyObject*)o); |
| 435 | return (PyObject*)o; |
| 436 | } |
| 437 | #define ast2obj_identifier ast2obj_object |
| 438 | #define ast2obj_string ast2obj_object |
| 439 | static PyObject* ast2obj_bool(bool b) |
| 440 | { |
| 441 | return PyBool_FromLong(b); |
| 442 | } |
| 443 | |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 444 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 445 | { |
| 446 | return PyInt_FromLong(b); |
| 447 | } |
| 448 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 449 | static int init_types(void) |
| 450 | { |
Neal Norwitz | 19379f1 | 2006-04-03 04:50:58 +0000 | [diff] [blame] | 451 | static int initialized; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 452 | if (initialized) return 1; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 453 | AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0); |
| 454 | mod_type = make_type("mod", AST_type, NULL, 0); |
| 455 | if (!mod_type) return 0; |
| 456 | if (!add_attributes(mod_type, NULL, 0)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 457 | Module_type = make_type("Module", mod_type, Module_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 458 | if (!Module_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 459 | Interactive_type = make_type("Interactive", mod_type, |
| 460 | Interactive_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 461 | if (!Interactive_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 462 | Expression_type = make_type("Expression", mod_type, Expression_fields, |
| 463 | 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 464 | if (!Expression_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 465 | Suite_type = make_type("Suite", mod_type, Suite_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 466 | if (!Suite_type) return 0; |
| 467 | stmt_type = make_type("stmt", AST_type, NULL, 0); |
| 468 | if (!stmt_type) return 0; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 469 | if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 470 | FunctionDef_type = make_type("FunctionDef", stmt_type, |
| 471 | FunctionDef_fields, 4); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 472 | if (!FunctionDef_type) return 0; |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 473 | ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 4); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 474 | if (!ClassDef_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 475 | Return_type = make_type("Return", stmt_type, Return_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 476 | if (!Return_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 477 | Delete_type = make_type("Delete", stmt_type, Delete_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 478 | if (!Delete_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 479 | Assign_type = make_type("Assign", stmt_type, Assign_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 480 | if (!Assign_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 481 | AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 482 | if (!AugAssign_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 483 | Print_type = make_type("Print", stmt_type, Print_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 484 | if (!Print_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 485 | For_type = make_type("For", stmt_type, For_fields, 4); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 486 | if (!For_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 487 | While_type = make_type("While", stmt_type, While_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 488 | if (!While_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 489 | If_type = make_type("If", stmt_type, If_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 490 | if (!If_type) return 0; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 491 | With_type = make_type("With", stmt_type, With_fields, 3); |
| 492 | if (!With_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 493 | Raise_type = make_type("Raise", stmt_type, Raise_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 494 | if (!Raise_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 495 | TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 496 | if (!TryExcept_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 497 | TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields, |
| 498 | 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 499 | if (!TryFinally_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 500 | Assert_type = make_type("Assert", stmt_type, Assert_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 501 | if (!Assert_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 502 | Import_type = make_type("Import", stmt_type, Import_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 503 | if (!Import_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 504 | ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 505 | 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 506 | if (!ImportFrom_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 507 | Exec_type = make_type("Exec", stmt_type, Exec_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 508 | if (!Exec_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 509 | Global_type = make_type("Global", stmt_type, Global_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 510 | if (!Global_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 511 | Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 512 | if (!Expr_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 513 | Pass_type = make_type("Pass", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 514 | if (!Pass_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 515 | Break_type = make_type("Break", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 516 | if (!Break_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 517 | Continue_type = make_type("Continue", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 518 | if (!Continue_type) return 0; |
| 519 | expr_type = make_type("expr", AST_type, NULL, 0); |
| 520 | if (!expr_type) return 0; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 521 | if (!add_attributes(expr_type, expr_attributes, 2)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 522 | BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 523 | if (!BoolOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 524 | BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 525 | if (!BinOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 526 | UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 527 | if (!UnaryOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 528 | Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 529 | if (!Lambda_type) return 0; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 530 | IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 531 | if (!IfExp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 532 | Dict_type = make_type("Dict", expr_type, Dict_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 533 | if (!Dict_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 534 | ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 535 | if (!ListComp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 536 | GeneratorExp_type = make_type("GeneratorExp", expr_type, |
| 537 | GeneratorExp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 538 | if (!GeneratorExp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 539 | Yield_type = make_type("Yield", expr_type, Yield_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 540 | if (!Yield_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 541 | Compare_type = make_type("Compare", expr_type, Compare_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 542 | if (!Compare_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 543 | Call_type = make_type("Call", expr_type, Call_fields, 5); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 544 | if (!Call_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 545 | Repr_type = make_type("Repr", expr_type, Repr_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 546 | if (!Repr_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 547 | Num_type = make_type("Num", expr_type, Num_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 548 | if (!Num_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 549 | Str_type = make_type("Str", expr_type, Str_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 550 | if (!Str_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 551 | Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 552 | if (!Attribute_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 553 | Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 554 | if (!Subscript_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 555 | Name_type = make_type("Name", expr_type, Name_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 556 | if (!Name_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 557 | List_type = make_type("List", expr_type, List_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 558 | if (!List_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 559 | Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 560 | if (!Tuple_type) return 0; |
| 561 | expr_context_type = make_type("expr_context", AST_type, NULL, 0); |
| 562 | if (!expr_context_type) return 0; |
| 563 | if (!add_attributes(expr_context_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 564 | Load_type = make_type("Load", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 565 | if (!Load_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 566 | Load_singleton = PyType_GenericNew(Load_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 567 | if (!Load_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 568 | Store_type = make_type("Store", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 569 | if (!Store_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 570 | Store_singleton = PyType_GenericNew(Store_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 571 | if (!Store_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 572 | Del_type = make_type("Del", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 573 | if (!Del_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 574 | Del_singleton = PyType_GenericNew(Del_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 575 | if (!Del_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 576 | AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 577 | if (!AugLoad_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 578 | AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 579 | if (!AugLoad_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 580 | AugStore_type = make_type("AugStore", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 581 | if (!AugStore_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 582 | AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 583 | if (!AugStore_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 584 | Param_type = make_type("Param", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 585 | if (!Param_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 586 | Param_singleton = PyType_GenericNew(Param_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 587 | if (!Param_singleton) return 0; |
| 588 | slice_type = make_type("slice", AST_type, NULL, 0); |
| 589 | if (!slice_type) return 0; |
| 590 | if (!add_attributes(slice_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 591 | Ellipsis_type = make_type("Ellipsis", slice_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 592 | if (!Ellipsis_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 593 | Slice_type = make_type("Slice", slice_type, Slice_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 594 | if (!Slice_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 595 | ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 596 | if (!ExtSlice_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 597 | Index_type = make_type("Index", slice_type, Index_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 598 | if (!Index_type) return 0; |
| 599 | boolop_type = make_type("boolop", AST_type, NULL, 0); |
| 600 | if (!boolop_type) return 0; |
| 601 | if (!add_attributes(boolop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 602 | And_type = make_type("And", boolop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 603 | if (!And_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 604 | And_singleton = PyType_GenericNew(And_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 605 | if (!And_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 606 | Or_type = make_type("Or", boolop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 607 | if (!Or_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 608 | Or_singleton = PyType_GenericNew(Or_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 609 | if (!Or_singleton) return 0; |
| 610 | operator_type = make_type("operator", AST_type, NULL, 0); |
| 611 | if (!operator_type) return 0; |
| 612 | if (!add_attributes(operator_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 613 | Add_type = make_type("Add", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 614 | if (!Add_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 615 | Add_singleton = PyType_GenericNew(Add_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 616 | if (!Add_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 617 | Sub_type = make_type("Sub", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 618 | if (!Sub_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 619 | Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 620 | if (!Sub_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 621 | Mult_type = make_type("Mult", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 622 | if (!Mult_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 623 | Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 624 | if (!Mult_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 625 | Div_type = make_type("Div", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 626 | if (!Div_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 627 | Div_singleton = PyType_GenericNew(Div_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 628 | if (!Div_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 629 | Mod_type = make_type("Mod", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 630 | if (!Mod_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 631 | Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 632 | if (!Mod_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 633 | Pow_type = make_type("Pow", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 634 | if (!Pow_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 635 | Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 636 | if (!Pow_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 637 | LShift_type = make_type("LShift", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 638 | if (!LShift_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 639 | LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 640 | if (!LShift_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 641 | RShift_type = make_type("RShift", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 642 | if (!RShift_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 643 | RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 644 | if (!RShift_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 645 | BitOr_type = make_type("BitOr", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 646 | if (!BitOr_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 647 | BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 648 | if (!BitOr_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 649 | BitXor_type = make_type("BitXor", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 650 | if (!BitXor_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 651 | BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 652 | if (!BitXor_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 653 | BitAnd_type = make_type("BitAnd", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 654 | if (!BitAnd_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 655 | BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 656 | if (!BitAnd_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 657 | FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 658 | if (!FloorDiv_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 659 | FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 660 | if (!FloorDiv_singleton) return 0; |
| 661 | unaryop_type = make_type("unaryop", AST_type, NULL, 0); |
| 662 | if (!unaryop_type) return 0; |
| 663 | if (!add_attributes(unaryop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 664 | Invert_type = make_type("Invert", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 665 | if (!Invert_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 666 | Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 667 | if (!Invert_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 668 | Not_type = make_type("Not", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 669 | if (!Not_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 670 | Not_singleton = PyType_GenericNew(Not_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 671 | if (!Not_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 672 | UAdd_type = make_type("UAdd", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 673 | if (!UAdd_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 674 | UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 675 | if (!UAdd_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 676 | USub_type = make_type("USub", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 677 | if (!USub_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 678 | USub_singleton = PyType_GenericNew(USub_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 679 | if (!USub_singleton) return 0; |
| 680 | cmpop_type = make_type("cmpop", AST_type, NULL, 0); |
| 681 | if (!cmpop_type) return 0; |
| 682 | if (!add_attributes(cmpop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 683 | Eq_type = make_type("Eq", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 684 | if (!Eq_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 685 | Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 686 | if (!Eq_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 687 | NotEq_type = make_type("NotEq", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 688 | if (!NotEq_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 689 | NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 690 | if (!NotEq_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 691 | Lt_type = make_type("Lt", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 692 | if (!Lt_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 693 | Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 694 | if (!Lt_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 695 | LtE_type = make_type("LtE", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 696 | if (!LtE_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 697 | LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 698 | if (!LtE_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 699 | Gt_type = make_type("Gt", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 700 | if (!Gt_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 701 | Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 702 | if (!Gt_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 703 | GtE_type = make_type("GtE", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 704 | if (!GtE_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 705 | GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 706 | if (!GtE_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 707 | Is_type = make_type("Is", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 708 | if (!Is_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 709 | Is_singleton = PyType_GenericNew(Is_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 710 | if (!Is_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 711 | IsNot_type = make_type("IsNot", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 712 | if (!IsNot_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 713 | IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 714 | if (!IsNot_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 715 | In_type = make_type("In", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 716 | if (!In_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 717 | In_singleton = PyType_GenericNew(In_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 718 | if (!In_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 719 | NotIn_type = make_type("NotIn", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 720 | if (!NotIn_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 721 | NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 722 | if (!NotIn_singleton) return 0; |
| 723 | comprehension_type = make_type("comprehension", AST_type, |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 724 | comprehension_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 725 | if (!comprehension_type) return 0; |
| 726 | excepthandler_type = make_type("excepthandler", AST_type, |
Jeremy Hylton | 2f327c1 | 2006-04-04 04:00:23 +0000 | [diff] [blame] | 727 | excepthandler_fields, 5); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 728 | if (!excepthandler_type) return 0; |
| 729 | arguments_type = make_type("arguments", AST_type, arguments_fields, 4); |
| 730 | if (!arguments_type) return 0; |
| 731 | keyword_type = make_type("keyword", AST_type, keyword_fields, 2); |
| 732 | if (!keyword_type) return 0; |
| 733 | alias_type = make_type("alias", AST_type, alias_fields, 2); |
| 734 | if (!alias_type) return 0; |
| 735 | initialized = 1; |
| 736 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 737 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 738 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 739 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 740 | Module(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 741 | { |
| 742 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 743 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 744 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 745 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 746 | p->kind = Module_kind; |
| 747 | p->v.Module.body = body; |
| 748 | return p; |
| 749 | } |
| 750 | |
| 751 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 752 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 753 | { |
| 754 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 755 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 756 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 757 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 758 | p->kind = Interactive_kind; |
| 759 | p->v.Interactive.body = body; |
| 760 | return p; |
| 761 | } |
| 762 | |
| 763 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 764 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 765 | { |
| 766 | mod_ty p; |
| 767 | if (!body) { |
| 768 | PyErr_SetString(PyExc_ValueError, |
| 769 | "field body is required for Expression"); |
| 770 | return NULL; |
| 771 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 772 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 773 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 774 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 775 | p->kind = Expression_kind; |
| 776 | p->v.Expression.body = body; |
| 777 | return p; |
| 778 | } |
| 779 | |
| 780 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 781 | Suite(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 782 | { |
| 783 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 784 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 785 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 786 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 787 | p->kind = Suite_kind; |
| 788 | p->v.Suite.body = body; |
| 789 | return p; |
| 790 | } |
| 791 | |
| 792 | stmt_ty |
| 793 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 794 | decorator_list, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 795 | { |
| 796 | stmt_ty p; |
| 797 | if (!name) { |
| 798 | PyErr_SetString(PyExc_ValueError, |
| 799 | "field name is required for FunctionDef"); |
| 800 | return NULL; |
| 801 | } |
| 802 | if (!args) { |
| 803 | PyErr_SetString(PyExc_ValueError, |
| 804 | "field args is required for FunctionDef"); |
| 805 | return NULL; |
| 806 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 807 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 808 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 809 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 810 | p->kind = FunctionDef_kind; |
| 811 | p->v.FunctionDef.name = name; |
| 812 | p->v.FunctionDef.args = args; |
| 813 | p->v.FunctionDef.body = body; |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 814 | p->v.FunctionDef.decorator_list = decorator_list; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 815 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 816 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 817 | return p; |
| 818 | } |
| 819 | |
| 820 | stmt_ty |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 821 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, asdl_seq * |
| 822 | decorator_list, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 823 | { |
| 824 | stmt_ty p; |
| 825 | if (!name) { |
| 826 | PyErr_SetString(PyExc_ValueError, |
| 827 | "field name is required for ClassDef"); |
| 828 | return NULL; |
| 829 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 830 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 831 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 832 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 833 | p->kind = ClassDef_kind; |
| 834 | p->v.ClassDef.name = name; |
| 835 | p->v.ClassDef.bases = bases; |
| 836 | p->v.ClassDef.body = body; |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 837 | p->v.ClassDef.decorator_list = decorator_list; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 838 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 839 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 840 | return p; |
| 841 | } |
| 842 | |
| 843 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 844 | Return(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 845 | { |
| 846 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 847 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 848 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 849 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 850 | p->kind = Return_kind; |
| 851 | p->v.Return.value = value; |
| 852 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 853 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 854 | return p; |
| 855 | } |
| 856 | |
| 857 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 858 | Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 859 | { |
| 860 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 861 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 862 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 863 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 864 | p->kind = Delete_kind; |
| 865 | p->v.Delete.targets = targets; |
| 866 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 867 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 868 | return p; |
| 869 | } |
| 870 | |
| 871 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 872 | Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena |
| 873 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 874 | { |
| 875 | stmt_ty p; |
| 876 | if (!value) { |
| 877 | PyErr_SetString(PyExc_ValueError, |
| 878 | "field value is required for Assign"); |
| 879 | return NULL; |
| 880 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 881 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 882 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 883 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 884 | p->kind = Assign_kind; |
| 885 | p->v.Assign.targets = targets; |
| 886 | p->v.Assign.value = value; |
| 887 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 888 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 889 | return p; |
| 890 | } |
| 891 | |
| 892 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 893 | AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int |
| 894 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 895 | { |
| 896 | stmt_ty p; |
| 897 | if (!target) { |
| 898 | PyErr_SetString(PyExc_ValueError, |
| 899 | "field target is required for AugAssign"); |
| 900 | return NULL; |
| 901 | } |
| 902 | if (!op) { |
| 903 | PyErr_SetString(PyExc_ValueError, |
| 904 | "field op is required for AugAssign"); |
| 905 | return NULL; |
| 906 | } |
| 907 | if (!value) { |
| 908 | PyErr_SetString(PyExc_ValueError, |
| 909 | "field value is required for AugAssign"); |
| 910 | return NULL; |
| 911 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 912 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 913 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 914 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 915 | p->kind = AugAssign_kind; |
| 916 | p->v.AugAssign.target = target; |
| 917 | p->v.AugAssign.op = op; |
| 918 | p->v.AugAssign.value = value; |
| 919 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 920 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 921 | return p; |
| 922 | } |
| 923 | |
| 924 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 925 | Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int col_offset, |
| 926 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 927 | { |
| 928 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 929 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 930 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 931 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 932 | p->kind = Print_kind; |
| 933 | p->v.Print.dest = dest; |
| 934 | p->v.Print.values = values; |
| 935 | p->v.Print.nl = nl; |
| 936 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 937 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 938 | return p; |
| 939 | } |
| 940 | |
| 941 | stmt_ty |
| 942 | 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] | 943 | lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 944 | { |
| 945 | stmt_ty p; |
| 946 | if (!target) { |
| 947 | PyErr_SetString(PyExc_ValueError, |
| 948 | "field target is required for For"); |
| 949 | return NULL; |
| 950 | } |
| 951 | if (!iter) { |
| 952 | PyErr_SetString(PyExc_ValueError, |
| 953 | "field iter is required for For"); |
| 954 | return NULL; |
| 955 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 956 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 957 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 958 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 959 | p->kind = For_kind; |
| 960 | p->v.For.target = target; |
| 961 | p->v.For.iter = iter; |
| 962 | p->v.For.body = body; |
| 963 | p->v.For.orelse = orelse; |
| 964 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 965 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 966 | return p; |
| 967 | } |
| 968 | |
| 969 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 970 | While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 971 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 972 | { |
| 973 | stmt_ty p; |
| 974 | if (!test) { |
| 975 | PyErr_SetString(PyExc_ValueError, |
| 976 | "field test is required for While"); |
| 977 | return NULL; |
| 978 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 979 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 980 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 981 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 982 | p->kind = While_kind; |
| 983 | p->v.While.test = test; |
| 984 | p->v.While.body = body; |
| 985 | p->v.While.orelse = orelse; |
| 986 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 987 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 988 | return p; |
| 989 | } |
| 990 | |
| 991 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 992 | If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 993 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 994 | { |
| 995 | stmt_ty p; |
| 996 | if (!test) { |
| 997 | PyErr_SetString(PyExc_ValueError, |
| 998 | "field test is required for If"); |
| 999 | return NULL; |
| 1000 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1001 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1002 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1003 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1004 | p->kind = If_kind; |
| 1005 | p->v.If.test = test; |
| 1006 | p->v.If.body = body; |
| 1007 | p->v.If.orelse = orelse; |
| 1008 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1009 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1010 | return p; |
| 1011 | } |
| 1012 | |
| 1013 | stmt_ty |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1014 | 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] | 1015 | int col_offset, PyArena *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1016 | { |
| 1017 | stmt_ty p; |
| 1018 | if (!context_expr) { |
| 1019 | PyErr_SetString(PyExc_ValueError, |
| 1020 | "field context_expr is required for With"); |
| 1021 | return NULL; |
| 1022 | } |
| 1023 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1024 | if (!p) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1025 | return NULL; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1026 | p->kind = With_kind; |
| 1027 | p->v.With.context_expr = context_expr; |
| 1028 | p->v.With.optional_vars = optional_vars; |
| 1029 | p->v.With.body = body; |
| 1030 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1031 | p->col_offset = col_offset; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1032 | return p; |
| 1033 | } |
| 1034 | |
| 1035 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1036 | Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset, |
| 1037 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1038 | { |
| 1039 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1040 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1041 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1042 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1043 | p->kind = Raise_kind; |
| 1044 | p->v.Raise.type = type; |
| 1045 | p->v.Raise.inst = inst; |
| 1046 | p->v.Raise.tback = tback; |
| 1047 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1048 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1049 | return p; |
| 1050 | } |
| 1051 | |
| 1052 | stmt_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1053 | 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] | 1054 | int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1055 | { |
| 1056 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1057 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1058 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1059 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1060 | p->kind = TryExcept_kind; |
| 1061 | p->v.TryExcept.body = body; |
| 1062 | p->v.TryExcept.handlers = handlers; |
| 1063 | p->v.TryExcept.orelse = orelse; |
| 1064 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1065 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1066 | return p; |
| 1067 | } |
| 1068 | |
| 1069 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1070 | TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset, |
| 1071 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1072 | { |
| 1073 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1074 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1075 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1076 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1077 | p->kind = TryFinally_kind; |
| 1078 | p->v.TryFinally.body = body; |
| 1079 | p->v.TryFinally.finalbody = finalbody; |
| 1080 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1081 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1082 | return p; |
| 1083 | } |
| 1084 | |
| 1085 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1086 | 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] | 1087 | { |
| 1088 | stmt_ty p; |
| 1089 | if (!test) { |
| 1090 | PyErr_SetString(PyExc_ValueError, |
| 1091 | "field test is required for Assert"); |
| 1092 | return NULL; |
| 1093 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1094 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1095 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1096 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1097 | p->kind = Assert_kind; |
| 1098 | p->v.Assert.test = test; |
| 1099 | p->v.Assert.msg = msg; |
| 1100 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1101 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1102 | return p; |
| 1103 | } |
| 1104 | |
| 1105 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1106 | Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1107 | { |
| 1108 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1109 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1110 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1111 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1112 | p->kind = Import_kind; |
| 1113 | p->v.Import.names = names; |
| 1114 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1115 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1116 | return p; |
| 1117 | } |
| 1118 | |
| 1119 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1120 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
| 1121 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1122 | { |
| 1123 | stmt_ty p; |
| 1124 | if (!module) { |
| 1125 | PyErr_SetString(PyExc_ValueError, |
| 1126 | "field module is required for ImportFrom"); |
| 1127 | return NULL; |
| 1128 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1129 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1130 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1131 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1132 | p->kind = ImportFrom_kind; |
| 1133 | p->v.ImportFrom.module = module; |
| 1134 | p->v.ImportFrom.names = names; |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 1135 | p->v.ImportFrom.level = level; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1136 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1137 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1138 | return p; |
| 1139 | } |
| 1140 | |
| 1141 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1142 | Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, int col_offset, |
| 1143 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1144 | { |
| 1145 | stmt_ty p; |
| 1146 | if (!body) { |
| 1147 | PyErr_SetString(PyExc_ValueError, |
| 1148 | "field body is required for Exec"); |
| 1149 | return NULL; |
| 1150 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1151 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1152 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1153 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1154 | p->kind = Exec_kind; |
| 1155 | p->v.Exec.body = body; |
| 1156 | p->v.Exec.globals = globals; |
| 1157 | p->v.Exec.locals = locals; |
| 1158 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1159 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1160 | return p; |
| 1161 | } |
| 1162 | |
| 1163 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1164 | Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1165 | { |
| 1166 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1167 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1168 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1169 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1170 | p->kind = Global_kind; |
| 1171 | p->v.Global.names = names; |
| 1172 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1173 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1174 | return p; |
| 1175 | } |
| 1176 | |
| 1177 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1178 | Expr(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1179 | { |
| 1180 | stmt_ty p; |
| 1181 | if (!value) { |
| 1182 | PyErr_SetString(PyExc_ValueError, |
| 1183 | "field value is required for Expr"); |
| 1184 | return NULL; |
| 1185 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1186 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1187 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1188 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1189 | p->kind = Expr_kind; |
| 1190 | p->v.Expr.value = value; |
| 1191 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1192 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1193 | return p; |
| 1194 | } |
| 1195 | |
| 1196 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1197 | Pass(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1198 | { |
| 1199 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1200 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1201 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1202 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1203 | p->kind = Pass_kind; |
| 1204 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1205 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1206 | return p; |
| 1207 | } |
| 1208 | |
| 1209 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1210 | Break(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1211 | { |
| 1212 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1213 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1214 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1215 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1216 | p->kind = Break_kind; |
| 1217 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1218 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1219 | return p; |
| 1220 | } |
| 1221 | |
| 1222 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1223 | Continue(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1224 | { |
| 1225 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1226 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1227 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1228 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1229 | p->kind = Continue_kind; |
| 1230 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1231 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1232 | return p; |
| 1233 | } |
| 1234 | |
| 1235 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1236 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1237 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1238 | { |
| 1239 | expr_ty p; |
| 1240 | if (!op) { |
| 1241 | PyErr_SetString(PyExc_ValueError, |
| 1242 | "field op is required for BoolOp"); |
| 1243 | return NULL; |
| 1244 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1245 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1246 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1247 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1248 | p->kind = BoolOp_kind; |
| 1249 | p->v.BoolOp.op = op; |
| 1250 | p->v.BoolOp.values = values; |
| 1251 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1252 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1253 | return p; |
| 1254 | } |
| 1255 | |
| 1256 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1257 | BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset, |
| 1258 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1259 | { |
| 1260 | expr_ty p; |
| 1261 | if (!left) { |
| 1262 | PyErr_SetString(PyExc_ValueError, |
| 1263 | "field left is required for BinOp"); |
| 1264 | return NULL; |
| 1265 | } |
| 1266 | if (!op) { |
| 1267 | PyErr_SetString(PyExc_ValueError, |
| 1268 | "field op is required for BinOp"); |
| 1269 | return NULL; |
| 1270 | } |
| 1271 | if (!right) { |
| 1272 | PyErr_SetString(PyExc_ValueError, |
| 1273 | "field right is required for BinOp"); |
| 1274 | return NULL; |
| 1275 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1276 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1277 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1278 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1279 | p->kind = BinOp_kind; |
| 1280 | p->v.BinOp.left = left; |
| 1281 | p->v.BinOp.op = op; |
| 1282 | p->v.BinOp.right = right; |
| 1283 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1284 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1285 | return p; |
| 1286 | } |
| 1287 | |
| 1288 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1289 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena |
| 1290 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1291 | { |
| 1292 | expr_ty p; |
| 1293 | if (!op) { |
| 1294 | PyErr_SetString(PyExc_ValueError, |
| 1295 | "field op is required for UnaryOp"); |
| 1296 | return NULL; |
| 1297 | } |
| 1298 | if (!operand) { |
| 1299 | PyErr_SetString(PyExc_ValueError, |
| 1300 | "field operand is required for UnaryOp"); |
| 1301 | return NULL; |
| 1302 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1303 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1304 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1305 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1306 | p->kind = UnaryOp_kind; |
| 1307 | p->v.UnaryOp.op = op; |
| 1308 | p->v.UnaryOp.operand = operand; |
| 1309 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1310 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1311 | return p; |
| 1312 | } |
| 1313 | |
| 1314 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1315 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena |
| 1316 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1317 | { |
| 1318 | expr_ty p; |
| 1319 | if (!args) { |
| 1320 | PyErr_SetString(PyExc_ValueError, |
| 1321 | "field args is required for Lambda"); |
| 1322 | return NULL; |
| 1323 | } |
| 1324 | if (!body) { |
| 1325 | PyErr_SetString(PyExc_ValueError, |
| 1326 | "field body is required for Lambda"); |
| 1327 | return NULL; |
| 1328 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1329 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1330 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1331 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1332 | p->kind = Lambda_kind; |
| 1333 | p->v.Lambda.args = args; |
| 1334 | p->v.Lambda.body = body; |
| 1335 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1336 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1337 | return p; |
| 1338 | } |
| 1339 | |
| 1340 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1341 | IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset, |
| 1342 | PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1343 | { |
| 1344 | expr_ty p; |
| 1345 | if (!test) { |
| 1346 | PyErr_SetString(PyExc_ValueError, |
| 1347 | "field test is required for IfExp"); |
| 1348 | return NULL; |
| 1349 | } |
| 1350 | if (!body) { |
| 1351 | PyErr_SetString(PyExc_ValueError, |
| 1352 | "field body is required for IfExp"); |
| 1353 | return NULL; |
| 1354 | } |
| 1355 | if (!orelse) { |
| 1356 | PyErr_SetString(PyExc_ValueError, |
| 1357 | "field orelse is required for IfExp"); |
| 1358 | return NULL; |
| 1359 | } |
| 1360 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1361 | if (!p) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1362 | return NULL; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1363 | p->kind = IfExp_kind; |
| 1364 | p->v.IfExp.test = test; |
| 1365 | p->v.IfExp.body = body; |
| 1366 | p->v.IfExp.orelse = orelse; |
| 1367 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1368 | p->col_offset = col_offset; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1369 | return p; |
| 1370 | } |
| 1371 | |
| 1372 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1373 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1374 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1375 | { |
| 1376 | expr_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1377 | p = (expr_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 = Dict_kind; |
| 1381 | p->v.Dict.keys = keys; |
| 1382 | p->v.Dict.values = values; |
| 1383 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1384 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1385 | return p; |
| 1386 | } |
| 1387 | |
| 1388 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1389 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1390 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1391 | { |
| 1392 | expr_ty p; |
| 1393 | if (!elt) { |
| 1394 | PyErr_SetString(PyExc_ValueError, |
| 1395 | "field elt is required for ListComp"); |
| 1396 | return NULL; |
| 1397 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1398 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1399 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1400 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1401 | p->kind = ListComp_kind; |
| 1402 | p->v.ListComp.elt = elt; |
| 1403 | p->v.ListComp.generators = generators; |
| 1404 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1405 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1406 | return p; |
| 1407 | } |
| 1408 | |
| 1409 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1410 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1411 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1412 | { |
| 1413 | expr_ty p; |
| 1414 | if (!elt) { |
| 1415 | PyErr_SetString(PyExc_ValueError, |
| 1416 | "field elt is required for GeneratorExp"); |
| 1417 | return NULL; |
| 1418 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1419 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1420 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1421 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1422 | p->kind = GeneratorExp_kind; |
| 1423 | p->v.GeneratorExp.elt = elt; |
| 1424 | p->v.GeneratorExp.generators = generators; |
| 1425 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1426 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1427 | return p; |
| 1428 | } |
| 1429 | |
| 1430 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1431 | Yield(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1432 | { |
| 1433 | expr_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1434 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1435 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1436 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1437 | p->kind = Yield_kind; |
| 1438 | p->v.Yield.value = value; |
| 1439 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1440 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1441 | return p; |
| 1442 | } |
| 1443 | |
| 1444 | expr_ty |
Martin v. Löwis | 0cc56e5 | 2006-04-13 12:29:43 +0000 | [diff] [blame] | 1445 | Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno, |
| 1446 | int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1447 | { |
| 1448 | expr_ty p; |
| 1449 | if (!left) { |
| 1450 | PyErr_SetString(PyExc_ValueError, |
| 1451 | "field left is required for Compare"); |
| 1452 | return NULL; |
| 1453 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1454 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1455 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1456 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1457 | p->kind = Compare_kind; |
| 1458 | p->v.Compare.left = left; |
| 1459 | p->v.Compare.ops = ops; |
| 1460 | p->v.Compare.comparators = comparators; |
| 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 |
| 1467 | 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] | 1468 | expr_ty kwargs, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1469 | { |
| 1470 | expr_ty p; |
| 1471 | if (!func) { |
| 1472 | PyErr_SetString(PyExc_ValueError, |
| 1473 | "field func is required for Call"); |
| 1474 | return NULL; |
| 1475 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1476 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1477 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1478 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1479 | p->kind = Call_kind; |
| 1480 | p->v.Call.func = func; |
| 1481 | p->v.Call.args = args; |
| 1482 | p->v.Call.keywords = keywords; |
| 1483 | p->v.Call.starargs = starargs; |
| 1484 | p->v.Call.kwargs = kwargs; |
| 1485 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1486 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1487 | return p; |
| 1488 | } |
| 1489 | |
| 1490 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1491 | Repr(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1492 | { |
| 1493 | expr_ty p; |
| 1494 | if (!value) { |
| 1495 | PyErr_SetString(PyExc_ValueError, |
| 1496 | "field value is required for Repr"); |
| 1497 | return NULL; |
| 1498 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1499 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1500 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1501 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1502 | p->kind = Repr_kind; |
| 1503 | p->v.Repr.value = value; |
| 1504 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1505 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1506 | return p; |
| 1507 | } |
| 1508 | |
| 1509 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1510 | Num(object n, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1511 | { |
| 1512 | expr_ty p; |
| 1513 | if (!n) { |
| 1514 | PyErr_SetString(PyExc_ValueError, |
| 1515 | "field n is required for Num"); |
| 1516 | return NULL; |
| 1517 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1518 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1519 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1520 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1521 | p->kind = Num_kind; |
| 1522 | p->v.Num.n = n; |
| 1523 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1524 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1525 | return p; |
| 1526 | } |
| 1527 | |
| 1528 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1529 | Str(string s, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1530 | { |
| 1531 | expr_ty p; |
| 1532 | if (!s) { |
| 1533 | PyErr_SetString(PyExc_ValueError, |
| 1534 | "field s is required for Str"); |
| 1535 | return NULL; |
| 1536 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1537 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1538 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1539 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1540 | p->kind = Str_kind; |
| 1541 | p->v.Str.s = s; |
| 1542 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1543 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1544 | return p; |
| 1545 | } |
| 1546 | |
| 1547 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1548 | Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int |
| 1549 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1550 | { |
| 1551 | expr_ty p; |
| 1552 | if (!value) { |
| 1553 | PyErr_SetString(PyExc_ValueError, |
| 1554 | "field value is required for Attribute"); |
| 1555 | return NULL; |
| 1556 | } |
| 1557 | if (!attr) { |
| 1558 | PyErr_SetString(PyExc_ValueError, |
| 1559 | "field attr is required for Attribute"); |
| 1560 | return NULL; |
| 1561 | } |
| 1562 | if (!ctx) { |
| 1563 | PyErr_SetString(PyExc_ValueError, |
| 1564 | "field ctx is required for Attribute"); |
| 1565 | return NULL; |
| 1566 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1567 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1568 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1569 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1570 | p->kind = Attribute_kind; |
| 1571 | p->v.Attribute.value = value; |
| 1572 | p->v.Attribute.attr = attr; |
| 1573 | p->v.Attribute.ctx = ctx; |
| 1574 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1575 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1576 | return p; |
| 1577 | } |
| 1578 | |
| 1579 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1580 | Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int |
| 1581 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1582 | { |
| 1583 | expr_ty p; |
| 1584 | if (!value) { |
| 1585 | PyErr_SetString(PyExc_ValueError, |
| 1586 | "field value is required for Subscript"); |
| 1587 | return NULL; |
| 1588 | } |
| 1589 | if (!slice) { |
| 1590 | PyErr_SetString(PyExc_ValueError, |
| 1591 | "field slice is required for Subscript"); |
| 1592 | return NULL; |
| 1593 | } |
| 1594 | if (!ctx) { |
| 1595 | PyErr_SetString(PyExc_ValueError, |
| 1596 | "field ctx is required for Subscript"); |
| 1597 | return NULL; |
| 1598 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1599 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1600 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1601 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1602 | p->kind = Subscript_kind; |
| 1603 | p->v.Subscript.value = value; |
| 1604 | p->v.Subscript.slice = slice; |
| 1605 | p->v.Subscript.ctx = ctx; |
| 1606 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1607 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1608 | return p; |
| 1609 | } |
| 1610 | |
| 1611 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1612 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1613 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1614 | { |
| 1615 | expr_ty p; |
| 1616 | if (!id) { |
| 1617 | PyErr_SetString(PyExc_ValueError, |
| 1618 | "field id is required for Name"); |
| 1619 | return NULL; |
| 1620 | } |
| 1621 | if (!ctx) { |
| 1622 | PyErr_SetString(PyExc_ValueError, |
| 1623 | "field ctx is required for Name"); |
| 1624 | return NULL; |
| 1625 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1626 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1627 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1628 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1629 | p->kind = Name_kind; |
| 1630 | p->v.Name.id = id; |
| 1631 | p->v.Name.ctx = ctx; |
| 1632 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1633 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1634 | return p; |
| 1635 | } |
| 1636 | |
| 1637 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1638 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1639 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1640 | { |
| 1641 | expr_ty p; |
| 1642 | if (!ctx) { |
| 1643 | PyErr_SetString(PyExc_ValueError, |
| 1644 | "field ctx is required for List"); |
| 1645 | return NULL; |
| 1646 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1647 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1648 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1649 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1650 | p->kind = List_kind; |
| 1651 | p->v.List.elts = elts; |
| 1652 | p->v.List.ctx = ctx; |
| 1653 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1654 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1655 | return p; |
| 1656 | } |
| 1657 | |
| 1658 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1659 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1660 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1661 | { |
| 1662 | expr_ty p; |
| 1663 | if (!ctx) { |
| 1664 | PyErr_SetString(PyExc_ValueError, |
| 1665 | "field ctx is required for Tuple"); |
| 1666 | return NULL; |
| 1667 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1668 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1669 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1670 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1671 | p->kind = Tuple_kind; |
| 1672 | p->v.Tuple.elts = elts; |
| 1673 | p->v.Tuple.ctx = ctx; |
| 1674 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1675 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1676 | return p; |
| 1677 | } |
| 1678 | |
| 1679 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1680 | Ellipsis(PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1681 | { |
| 1682 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1683 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1684 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1685 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1686 | p->kind = Ellipsis_kind; |
| 1687 | return p; |
| 1688 | } |
| 1689 | |
| 1690 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1691 | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1692 | { |
| 1693 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1694 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1695 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1696 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1697 | p->kind = Slice_kind; |
| 1698 | p->v.Slice.lower = lower; |
| 1699 | p->v.Slice.upper = upper; |
| 1700 | p->v.Slice.step = step; |
| 1701 | return p; |
| 1702 | } |
| 1703 | |
| 1704 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1705 | ExtSlice(asdl_seq * dims, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1706 | { |
| 1707 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1708 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1709 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1710 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1711 | p->kind = ExtSlice_kind; |
| 1712 | p->v.ExtSlice.dims = dims; |
| 1713 | return p; |
| 1714 | } |
| 1715 | |
| 1716 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1717 | Index(expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1718 | { |
| 1719 | slice_ty p; |
| 1720 | if (!value) { |
| 1721 | PyErr_SetString(PyExc_ValueError, |
| 1722 | "field value is required for Index"); |
| 1723 | return NULL; |
| 1724 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1725 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1726 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1727 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1728 | p->kind = Index_kind; |
| 1729 | p->v.Index.value = value; |
| 1730 | return p; |
| 1731 | } |
| 1732 | |
| 1733 | comprehension_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1734 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1735 | { |
| 1736 | comprehension_ty p; |
| 1737 | if (!target) { |
| 1738 | PyErr_SetString(PyExc_ValueError, |
| 1739 | "field target is required for comprehension"); |
| 1740 | return NULL; |
| 1741 | } |
| 1742 | if (!iter) { |
| 1743 | PyErr_SetString(PyExc_ValueError, |
| 1744 | "field iter is required for comprehension"); |
| 1745 | return NULL; |
| 1746 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1747 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1748 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1749 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1750 | p->target = target; |
| 1751 | p->iter = iter; |
| 1752 | p->ifs = ifs; |
| 1753 | return p; |
| 1754 | } |
| 1755 | |
| 1756 | excepthandler_ty |
Jeremy Hylton | 2f327c1 | 2006-04-04 04:00:23 +0000 | [diff] [blame] | 1757 | excepthandler(expr_ty type, expr_ty name, asdl_seq * body, int lineno, int |
| 1758 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1759 | { |
| 1760 | excepthandler_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1761 | p = (excepthandler_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->type = type; |
| 1765 | p->name = name; |
| 1766 | p->body = body; |
Jeremy Hylton | 2f327c1 | 2006-04-04 04:00:23 +0000 | [diff] [blame] | 1767 | p->lineno = lineno; |
| 1768 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1769 | return p; |
| 1770 | } |
| 1771 | |
| 1772 | arguments_ty |
| 1773 | arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq * |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1774 | defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1775 | { |
| 1776 | arguments_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1777 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1778 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1779 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1780 | p->args = args; |
| 1781 | p->vararg = vararg; |
| 1782 | p->kwarg = kwarg; |
| 1783 | p->defaults = defaults; |
| 1784 | return p; |
| 1785 | } |
| 1786 | |
| 1787 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1788 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1789 | { |
| 1790 | keyword_ty p; |
| 1791 | if (!arg) { |
| 1792 | PyErr_SetString(PyExc_ValueError, |
| 1793 | "field arg is required for keyword"); |
| 1794 | return NULL; |
| 1795 | } |
| 1796 | if (!value) { |
| 1797 | PyErr_SetString(PyExc_ValueError, |
| 1798 | "field value is required for keyword"); |
| 1799 | return NULL; |
| 1800 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1801 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1802 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1803 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1804 | p->arg = arg; |
| 1805 | p->value = value; |
| 1806 | return p; |
| 1807 | } |
| 1808 | |
| 1809 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1810 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1811 | { |
| 1812 | alias_ty p; |
| 1813 | if (!name) { |
| 1814 | PyErr_SetString(PyExc_ValueError, |
| 1815 | "field name is required for alias"); |
| 1816 | return NULL; |
| 1817 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1818 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
Neal Norwitz | 7b7d1c8 | 2007-02-26 18:10:47 +0000 | [diff] [blame] | 1819 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1820 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1821 | p->name = name; |
| 1822 | p->asname = asname; |
| 1823 | return p; |
| 1824 | } |
| 1825 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 1826 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1827 | PyObject* |
| 1828 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 1829 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1830 | mod_ty o = (mod_ty)_o; |
| 1831 | PyObject *result = NULL, *value = NULL; |
| 1832 | if (!o) { |
| 1833 | Py_INCREF(Py_None); |
| 1834 | return Py_None; |
| 1835 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 1836 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1837 | switch (o->kind) { |
| 1838 | case Module_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1839 | result = PyType_GenericNew(Module_type, NULL, NULL); |
| 1840 | if (!result) goto failed; |
| 1841 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 1842 | if (!value) goto failed; |
| 1843 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 1844 | goto failed; |
| 1845 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1846 | break; |
| 1847 | case Interactive_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1848 | result = PyType_GenericNew(Interactive_type, NULL, NULL); |
| 1849 | if (!result) goto failed; |
| 1850 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 1851 | if (!value) goto failed; |
| 1852 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 1853 | goto failed; |
| 1854 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1855 | break; |
| 1856 | case Expression_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1857 | result = PyType_GenericNew(Expression_type, NULL, NULL); |
| 1858 | if (!result) goto failed; |
| 1859 | value = ast2obj_expr(o->v.Expression.body); |
| 1860 | if (!value) goto failed; |
| 1861 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 1862 | goto failed; |
| 1863 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1864 | break; |
| 1865 | case Suite_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1866 | result = PyType_GenericNew(Suite_type, NULL, NULL); |
| 1867 | if (!result) goto failed; |
| 1868 | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
| 1869 | if (!value) goto failed; |
| 1870 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 1871 | goto failed; |
| 1872 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1873 | break; |
| 1874 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1875 | return result; |
| 1876 | failed: |
| 1877 | Py_XDECREF(value); |
| 1878 | Py_XDECREF(result); |
| 1879 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1880 | } |
| 1881 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1882 | PyObject* |
| 1883 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1884 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1885 | stmt_ty o = (stmt_ty)_o; |
| 1886 | PyObject *result = NULL, *value = NULL; |
| 1887 | if (!o) { |
| 1888 | Py_INCREF(Py_None); |
| 1889 | return Py_None; |
| 1890 | } |
| 1891 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1892 | switch (o->kind) { |
| 1893 | case FunctionDef_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1894 | result = PyType_GenericNew(FunctionDef_type, NULL, NULL); |
| 1895 | if (!result) goto failed; |
| 1896 | value = ast2obj_identifier(o->v.FunctionDef.name); |
| 1897 | if (!value) goto failed; |
| 1898 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 1899 | goto failed; |
| 1900 | Py_DECREF(value); |
| 1901 | value = ast2obj_arguments(o->v.FunctionDef.args); |
| 1902 | if (!value) goto failed; |
| 1903 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 1904 | goto failed; |
| 1905 | Py_DECREF(value); |
| 1906 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 1907 | if (!value) goto failed; |
| 1908 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 1909 | goto failed; |
| 1910 | Py_DECREF(value); |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 1911 | value = ast2obj_list(o->v.FunctionDef.decorator_list, |
| 1912 | ast2obj_expr); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1913 | if (!value) goto failed; |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 1914 | if (PyObject_SetAttrString(result, "decorator_list", value) == |
| 1915 | -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1916 | goto failed; |
| 1917 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1918 | break; |
| 1919 | case ClassDef_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1920 | result = PyType_GenericNew(ClassDef_type, NULL, NULL); |
| 1921 | if (!result) goto failed; |
| 1922 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 1923 | if (!value) goto failed; |
| 1924 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 1925 | goto failed; |
| 1926 | Py_DECREF(value); |
| 1927 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 1928 | if (!value) goto failed; |
| 1929 | if (PyObject_SetAttrString(result, "bases", value) == -1) |
| 1930 | goto failed; |
| 1931 | Py_DECREF(value); |
| 1932 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 1933 | if (!value) goto failed; |
| 1934 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 1935 | goto failed; |
| 1936 | Py_DECREF(value); |
Christian Heimes | 5224d28 | 2008-02-23 15:01:05 +0000 | [diff] [blame] | 1937 | value = ast2obj_list(o->v.ClassDef.decorator_list, |
| 1938 | ast2obj_expr); |
| 1939 | if (!value) goto failed; |
| 1940 | if (PyObject_SetAttrString(result, "decorator_list", value) == |
| 1941 | -1) |
| 1942 | goto failed; |
| 1943 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1944 | break; |
| 1945 | case Return_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1946 | result = PyType_GenericNew(Return_type, NULL, NULL); |
| 1947 | if (!result) goto failed; |
| 1948 | value = ast2obj_expr(o->v.Return.value); |
| 1949 | if (!value) goto failed; |
| 1950 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 1951 | goto failed; |
| 1952 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1953 | break; |
| 1954 | case Delete_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1955 | result = PyType_GenericNew(Delete_type, NULL, NULL); |
| 1956 | if (!result) goto failed; |
| 1957 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 1958 | if (!value) goto failed; |
| 1959 | if (PyObject_SetAttrString(result, "targets", value) == -1) |
| 1960 | goto failed; |
| 1961 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1962 | break; |
| 1963 | case Assign_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1964 | result = PyType_GenericNew(Assign_type, NULL, NULL); |
| 1965 | if (!result) goto failed; |
| 1966 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 1967 | if (!value) goto failed; |
| 1968 | if (PyObject_SetAttrString(result, "targets", value) == -1) |
| 1969 | goto failed; |
| 1970 | Py_DECREF(value); |
| 1971 | value = ast2obj_expr(o->v.Assign.value); |
| 1972 | if (!value) goto failed; |
| 1973 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 1974 | goto failed; |
| 1975 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1976 | break; |
| 1977 | case AugAssign_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1978 | result = PyType_GenericNew(AugAssign_type, NULL, NULL); |
| 1979 | if (!result) goto failed; |
| 1980 | value = ast2obj_expr(o->v.AugAssign.target); |
| 1981 | if (!value) goto failed; |
| 1982 | if (PyObject_SetAttrString(result, "target", value) == -1) |
| 1983 | goto failed; |
| 1984 | Py_DECREF(value); |
| 1985 | value = ast2obj_operator(o->v.AugAssign.op); |
| 1986 | if (!value) goto failed; |
| 1987 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 1988 | goto failed; |
| 1989 | Py_DECREF(value); |
| 1990 | value = ast2obj_expr(o->v.AugAssign.value); |
| 1991 | if (!value) goto failed; |
| 1992 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 1993 | goto failed; |
| 1994 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1995 | break; |
| 1996 | case Print_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1997 | result = PyType_GenericNew(Print_type, NULL, NULL); |
| 1998 | if (!result) goto failed; |
| 1999 | value = ast2obj_expr(o->v.Print.dest); |
| 2000 | if (!value) goto failed; |
| 2001 | if (PyObject_SetAttrString(result, "dest", value) == -1) |
| 2002 | goto failed; |
| 2003 | Py_DECREF(value); |
| 2004 | value = ast2obj_list(o->v.Print.values, ast2obj_expr); |
| 2005 | if (!value) goto failed; |
| 2006 | if (PyObject_SetAttrString(result, "values", value) == -1) |
| 2007 | goto failed; |
| 2008 | Py_DECREF(value); |
| 2009 | value = ast2obj_bool(o->v.Print.nl); |
| 2010 | if (!value) goto failed; |
| 2011 | if (PyObject_SetAttrString(result, "nl", value) == -1) |
| 2012 | goto failed; |
| 2013 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2014 | break; |
| 2015 | case For_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2016 | result = PyType_GenericNew(For_type, NULL, NULL); |
| 2017 | if (!result) goto failed; |
| 2018 | value = ast2obj_expr(o->v.For.target); |
| 2019 | if (!value) goto failed; |
| 2020 | if (PyObject_SetAttrString(result, "target", value) == -1) |
| 2021 | goto failed; |
| 2022 | Py_DECREF(value); |
| 2023 | value = ast2obj_expr(o->v.For.iter); |
| 2024 | if (!value) goto failed; |
| 2025 | if (PyObject_SetAttrString(result, "iter", value) == -1) |
| 2026 | goto failed; |
| 2027 | Py_DECREF(value); |
| 2028 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 2029 | if (!value) goto failed; |
| 2030 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2031 | goto failed; |
| 2032 | Py_DECREF(value); |
| 2033 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 2034 | if (!value) goto failed; |
| 2035 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2036 | goto failed; |
| 2037 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2038 | break; |
| 2039 | case While_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2040 | result = PyType_GenericNew(While_type, NULL, NULL); |
| 2041 | if (!result) goto failed; |
| 2042 | value = ast2obj_expr(o->v.While.test); |
| 2043 | if (!value) goto failed; |
| 2044 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2045 | goto failed; |
| 2046 | Py_DECREF(value); |
| 2047 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 2048 | if (!value) goto failed; |
| 2049 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2050 | goto failed; |
| 2051 | Py_DECREF(value); |
| 2052 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 2053 | if (!value) goto failed; |
| 2054 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2055 | goto failed; |
| 2056 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2057 | break; |
| 2058 | case If_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2059 | result = PyType_GenericNew(If_type, NULL, NULL); |
| 2060 | if (!result) goto failed; |
| 2061 | value = ast2obj_expr(o->v.If.test); |
| 2062 | if (!value) goto failed; |
| 2063 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2064 | goto failed; |
| 2065 | Py_DECREF(value); |
| 2066 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 2067 | if (!value) goto failed; |
| 2068 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2069 | goto failed; |
| 2070 | Py_DECREF(value); |
| 2071 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 2072 | if (!value) goto failed; |
| 2073 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2074 | goto failed; |
| 2075 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2076 | break; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2077 | case With_kind: |
| 2078 | result = PyType_GenericNew(With_type, NULL, NULL); |
| 2079 | if (!result) goto failed; |
| 2080 | value = ast2obj_expr(o->v.With.context_expr); |
| 2081 | if (!value) goto failed; |
| 2082 | if (PyObject_SetAttrString(result, "context_expr", value) == -1) |
| 2083 | goto failed; |
| 2084 | Py_DECREF(value); |
| 2085 | value = ast2obj_expr(o->v.With.optional_vars); |
| 2086 | if (!value) goto failed; |
| 2087 | if (PyObject_SetAttrString(result, "optional_vars", value) == |
| 2088 | -1) |
| 2089 | goto failed; |
| 2090 | Py_DECREF(value); |
| 2091 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 2092 | if (!value) goto failed; |
| 2093 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2094 | goto failed; |
| 2095 | Py_DECREF(value); |
| 2096 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2097 | case Raise_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2098 | result = PyType_GenericNew(Raise_type, NULL, NULL); |
| 2099 | if (!result) goto failed; |
| 2100 | value = ast2obj_expr(o->v.Raise.type); |
| 2101 | if (!value) goto failed; |
| 2102 | if (PyObject_SetAttrString(result, "type", value) == -1) |
| 2103 | goto failed; |
| 2104 | Py_DECREF(value); |
| 2105 | value = ast2obj_expr(o->v.Raise.inst); |
| 2106 | if (!value) goto failed; |
| 2107 | if (PyObject_SetAttrString(result, "inst", value) == -1) |
| 2108 | goto failed; |
| 2109 | Py_DECREF(value); |
| 2110 | value = ast2obj_expr(o->v.Raise.tback); |
| 2111 | if (!value) goto failed; |
| 2112 | if (PyObject_SetAttrString(result, "tback", value) == -1) |
| 2113 | goto failed; |
| 2114 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2115 | break; |
| 2116 | case TryExcept_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2117 | result = PyType_GenericNew(TryExcept_type, NULL, NULL); |
| 2118 | if (!result) goto failed; |
| 2119 | value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt); |
| 2120 | if (!value) goto failed; |
| 2121 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2122 | goto failed; |
| 2123 | Py_DECREF(value); |
| 2124 | value = ast2obj_list(o->v.TryExcept.handlers, |
| 2125 | ast2obj_excepthandler); |
| 2126 | if (!value) goto failed; |
| 2127 | if (PyObject_SetAttrString(result, "handlers", value) == -1) |
| 2128 | goto failed; |
| 2129 | Py_DECREF(value); |
| 2130 | value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt); |
| 2131 | if (!value) goto failed; |
| 2132 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2133 | goto failed; |
| 2134 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2135 | break; |
| 2136 | case TryFinally_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2137 | result = PyType_GenericNew(TryFinally_type, NULL, NULL); |
| 2138 | if (!result) goto failed; |
| 2139 | value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt); |
| 2140 | if (!value) goto failed; |
| 2141 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2142 | goto failed; |
| 2143 | Py_DECREF(value); |
| 2144 | value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt); |
| 2145 | if (!value) goto failed; |
| 2146 | if (PyObject_SetAttrString(result, "finalbody", value) == -1) |
| 2147 | goto failed; |
| 2148 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2149 | break; |
| 2150 | case Assert_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2151 | result = PyType_GenericNew(Assert_type, NULL, NULL); |
| 2152 | if (!result) goto failed; |
| 2153 | value = ast2obj_expr(o->v.Assert.test); |
| 2154 | if (!value) goto failed; |
| 2155 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2156 | goto failed; |
| 2157 | Py_DECREF(value); |
| 2158 | value = ast2obj_expr(o->v.Assert.msg); |
| 2159 | if (!value) goto failed; |
| 2160 | if (PyObject_SetAttrString(result, "msg", value) == -1) |
| 2161 | goto failed; |
| 2162 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2163 | break; |
| 2164 | case Import_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2165 | result = PyType_GenericNew(Import_type, NULL, NULL); |
| 2166 | if (!result) goto failed; |
| 2167 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 2168 | if (!value) goto failed; |
| 2169 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2170 | goto failed; |
| 2171 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2172 | break; |
| 2173 | case ImportFrom_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2174 | result = PyType_GenericNew(ImportFrom_type, NULL, NULL); |
| 2175 | if (!result) goto failed; |
| 2176 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 2177 | if (!value) goto failed; |
| 2178 | if (PyObject_SetAttrString(result, "module", value) == -1) |
| 2179 | goto failed; |
| 2180 | Py_DECREF(value); |
| 2181 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 2182 | if (!value) goto failed; |
| 2183 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2184 | goto failed; |
| 2185 | Py_DECREF(value); |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 2186 | value = ast2obj_int(o->v.ImportFrom.level); |
| 2187 | if (!value) goto failed; |
| 2188 | if (PyObject_SetAttrString(result, "level", value) == -1) |
| 2189 | goto failed; |
| 2190 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2191 | break; |
| 2192 | case Exec_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2193 | result = PyType_GenericNew(Exec_type, NULL, NULL); |
| 2194 | if (!result) goto failed; |
| 2195 | value = ast2obj_expr(o->v.Exec.body); |
| 2196 | if (!value) goto failed; |
| 2197 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2198 | goto failed; |
| 2199 | Py_DECREF(value); |
| 2200 | value = ast2obj_expr(o->v.Exec.globals); |
| 2201 | if (!value) goto failed; |
| 2202 | if (PyObject_SetAttrString(result, "globals", value) == -1) |
| 2203 | goto failed; |
| 2204 | Py_DECREF(value); |
| 2205 | value = ast2obj_expr(o->v.Exec.locals); |
| 2206 | if (!value) goto failed; |
| 2207 | if (PyObject_SetAttrString(result, "locals", value) == -1) |
| 2208 | goto failed; |
| 2209 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2210 | break; |
| 2211 | case Global_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2212 | result = PyType_GenericNew(Global_type, NULL, NULL); |
| 2213 | if (!result) goto failed; |
| 2214 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 2215 | if (!value) goto failed; |
| 2216 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2217 | goto failed; |
| 2218 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2219 | break; |
| 2220 | case Expr_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2221 | result = PyType_GenericNew(Expr_type, NULL, NULL); |
| 2222 | if (!result) goto failed; |
| 2223 | value = ast2obj_expr(o->v.Expr.value); |
| 2224 | if (!value) goto failed; |
| 2225 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2226 | goto failed; |
| 2227 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2228 | break; |
| 2229 | case Pass_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2230 | result = PyType_GenericNew(Pass_type, NULL, NULL); |
| 2231 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2232 | break; |
| 2233 | case Break_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2234 | result = PyType_GenericNew(Break_type, NULL, NULL); |
| 2235 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2236 | break; |
| 2237 | case Continue_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2238 | result = PyType_GenericNew(Continue_type, NULL, NULL); |
| 2239 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2240 | break; |
| 2241 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2242 | value = ast2obj_int(o->lineno); |
| 2243 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2244 | if (PyObject_SetAttrString(result, "lineno", value) < 0) |
| 2245 | goto failed; |
| 2246 | Py_DECREF(value); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2247 | value = ast2obj_int(o->col_offset); |
| 2248 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2249 | if (PyObject_SetAttrString(result, "col_offset", value) < 0) |
| 2250 | goto failed; |
| 2251 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2252 | return result; |
| 2253 | failed: |
| 2254 | Py_XDECREF(value); |
| 2255 | Py_XDECREF(result); |
| 2256 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2257 | } |
| 2258 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2259 | PyObject* |
| 2260 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2261 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2262 | expr_ty o = (expr_ty)_o; |
| 2263 | PyObject *result = NULL, *value = NULL; |
| 2264 | if (!o) { |
| 2265 | Py_INCREF(Py_None); |
| 2266 | return Py_None; |
| 2267 | } |
| 2268 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2269 | switch (o->kind) { |
| 2270 | case BoolOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2271 | result = PyType_GenericNew(BoolOp_type, NULL, NULL); |
| 2272 | if (!result) goto failed; |
| 2273 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 2274 | if (!value) goto failed; |
| 2275 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2276 | goto failed; |
| 2277 | Py_DECREF(value); |
| 2278 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 2279 | if (!value) goto failed; |
| 2280 | if (PyObject_SetAttrString(result, "values", value) == -1) |
| 2281 | goto failed; |
| 2282 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2283 | break; |
| 2284 | case BinOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2285 | result = PyType_GenericNew(BinOp_type, NULL, NULL); |
| 2286 | if (!result) goto failed; |
| 2287 | value = ast2obj_expr(o->v.BinOp.left); |
| 2288 | if (!value) goto failed; |
| 2289 | if (PyObject_SetAttrString(result, "left", value) == -1) |
| 2290 | goto failed; |
| 2291 | Py_DECREF(value); |
| 2292 | value = ast2obj_operator(o->v.BinOp.op); |
| 2293 | if (!value) goto failed; |
| 2294 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2295 | goto failed; |
| 2296 | Py_DECREF(value); |
| 2297 | value = ast2obj_expr(o->v.BinOp.right); |
| 2298 | if (!value) goto failed; |
| 2299 | if (PyObject_SetAttrString(result, "right", value) == -1) |
| 2300 | goto failed; |
| 2301 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2302 | break; |
| 2303 | case UnaryOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2304 | result = PyType_GenericNew(UnaryOp_type, NULL, NULL); |
| 2305 | if (!result) goto failed; |
| 2306 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 2307 | if (!value) goto failed; |
| 2308 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2309 | goto failed; |
| 2310 | Py_DECREF(value); |
| 2311 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 2312 | if (!value) goto failed; |
| 2313 | if (PyObject_SetAttrString(result, "operand", value) == -1) |
| 2314 | goto failed; |
| 2315 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2316 | break; |
| 2317 | case Lambda_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2318 | result = PyType_GenericNew(Lambda_type, NULL, NULL); |
| 2319 | if (!result) goto failed; |
| 2320 | value = ast2obj_arguments(o->v.Lambda.args); |
| 2321 | if (!value) goto failed; |
| 2322 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 2323 | goto failed; |
| 2324 | Py_DECREF(value); |
| 2325 | value = ast2obj_expr(o->v.Lambda.body); |
| 2326 | if (!value) goto failed; |
| 2327 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2328 | goto failed; |
| 2329 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2330 | break; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2331 | case IfExp_kind: |
| 2332 | result = PyType_GenericNew(IfExp_type, NULL, NULL); |
| 2333 | if (!result) goto failed; |
| 2334 | value = ast2obj_expr(o->v.IfExp.test); |
| 2335 | if (!value) goto failed; |
| 2336 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2337 | goto failed; |
| 2338 | Py_DECREF(value); |
| 2339 | value = ast2obj_expr(o->v.IfExp.body); |
| 2340 | if (!value) goto failed; |
| 2341 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2342 | goto failed; |
| 2343 | Py_DECREF(value); |
| 2344 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 2345 | if (!value) goto failed; |
| 2346 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2347 | goto failed; |
| 2348 | Py_DECREF(value); |
| 2349 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2350 | case Dict_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2351 | result = PyType_GenericNew(Dict_type, NULL, NULL); |
| 2352 | if (!result) goto failed; |
| 2353 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 2354 | if (!value) goto failed; |
| 2355 | if (PyObject_SetAttrString(result, "keys", value) == -1) |
| 2356 | goto failed; |
| 2357 | Py_DECREF(value); |
| 2358 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 2359 | if (!value) goto failed; |
| 2360 | if (PyObject_SetAttrString(result, "values", value) == -1) |
| 2361 | goto failed; |
| 2362 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2363 | break; |
| 2364 | case ListComp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2365 | result = PyType_GenericNew(ListComp_type, NULL, NULL); |
| 2366 | if (!result) goto failed; |
| 2367 | value = ast2obj_expr(o->v.ListComp.elt); |
| 2368 | if (!value) goto failed; |
| 2369 | if (PyObject_SetAttrString(result, "elt", value) == -1) |
| 2370 | goto failed; |
| 2371 | Py_DECREF(value); |
| 2372 | value = ast2obj_list(o->v.ListComp.generators, |
| 2373 | ast2obj_comprehension); |
| 2374 | if (!value) goto failed; |
| 2375 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2376 | goto failed; |
| 2377 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2378 | break; |
| 2379 | case GeneratorExp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2380 | result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); |
| 2381 | if (!result) goto failed; |
| 2382 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 2383 | if (!value) goto failed; |
| 2384 | if (PyObject_SetAttrString(result, "elt", value) == -1) |
| 2385 | goto failed; |
| 2386 | Py_DECREF(value); |
| 2387 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 2388 | ast2obj_comprehension); |
| 2389 | if (!value) goto failed; |
| 2390 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2391 | goto failed; |
| 2392 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2393 | break; |
| 2394 | case Yield_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2395 | result = PyType_GenericNew(Yield_type, NULL, NULL); |
| 2396 | if (!result) goto failed; |
| 2397 | value = ast2obj_expr(o->v.Yield.value); |
| 2398 | if (!value) goto failed; |
| 2399 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2400 | goto failed; |
| 2401 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2402 | break; |
| 2403 | case Compare_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2404 | result = PyType_GenericNew(Compare_type, NULL, NULL); |
| 2405 | if (!result) goto failed; |
| 2406 | value = ast2obj_expr(o->v.Compare.left); |
| 2407 | if (!value) goto failed; |
| 2408 | if (PyObject_SetAttrString(result, "left", value) == -1) |
| 2409 | goto failed; |
| 2410 | Py_DECREF(value); |
Martin v. Löwis | ce1d5d2 | 2006-02-26 20:51:25 +0000 | [diff] [blame] | 2411 | { |
| 2412 | int i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 2413 | value = PyList_New(n); |
| 2414 | if (!value) goto failed; |
| 2415 | for(i = 0; i < n; i++) |
Martin v. Löwis | 0cc56e5 | 2006-04-13 12:29:43 +0000 | [diff] [blame] | 2416 | 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] | 2417 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2418 | if (!value) goto failed; |
| 2419 | if (PyObject_SetAttrString(result, "ops", value) == -1) |
| 2420 | goto failed; |
| 2421 | Py_DECREF(value); |
| 2422 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
| 2423 | if (!value) goto failed; |
| 2424 | if (PyObject_SetAttrString(result, "comparators", value) == -1) |
| 2425 | goto failed; |
| 2426 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2427 | break; |
| 2428 | case Call_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2429 | result = PyType_GenericNew(Call_type, NULL, NULL); |
| 2430 | if (!result) goto failed; |
| 2431 | value = ast2obj_expr(o->v.Call.func); |
| 2432 | if (!value) goto failed; |
| 2433 | if (PyObject_SetAttrString(result, "func", value) == -1) |
| 2434 | goto failed; |
| 2435 | Py_DECREF(value); |
| 2436 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 2437 | if (!value) goto failed; |
| 2438 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 2439 | goto failed; |
| 2440 | Py_DECREF(value); |
| 2441 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 2442 | if (!value) goto failed; |
| 2443 | if (PyObject_SetAttrString(result, "keywords", value) == -1) |
| 2444 | goto failed; |
| 2445 | Py_DECREF(value); |
| 2446 | value = ast2obj_expr(o->v.Call.starargs); |
| 2447 | if (!value) goto failed; |
| 2448 | if (PyObject_SetAttrString(result, "starargs", value) == -1) |
| 2449 | goto failed; |
| 2450 | Py_DECREF(value); |
| 2451 | value = ast2obj_expr(o->v.Call.kwargs); |
| 2452 | if (!value) goto failed; |
| 2453 | if (PyObject_SetAttrString(result, "kwargs", value) == -1) |
| 2454 | goto failed; |
| 2455 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2456 | break; |
| 2457 | case Repr_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2458 | result = PyType_GenericNew(Repr_type, NULL, NULL); |
| 2459 | if (!result) goto failed; |
| 2460 | value = ast2obj_expr(o->v.Repr.value); |
| 2461 | if (!value) goto failed; |
| 2462 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2463 | goto failed; |
| 2464 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2465 | break; |
| 2466 | case Num_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2467 | result = PyType_GenericNew(Num_type, NULL, NULL); |
| 2468 | if (!result) goto failed; |
| 2469 | value = ast2obj_object(o->v.Num.n); |
| 2470 | if (!value) goto failed; |
| 2471 | if (PyObject_SetAttrString(result, "n", value) == -1) |
| 2472 | goto failed; |
| 2473 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2474 | break; |
| 2475 | case Str_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2476 | result = PyType_GenericNew(Str_type, NULL, NULL); |
| 2477 | if (!result) goto failed; |
| 2478 | value = ast2obj_string(o->v.Str.s); |
| 2479 | if (!value) goto failed; |
| 2480 | if (PyObject_SetAttrString(result, "s", value) == -1) |
| 2481 | goto failed; |
| 2482 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2483 | break; |
| 2484 | case Attribute_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2485 | result = PyType_GenericNew(Attribute_type, NULL, NULL); |
| 2486 | if (!result) goto failed; |
| 2487 | value = ast2obj_expr(o->v.Attribute.value); |
| 2488 | if (!value) goto failed; |
| 2489 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2490 | goto failed; |
| 2491 | Py_DECREF(value); |
| 2492 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 2493 | if (!value) goto failed; |
| 2494 | if (PyObject_SetAttrString(result, "attr", value) == -1) |
| 2495 | goto failed; |
| 2496 | Py_DECREF(value); |
| 2497 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 2498 | if (!value) goto failed; |
| 2499 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2500 | goto failed; |
| 2501 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2502 | break; |
| 2503 | case Subscript_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2504 | result = PyType_GenericNew(Subscript_type, NULL, NULL); |
| 2505 | if (!result) goto failed; |
| 2506 | value = ast2obj_expr(o->v.Subscript.value); |
| 2507 | if (!value) goto failed; |
| 2508 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2509 | goto failed; |
| 2510 | Py_DECREF(value); |
| 2511 | value = ast2obj_slice(o->v.Subscript.slice); |
| 2512 | if (!value) goto failed; |
| 2513 | if (PyObject_SetAttrString(result, "slice", value) == -1) |
| 2514 | goto failed; |
| 2515 | Py_DECREF(value); |
| 2516 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 2517 | if (!value) goto failed; |
| 2518 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2519 | goto failed; |
| 2520 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2521 | break; |
| 2522 | case Name_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2523 | result = PyType_GenericNew(Name_type, NULL, NULL); |
| 2524 | if (!result) goto failed; |
| 2525 | value = ast2obj_identifier(o->v.Name.id); |
| 2526 | if (!value) goto failed; |
| 2527 | if (PyObject_SetAttrString(result, "id", value) == -1) |
| 2528 | goto failed; |
| 2529 | Py_DECREF(value); |
| 2530 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 2531 | if (!value) goto failed; |
| 2532 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2533 | goto failed; |
| 2534 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2535 | break; |
| 2536 | case List_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2537 | result = PyType_GenericNew(List_type, NULL, NULL); |
| 2538 | if (!result) goto failed; |
| 2539 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 2540 | if (!value) goto failed; |
| 2541 | if (PyObject_SetAttrString(result, "elts", value) == -1) |
| 2542 | goto failed; |
| 2543 | Py_DECREF(value); |
| 2544 | value = ast2obj_expr_context(o->v.List.ctx); |
| 2545 | if (!value) goto failed; |
| 2546 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2547 | goto failed; |
| 2548 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2549 | break; |
| 2550 | case Tuple_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2551 | result = PyType_GenericNew(Tuple_type, NULL, NULL); |
| 2552 | if (!result) goto failed; |
| 2553 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 2554 | if (!value) goto failed; |
| 2555 | if (PyObject_SetAttrString(result, "elts", value) == -1) |
| 2556 | goto failed; |
| 2557 | Py_DECREF(value); |
| 2558 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 2559 | if (!value) goto failed; |
| 2560 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2561 | goto failed; |
| 2562 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2563 | break; |
| 2564 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2565 | value = ast2obj_int(o->lineno); |
| 2566 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2567 | if (PyObject_SetAttrString(result, "lineno", value) < 0) |
| 2568 | goto failed; |
| 2569 | Py_DECREF(value); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2570 | value = ast2obj_int(o->col_offset); |
| 2571 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2572 | if (PyObject_SetAttrString(result, "col_offset", value) < 0) |
| 2573 | goto failed; |
| 2574 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2575 | return result; |
| 2576 | failed: |
| 2577 | Py_XDECREF(value); |
| 2578 | Py_XDECREF(result); |
| 2579 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2580 | } |
| 2581 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2582 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2583 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2584 | switch(o) { |
| 2585 | case Load: |
| 2586 | Py_INCREF(Load_singleton); |
| 2587 | return Load_singleton; |
| 2588 | case Store: |
| 2589 | Py_INCREF(Store_singleton); |
| 2590 | return Store_singleton; |
| 2591 | case Del: |
| 2592 | Py_INCREF(Del_singleton); |
| 2593 | return Del_singleton; |
| 2594 | case AugLoad: |
| 2595 | Py_INCREF(AugLoad_singleton); |
| 2596 | return AugLoad_singleton; |
| 2597 | case AugStore: |
| 2598 | Py_INCREF(AugStore_singleton); |
| 2599 | return AugStore_singleton; |
| 2600 | case Param: |
| 2601 | Py_INCREF(Param_singleton); |
| 2602 | return Param_singleton; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2603 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2604 | return NULL; /* cannot happen */ |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2605 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2606 | PyObject* |
| 2607 | ast2obj_slice(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2608 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2609 | slice_ty o = (slice_ty)_o; |
| 2610 | PyObject *result = NULL, *value = NULL; |
| 2611 | if (!o) { |
| 2612 | Py_INCREF(Py_None); |
| 2613 | return Py_None; |
| 2614 | } |
| 2615 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2616 | switch (o->kind) { |
| 2617 | case Ellipsis_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2618 | result = PyType_GenericNew(Ellipsis_type, NULL, NULL); |
| 2619 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2620 | break; |
| 2621 | case Slice_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2622 | result = PyType_GenericNew(Slice_type, NULL, NULL); |
| 2623 | if (!result) goto failed; |
| 2624 | value = ast2obj_expr(o->v.Slice.lower); |
| 2625 | if (!value) goto failed; |
| 2626 | if (PyObject_SetAttrString(result, "lower", value) == -1) |
| 2627 | goto failed; |
| 2628 | Py_DECREF(value); |
| 2629 | value = ast2obj_expr(o->v.Slice.upper); |
| 2630 | if (!value) goto failed; |
| 2631 | if (PyObject_SetAttrString(result, "upper", value) == -1) |
| 2632 | goto failed; |
| 2633 | Py_DECREF(value); |
| 2634 | value = ast2obj_expr(o->v.Slice.step); |
| 2635 | if (!value) goto failed; |
| 2636 | if (PyObject_SetAttrString(result, "step", value) == -1) |
| 2637 | goto failed; |
| 2638 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2639 | break; |
| 2640 | case ExtSlice_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2641 | result = PyType_GenericNew(ExtSlice_type, NULL, NULL); |
| 2642 | if (!result) goto failed; |
| 2643 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 2644 | if (!value) goto failed; |
| 2645 | if (PyObject_SetAttrString(result, "dims", value) == -1) |
| 2646 | goto failed; |
| 2647 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2648 | break; |
| 2649 | case Index_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2650 | result = PyType_GenericNew(Index_type, NULL, NULL); |
| 2651 | if (!result) goto failed; |
| 2652 | value = ast2obj_expr(o->v.Index.value); |
| 2653 | if (!value) goto failed; |
| 2654 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2655 | goto failed; |
| 2656 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2657 | break; |
| 2658 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2659 | return result; |
| 2660 | failed: |
| 2661 | Py_XDECREF(value); |
| 2662 | Py_XDECREF(result); |
| 2663 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2664 | } |
| 2665 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2666 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2667 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2668 | switch(o) { |
| 2669 | case And: |
| 2670 | Py_INCREF(And_singleton); |
| 2671 | return And_singleton; |
| 2672 | case Or: |
| 2673 | Py_INCREF(Or_singleton); |
| 2674 | return Or_singleton; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2675 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2676 | return NULL; /* cannot happen */ |
| 2677 | } |
| 2678 | PyObject* ast2obj_operator(operator_ty o) |
| 2679 | { |
| 2680 | switch(o) { |
| 2681 | case Add: |
| 2682 | Py_INCREF(Add_singleton); |
| 2683 | return Add_singleton; |
| 2684 | case Sub: |
| 2685 | Py_INCREF(Sub_singleton); |
| 2686 | return Sub_singleton; |
| 2687 | case Mult: |
| 2688 | Py_INCREF(Mult_singleton); |
| 2689 | return Mult_singleton; |
| 2690 | case Div: |
| 2691 | Py_INCREF(Div_singleton); |
| 2692 | return Div_singleton; |
| 2693 | case Mod: |
| 2694 | Py_INCREF(Mod_singleton); |
| 2695 | return Mod_singleton; |
| 2696 | case Pow: |
| 2697 | Py_INCREF(Pow_singleton); |
| 2698 | return Pow_singleton; |
| 2699 | case LShift: |
| 2700 | Py_INCREF(LShift_singleton); |
| 2701 | return LShift_singleton; |
| 2702 | case RShift: |
| 2703 | Py_INCREF(RShift_singleton); |
| 2704 | return RShift_singleton; |
| 2705 | case BitOr: |
| 2706 | Py_INCREF(BitOr_singleton); |
| 2707 | return BitOr_singleton; |
| 2708 | case BitXor: |
| 2709 | Py_INCREF(BitXor_singleton); |
| 2710 | return BitXor_singleton; |
| 2711 | case BitAnd: |
| 2712 | Py_INCREF(BitAnd_singleton); |
| 2713 | return BitAnd_singleton; |
| 2714 | case FloorDiv: |
| 2715 | Py_INCREF(FloorDiv_singleton); |
| 2716 | return FloorDiv_singleton; |
| 2717 | } |
| 2718 | return NULL; /* cannot happen */ |
| 2719 | } |
| 2720 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 2721 | { |
| 2722 | switch(o) { |
| 2723 | case Invert: |
| 2724 | Py_INCREF(Invert_singleton); |
| 2725 | return Invert_singleton; |
| 2726 | case Not: |
| 2727 | Py_INCREF(Not_singleton); |
| 2728 | return Not_singleton; |
| 2729 | case UAdd: |
| 2730 | Py_INCREF(UAdd_singleton); |
| 2731 | return UAdd_singleton; |
| 2732 | case USub: |
| 2733 | Py_INCREF(USub_singleton); |
| 2734 | return USub_singleton; |
| 2735 | } |
| 2736 | return NULL; /* cannot happen */ |
| 2737 | } |
| 2738 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 2739 | { |
| 2740 | switch(o) { |
| 2741 | case Eq: |
| 2742 | Py_INCREF(Eq_singleton); |
| 2743 | return Eq_singleton; |
| 2744 | case NotEq: |
| 2745 | Py_INCREF(NotEq_singleton); |
| 2746 | return NotEq_singleton; |
| 2747 | case Lt: |
| 2748 | Py_INCREF(Lt_singleton); |
| 2749 | return Lt_singleton; |
| 2750 | case LtE: |
| 2751 | Py_INCREF(LtE_singleton); |
| 2752 | return LtE_singleton; |
| 2753 | case Gt: |
| 2754 | Py_INCREF(Gt_singleton); |
| 2755 | return Gt_singleton; |
| 2756 | case GtE: |
| 2757 | Py_INCREF(GtE_singleton); |
| 2758 | return GtE_singleton; |
| 2759 | case Is: |
| 2760 | Py_INCREF(Is_singleton); |
| 2761 | return Is_singleton; |
| 2762 | case IsNot: |
| 2763 | Py_INCREF(IsNot_singleton); |
| 2764 | return IsNot_singleton; |
| 2765 | case In: |
| 2766 | Py_INCREF(In_singleton); |
| 2767 | return In_singleton; |
| 2768 | case NotIn: |
| 2769 | Py_INCREF(NotIn_singleton); |
| 2770 | return NotIn_singleton; |
| 2771 | } |
| 2772 | return NULL; /* cannot happen */ |
| 2773 | } |
| 2774 | PyObject* |
| 2775 | ast2obj_comprehension(void* _o) |
| 2776 | { |
| 2777 | comprehension_ty o = (comprehension_ty)_o; |
| 2778 | PyObject *result = NULL, *value = NULL; |
| 2779 | if (!o) { |
| 2780 | Py_INCREF(Py_None); |
| 2781 | return Py_None; |
| 2782 | } |
| 2783 | |
| 2784 | result = PyType_GenericNew(comprehension_type, NULL, NULL); |
| 2785 | if (!result) return NULL; |
| 2786 | value = ast2obj_expr(o->target); |
| 2787 | if (!value) goto failed; |
| 2788 | if (PyObject_SetAttrString(result, "target", value) == -1) |
| 2789 | goto failed; |
| 2790 | Py_DECREF(value); |
| 2791 | value = ast2obj_expr(o->iter); |
| 2792 | if (!value) goto failed; |
| 2793 | if (PyObject_SetAttrString(result, "iter", value) == -1) |
| 2794 | goto failed; |
| 2795 | Py_DECREF(value); |
| 2796 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 2797 | if (!value) goto failed; |
| 2798 | if (PyObject_SetAttrString(result, "ifs", value) == -1) |
| 2799 | goto failed; |
| 2800 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2801 | return result; |
| 2802 | failed: |
| 2803 | Py_XDECREF(value); |
| 2804 | Py_XDECREF(result); |
| 2805 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2806 | } |
| 2807 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2808 | PyObject* |
| 2809 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2810 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2811 | excepthandler_ty o = (excepthandler_ty)_o; |
| 2812 | PyObject *result = NULL, *value = NULL; |
| 2813 | if (!o) { |
| 2814 | Py_INCREF(Py_None); |
| 2815 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2816 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2817 | |
| 2818 | result = PyType_GenericNew(excepthandler_type, NULL, NULL); |
| 2819 | if (!result) return NULL; |
| 2820 | value = ast2obj_expr(o->type); |
| 2821 | if (!value) goto failed; |
| 2822 | if (PyObject_SetAttrString(result, "type", value) == -1) |
| 2823 | goto failed; |
| 2824 | Py_DECREF(value); |
| 2825 | value = ast2obj_expr(o->name); |
| 2826 | if (!value) goto failed; |
| 2827 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 2828 | goto failed; |
| 2829 | Py_DECREF(value); |
| 2830 | value = ast2obj_list(o->body, ast2obj_stmt); |
| 2831 | if (!value) goto failed; |
| 2832 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2833 | goto failed; |
| 2834 | Py_DECREF(value); |
Jeremy Hylton | 2f327c1 | 2006-04-04 04:00:23 +0000 | [diff] [blame] | 2835 | value = ast2obj_int(o->lineno); |
| 2836 | if (!value) goto failed; |
| 2837 | if (PyObject_SetAttrString(result, "lineno", value) == -1) |
| 2838 | goto failed; |
| 2839 | Py_DECREF(value); |
| 2840 | value = ast2obj_int(o->col_offset); |
| 2841 | if (!value) goto failed; |
| 2842 | if (PyObject_SetAttrString(result, "col_offset", value) == -1) |
| 2843 | goto failed; |
| 2844 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2845 | return result; |
| 2846 | failed: |
| 2847 | Py_XDECREF(value); |
| 2848 | Py_XDECREF(result); |
| 2849 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2850 | } |
| 2851 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2852 | PyObject* |
| 2853 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2854 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2855 | arguments_ty o = (arguments_ty)_o; |
| 2856 | PyObject *result = NULL, *value = NULL; |
| 2857 | if (!o) { |
| 2858 | Py_INCREF(Py_None); |
| 2859 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2860 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2861 | |
| 2862 | result = PyType_GenericNew(arguments_type, NULL, NULL); |
| 2863 | if (!result) return NULL; |
| 2864 | value = ast2obj_list(o->args, ast2obj_expr); |
| 2865 | if (!value) goto failed; |
| 2866 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 2867 | goto failed; |
| 2868 | Py_DECREF(value); |
| 2869 | value = ast2obj_identifier(o->vararg); |
| 2870 | if (!value) goto failed; |
| 2871 | if (PyObject_SetAttrString(result, "vararg", value) == -1) |
| 2872 | goto failed; |
| 2873 | Py_DECREF(value); |
| 2874 | value = ast2obj_identifier(o->kwarg); |
| 2875 | if (!value) goto failed; |
| 2876 | if (PyObject_SetAttrString(result, "kwarg", value) == -1) |
| 2877 | goto failed; |
| 2878 | Py_DECREF(value); |
| 2879 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 2880 | if (!value) goto failed; |
| 2881 | if (PyObject_SetAttrString(result, "defaults", value) == -1) |
| 2882 | goto failed; |
| 2883 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2884 | return result; |
| 2885 | failed: |
| 2886 | Py_XDECREF(value); |
| 2887 | Py_XDECREF(result); |
| 2888 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2889 | } |
| 2890 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2891 | PyObject* |
| 2892 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2893 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2894 | keyword_ty o = (keyword_ty)_o; |
| 2895 | PyObject *result = NULL, *value = NULL; |
| 2896 | if (!o) { |
| 2897 | Py_INCREF(Py_None); |
| 2898 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2899 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2900 | |
| 2901 | result = PyType_GenericNew(keyword_type, NULL, NULL); |
| 2902 | if (!result) return NULL; |
| 2903 | value = ast2obj_identifier(o->arg); |
| 2904 | if (!value) goto failed; |
| 2905 | if (PyObject_SetAttrString(result, "arg", value) == -1) |
| 2906 | goto failed; |
| 2907 | Py_DECREF(value); |
| 2908 | value = ast2obj_expr(o->value); |
| 2909 | if (!value) goto failed; |
| 2910 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2911 | goto failed; |
| 2912 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2913 | return result; |
| 2914 | failed: |
| 2915 | Py_XDECREF(value); |
| 2916 | Py_XDECREF(result); |
| 2917 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2918 | } |
| 2919 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2920 | PyObject* |
| 2921 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2922 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2923 | alias_ty o = (alias_ty)_o; |
| 2924 | PyObject *result = NULL, *value = NULL; |
| 2925 | if (!o) { |
| 2926 | Py_INCREF(Py_None); |
| 2927 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2928 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2929 | |
| 2930 | result = PyType_GenericNew(alias_type, NULL, NULL); |
| 2931 | if (!result) return NULL; |
| 2932 | value = ast2obj_identifier(o->name); |
| 2933 | if (!value) goto failed; |
| 2934 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 2935 | goto failed; |
| 2936 | Py_DECREF(value); |
| 2937 | value = ast2obj_identifier(o->asname); |
| 2938 | if (!value) goto failed; |
| 2939 | if (PyObject_SetAttrString(result, "asname", value) == -1) |
| 2940 | goto failed; |
| 2941 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2942 | return result; |
| 2943 | failed: |
| 2944 | Py_XDECREF(value); |
| 2945 | Py_XDECREF(result); |
| 2946 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2947 | } |
| 2948 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2949 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2950 | PyMODINIT_FUNC |
| 2951 | init_ast(void) |
| 2952 | { |
| 2953 | PyObject *m, *d; |
| 2954 | if (!init_types()) return; |
| 2955 | m = Py_InitModule3("_ast", NULL, NULL); |
| 2956 | if (!m) return; |
| 2957 | d = PyModule_GetDict(m); |
| 2958 | if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return; |
| 2959 | if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) |
| 2960 | return; |
Christian Heimes | 4034685 | 2008-02-23 17:52:07 +0000 | [diff] [blame] | 2961 | if (PyModule_AddStringConstant(m, "__version__", "60978") < 0) |
Martin v. Löwis | ace990c | 2006-02-28 00:32:31 +0000 | [diff] [blame] | 2962 | return; |
Neal Norwitz | 19379f1 | 2006-04-03 04:50:58 +0000 | [diff] [blame] | 2963 | if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return; |
| 2964 | if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) |
| 2965 | return; |
| 2966 | if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) |
| 2967 | < 0) return; |
| 2968 | if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < |
| 2969 | 0) return; |
| 2970 | if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return; |
| 2971 | if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return; |
| 2972 | if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) |
| 2973 | < 0) return; |
| 2974 | if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) |
| 2975 | return; |
| 2976 | if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) |
| 2977 | return; |
| 2978 | if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) |
| 2979 | return; |
| 2980 | if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) |
| 2981 | return; |
| 2982 | if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < |
| 2983 | 0) return; |
| 2984 | if (PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return; |
| 2985 | if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return; |
| 2986 | if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return; |
| 2987 | if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return; |
| 2988 | if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return; |
| 2989 | if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return; |
| 2990 | if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) < |
| 2991 | 0) return; |
| 2992 | if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) < |
| 2993 | 0) return; |
| 2994 | if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) |
| 2995 | return; |
| 2996 | if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) |
| 2997 | return; |
| 2998 | if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < |
| 2999 | 0) return; |
| 3000 | if (PyDict_SetItemString(d, "Exec", (PyObject*)Exec_type) < 0) return; |
| 3001 | if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) |
| 3002 | return; |
| 3003 | if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return; |
| 3004 | if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return; |
| 3005 | if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return; |
| 3006 | if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) |
| 3007 | return; |
| 3008 | if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return; |
| 3009 | if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) |
| 3010 | return; |
| 3011 | if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return; |
| 3012 | if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) |
| 3013 | return; |
| 3014 | if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) |
| 3015 | return; |
| 3016 | if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return; |
| 3017 | if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return; |
| 3018 | if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) |
| 3019 | return; |
| 3020 | if (PyDict_SetItemString(d, "GeneratorExp", |
| 3021 | (PyObject*)GeneratorExp_type) < 0) return; |
| 3022 | if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return; |
| 3023 | if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) |
| 3024 | return; |
| 3025 | if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return; |
| 3026 | if (PyDict_SetItemString(d, "Repr", (PyObject*)Repr_type) < 0) return; |
| 3027 | if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return; |
| 3028 | if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return; |
| 3029 | if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < |
| 3030 | 0) return; |
| 3031 | if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < |
| 3032 | 0) return; |
| 3033 | if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return; |
| 3034 | if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return; |
| 3035 | if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return; |
| 3036 | if (PyDict_SetItemString(d, "expr_context", |
| 3037 | (PyObject*)expr_context_type) < 0) return; |
| 3038 | if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return; |
| 3039 | if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return; |
| 3040 | if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return; |
| 3041 | if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) |
| 3042 | return; |
| 3043 | if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) |
| 3044 | return; |
| 3045 | if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return; |
| 3046 | if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return; |
| 3047 | if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0) |
| 3048 | return; |
| 3049 | if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return; |
| 3050 | if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) |
| 3051 | return; |
| 3052 | if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return; |
| 3053 | if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) |
| 3054 | return; |
| 3055 | if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return; |
| 3056 | if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return; |
| 3057 | if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) |
| 3058 | return; |
| 3059 | if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return; |
| 3060 | if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return; |
| 3061 | if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return; |
| 3062 | if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return; |
| 3063 | if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return; |
| 3064 | if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return; |
| 3065 | if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) |
| 3066 | return; |
| 3067 | if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) |
| 3068 | return; |
| 3069 | if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return; |
| 3070 | if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) |
| 3071 | return; |
| 3072 | if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) |
| 3073 | return; |
| 3074 | if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) |
| 3075 | return; |
| 3076 | if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) |
| 3077 | return; |
| 3078 | if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) |
| 3079 | return; |
| 3080 | if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return; |
| 3081 | if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return; |
| 3082 | if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return; |
| 3083 | if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return; |
| 3084 | if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return; |
| 3085 | if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return; |
| 3086 | if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return; |
| 3087 | if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return; |
| 3088 | if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return; |
| 3089 | if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return; |
| 3090 | if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return; |
| 3091 | if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return; |
| 3092 | if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return; |
| 3093 | if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return; |
| 3094 | if (PyDict_SetItemString(d, "comprehension", |
| 3095 | (PyObject*)comprehension_type) < 0) return; |
| 3096 | if (PyDict_SetItemString(d, "excepthandler", |
| 3097 | (PyObject*)excepthandler_type) < 0) return; |
| 3098 | if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < |
| 3099 | 0) return; |
| 3100 | if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) |
| 3101 | return; |
| 3102 | if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 3103 | } |
| 3104 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3105 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3106 | PyObject* PyAST_mod2obj(mod_ty t) |
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 | init_types(); |
| 3109 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3110 | } |
| 3111 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3112 | |