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