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