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