Thomas Wouters | cf297e4 | 2007-02-23 15:07:44 +0000 | [diff] [blame] | 1 | /* File automatically generated by Parser/asdl_c.py. */ |
| 2 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 3 | #include <stddef.h> |
| 4 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 5 | #include "Python.h" |
| 6 | #include "Python-ast.h" |
| 7 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 8 | static PyTypeObject AST_type; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 9 | static PyTypeObject *mod_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 10 | static PyObject* ast2obj_mod(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 11 | static PyTypeObject *Module_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 12 | _Py_IDENTIFIER(body); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 13 | static char *Module_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 14 | "body", |
| 15 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 16 | static PyTypeObject *Interactive_type; |
| 17 | static char *Interactive_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 18 | "body", |
| 19 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 20 | static PyTypeObject *Expression_type; |
| 21 | static char *Expression_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 22 | "body", |
| 23 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 24 | static PyTypeObject *Suite_type; |
| 25 | static char *Suite_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 26 | "body", |
| 27 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 28 | static PyTypeObject *stmt_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 29 | _Py_IDENTIFIER(lineno); |
| 30 | _Py_IDENTIFIER(col_offset); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 31 | static char *stmt_attributes[] = { |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 32 | "lineno", |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 33 | "col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 34 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 35 | static PyObject* ast2obj_stmt(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 36 | static PyTypeObject *FunctionDef_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 37 | _Py_IDENTIFIER(name); |
| 38 | _Py_IDENTIFIER(args); |
| 39 | _Py_IDENTIFIER(decorator_list); |
| 40 | _Py_IDENTIFIER(returns); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 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", |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 45 | "decorator_list", |
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; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 49 | _Py_IDENTIFIER(bases); |
| 50 | _Py_IDENTIFIER(keywords); |
| 51 | _Py_IDENTIFIER(starargs); |
| 52 | _Py_IDENTIFIER(kwargs); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 53 | static char *ClassDef_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 54 | "name", |
| 55 | "bases", |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 56 | "keywords", |
| 57 | "starargs", |
| 58 | "kwargs", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 59 | "body", |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 60 | "decorator_list", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 61 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 62 | static PyTypeObject *Return_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 63 | _Py_IDENTIFIER(value); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 64 | static char *Return_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 65 | "value", |
| 66 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 67 | static PyTypeObject *Delete_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 68 | _Py_IDENTIFIER(targets); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 69 | static char *Delete_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 70 | "targets", |
| 71 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 72 | static PyTypeObject *Assign_type; |
| 73 | static char *Assign_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 74 | "targets", |
| 75 | "value", |
| 76 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 77 | static PyTypeObject *AugAssign_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 78 | _Py_IDENTIFIER(target); |
| 79 | _Py_IDENTIFIER(op); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 80 | static char *AugAssign_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 81 | "target", |
| 82 | "op", |
| 83 | "value", |
| 84 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 85 | static PyTypeObject *For_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 86 | _Py_IDENTIFIER(iter); |
| 87 | _Py_IDENTIFIER(orelse); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 88 | static char *For_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 89 | "target", |
| 90 | "iter", |
| 91 | "body", |
| 92 | "orelse", |
| 93 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 94 | static PyTypeObject *While_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 95 | _Py_IDENTIFIER(test); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 96 | static char *While_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 97 | "test", |
| 98 | "body", |
| 99 | "orelse", |
| 100 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 101 | static PyTypeObject *If_type; |
| 102 | static char *If_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 103 | "test", |
| 104 | "body", |
| 105 | "orelse", |
| 106 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 107 | static PyTypeObject *With_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 108 | _Py_IDENTIFIER(items); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 109 | static char *With_fields[]={ |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 110 | "items", |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 111 | "body", |
| 112 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 113 | static PyTypeObject *Raise_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 114 | _Py_IDENTIFIER(exc); |
| 115 | _Py_IDENTIFIER(cause); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 116 | static char *Raise_fields[]={ |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 117 | "exc", |
| 118 | "cause", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 119 | }; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 120 | static PyTypeObject *Try_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 121 | _Py_IDENTIFIER(handlers); |
| 122 | _Py_IDENTIFIER(finalbody); |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 123 | static char *Try_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 124 | "body", |
| 125 | "handlers", |
| 126 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 127 | "finalbody", |
| 128 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 129 | static PyTypeObject *Assert_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 130 | _Py_IDENTIFIER(msg); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 131 | static char *Assert_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 132 | "test", |
| 133 | "msg", |
| 134 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 135 | static PyTypeObject *Import_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 136 | _Py_IDENTIFIER(names); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 137 | static char *Import_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 138 | "names", |
| 139 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 140 | static PyTypeObject *ImportFrom_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 141 | _Py_IDENTIFIER(module); |
| 142 | _Py_IDENTIFIER(level); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 143 | static char *ImportFrom_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 144 | "module", |
| 145 | "names", |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 146 | "level", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 147 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 148 | static PyTypeObject *Global_type; |
| 149 | static char *Global_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 150 | "names", |
| 151 | }; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 152 | static PyTypeObject *Nonlocal_type; |
| 153 | static char *Nonlocal_fields[]={ |
| 154 | "names", |
| 155 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 156 | static PyTypeObject *Expr_type; |
| 157 | static char *Expr_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 158 | "value", |
| 159 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 160 | static PyTypeObject *Pass_type; |
| 161 | static PyTypeObject *Break_type; |
| 162 | static PyTypeObject *Continue_type; |
| 163 | static PyTypeObject *expr_type; |
| 164 | static char *expr_attributes[] = { |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 165 | "lineno", |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 166 | "col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 167 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 168 | static PyObject* ast2obj_expr(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 169 | static PyTypeObject *BoolOp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 170 | _Py_IDENTIFIER(values); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 171 | static char *BoolOp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 172 | "op", |
| 173 | "values", |
| 174 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 175 | static PyTypeObject *BinOp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 176 | _Py_IDENTIFIER(left); |
| 177 | _Py_IDENTIFIER(right); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 178 | static char *BinOp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 179 | "left", |
| 180 | "op", |
| 181 | "right", |
| 182 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 183 | static PyTypeObject *UnaryOp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 184 | _Py_IDENTIFIER(operand); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 185 | static char *UnaryOp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 186 | "op", |
| 187 | "operand", |
| 188 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 189 | static PyTypeObject *Lambda_type; |
| 190 | static char *Lambda_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 191 | "args", |
| 192 | "body", |
| 193 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 194 | static PyTypeObject *IfExp_type; |
| 195 | static char *IfExp_fields[]={ |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 196 | "test", |
| 197 | "body", |
| 198 | "orelse", |
| 199 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 200 | static PyTypeObject *Dict_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 201 | _Py_IDENTIFIER(keys); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 202 | static char *Dict_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 203 | "keys", |
| 204 | "values", |
| 205 | }; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 206 | static PyTypeObject *Set_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 207 | _Py_IDENTIFIER(elts); |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 208 | static char *Set_fields[]={ |
| 209 | "elts", |
| 210 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 211 | static PyTypeObject *ListComp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 212 | _Py_IDENTIFIER(elt); |
| 213 | _Py_IDENTIFIER(generators); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 214 | static char *ListComp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 215 | "elt", |
| 216 | "generators", |
| 217 | }; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 218 | static PyTypeObject *SetComp_type; |
| 219 | static char *SetComp_fields[]={ |
| 220 | "elt", |
| 221 | "generators", |
| 222 | }; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 223 | static PyTypeObject *DictComp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 224 | _Py_IDENTIFIER(key); |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 225 | static char *DictComp_fields[]={ |
| 226 | "key", |
| 227 | "value", |
| 228 | "generators", |
| 229 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 230 | static PyTypeObject *GeneratorExp_type; |
| 231 | static char *GeneratorExp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 232 | "elt", |
| 233 | "generators", |
| 234 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 235 | static PyTypeObject *Yield_type; |
| 236 | static char *Yield_fields[]={ |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 237 | "value", |
| 238 | }; |
| 239 | static PyTypeObject *YieldFrom_type; |
| 240 | static char *YieldFrom_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 241 | "value", |
| 242 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 243 | static PyTypeObject *Compare_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 244 | _Py_IDENTIFIER(ops); |
| 245 | _Py_IDENTIFIER(comparators); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 246 | static char *Compare_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 247 | "left", |
| 248 | "ops", |
| 249 | "comparators", |
| 250 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 251 | static PyTypeObject *Call_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 252 | _Py_IDENTIFIER(func); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 253 | static char *Call_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 254 | "func", |
| 255 | "args", |
| 256 | "keywords", |
| 257 | "starargs", |
| 258 | "kwargs", |
| 259 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 260 | static PyTypeObject *Num_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 261 | _Py_IDENTIFIER(n); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 262 | static char *Num_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 263 | "n", |
| 264 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 265 | static PyTypeObject *Str_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 266 | _Py_IDENTIFIER(s); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 267 | static char *Str_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 268 | "s", |
| 269 | }; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 270 | static PyTypeObject *Bytes_type; |
| 271 | static char *Bytes_fields[]={ |
| 272 | "s", |
| 273 | }; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 274 | static PyTypeObject *Ellipsis_type; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 275 | static PyTypeObject *Attribute_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 276 | _Py_IDENTIFIER(attr); |
| 277 | _Py_IDENTIFIER(ctx); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 278 | static char *Attribute_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 279 | "value", |
| 280 | "attr", |
| 281 | "ctx", |
| 282 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 283 | static PyTypeObject *Subscript_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 284 | _Py_IDENTIFIER(slice); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 285 | static char *Subscript_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 286 | "value", |
| 287 | "slice", |
| 288 | "ctx", |
| 289 | }; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 290 | static PyTypeObject *Starred_type; |
| 291 | static char *Starred_fields[]={ |
| 292 | "value", |
| 293 | "ctx", |
| 294 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 295 | static PyTypeObject *Name_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 296 | _Py_IDENTIFIER(id); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 297 | static char *Name_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 298 | "id", |
| 299 | "ctx", |
| 300 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 301 | static PyTypeObject *List_type; |
| 302 | static char *List_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 303 | "elts", |
| 304 | "ctx", |
| 305 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 306 | static PyTypeObject *Tuple_type; |
| 307 | static char *Tuple_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 308 | "elts", |
| 309 | "ctx", |
| 310 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 311 | static PyTypeObject *expr_context_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 312 | static PyObject *Load_singleton, *Store_singleton, *Del_singleton, |
| 313 | *AugLoad_singleton, *AugStore_singleton, *Param_singleton; |
| 314 | static PyObject* ast2obj_expr_context(expr_context_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 315 | static PyTypeObject *Load_type; |
| 316 | static PyTypeObject *Store_type; |
| 317 | static PyTypeObject *Del_type; |
| 318 | static PyTypeObject *AugLoad_type; |
| 319 | static PyTypeObject *AugStore_type; |
| 320 | static PyTypeObject *Param_type; |
| 321 | static PyTypeObject *slice_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 322 | static PyObject* ast2obj_slice(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 323 | static PyTypeObject *Slice_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 324 | _Py_IDENTIFIER(lower); |
| 325 | _Py_IDENTIFIER(upper); |
| 326 | _Py_IDENTIFIER(step); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 327 | static char *Slice_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 328 | "lower", |
| 329 | "upper", |
| 330 | "step", |
| 331 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 332 | static PyTypeObject *ExtSlice_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 333 | _Py_IDENTIFIER(dims); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 334 | static char *ExtSlice_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 335 | "dims", |
| 336 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 337 | static PyTypeObject *Index_type; |
| 338 | static char *Index_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 339 | "value", |
| 340 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 341 | static PyTypeObject *boolop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 342 | static PyObject *And_singleton, *Or_singleton; |
| 343 | static PyObject* ast2obj_boolop(boolop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 344 | static PyTypeObject *And_type; |
| 345 | static PyTypeObject *Or_type; |
| 346 | static PyTypeObject *operator_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 347 | static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton, |
| 348 | *Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton, |
| 349 | *RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton, |
| 350 | *FloorDiv_singleton; |
| 351 | static PyObject* ast2obj_operator(operator_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 352 | static PyTypeObject *Add_type; |
| 353 | static PyTypeObject *Sub_type; |
| 354 | static PyTypeObject *Mult_type; |
| 355 | static PyTypeObject *Div_type; |
| 356 | static PyTypeObject *Mod_type; |
| 357 | static PyTypeObject *Pow_type; |
| 358 | static PyTypeObject *LShift_type; |
| 359 | static PyTypeObject *RShift_type; |
| 360 | static PyTypeObject *BitOr_type; |
| 361 | static PyTypeObject *BitXor_type; |
| 362 | static PyTypeObject *BitAnd_type; |
| 363 | static PyTypeObject *FloorDiv_type; |
| 364 | static PyTypeObject *unaryop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 365 | static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton, |
| 366 | *USub_singleton; |
| 367 | static PyObject* ast2obj_unaryop(unaryop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 368 | static PyTypeObject *Invert_type; |
| 369 | static PyTypeObject *Not_type; |
| 370 | static PyTypeObject *UAdd_type; |
| 371 | static PyTypeObject *USub_type; |
| 372 | static PyTypeObject *cmpop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 373 | static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton, |
| 374 | *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton, |
| 375 | *NotIn_singleton; |
| 376 | static PyObject* ast2obj_cmpop(cmpop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 377 | static PyTypeObject *Eq_type; |
| 378 | static PyTypeObject *NotEq_type; |
| 379 | static PyTypeObject *Lt_type; |
| 380 | static PyTypeObject *LtE_type; |
| 381 | static PyTypeObject *Gt_type; |
| 382 | static PyTypeObject *GtE_type; |
| 383 | static PyTypeObject *Is_type; |
| 384 | static PyTypeObject *IsNot_type; |
| 385 | static PyTypeObject *In_type; |
| 386 | static PyTypeObject *NotIn_type; |
| 387 | static PyTypeObject *comprehension_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 388 | static PyObject* ast2obj_comprehension(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 389 | _Py_IDENTIFIER(ifs); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 390 | static char *comprehension_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 391 | "target", |
| 392 | "iter", |
| 393 | "ifs", |
| 394 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 395 | static PyTypeObject *excepthandler_type; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 396 | static char *excepthandler_attributes[] = { |
| 397 | "lineno", |
| 398 | "col_offset", |
| 399 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 400 | static PyObject* ast2obj_excepthandler(void*); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 401 | static PyTypeObject *ExceptHandler_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 402 | _Py_IDENTIFIER(type); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 403 | static char *ExceptHandler_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 404 | "type", |
| 405 | "name", |
| 406 | "body", |
| 407 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 408 | static PyTypeObject *arguments_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 409 | static PyObject* ast2obj_arguments(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 410 | _Py_IDENTIFIER(vararg); |
| 411 | _Py_IDENTIFIER(varargannotation); |
| 412 | _Py_IDENTIFIER(kwonlyargs); |
| 413 | _Py_IDENTIFIER(kwarg); |
| 414 | _Py_IDENTIFIER(kwargannotation); |
| 415 | _Py_IDENTIFIER(defaults); |
| 416 | _Py_IDENTIFIER(kw_defaults); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 417 | static char *arguments_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 418 | "args", |
| 419 | "vararg", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 420 | "varargannotation", |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 421 | "kwonlyargs", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 422 | "kwarg", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 423 | "kwargannotation", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 424 | "defaults", |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 425 | "kw_defaults", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 426 | }; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 427 | static PyTypeObject *arg_type; |
| 428 | static PyObject* ast2obj_arg(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 429 | _Py_IDENTIFIER(arg); |
| 430 | _Py_IDENTIFIER(annotation); |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 431 | static char *arg_fields[]={ |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 432 | "arg", |
| 433 | "annotation", |
| 434 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 435 | static PyTypeObject *keyword_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 436 | static PyObject* ast2obj_keyword(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 437 | static char *keyword_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 438 | "arg", |
| 439 | "value", |
| 440 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 441 | static PyTypeObject *alias_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 442 | static PyObject* ast2obj_alias(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 443 | _Py_IDENTIFIER(asname); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 444 | static char *alias_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 445 | "name", |
| 446 | "asname", |
| 447 | }; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 448 | static PyTypeObject *withitem_type; |
| 449 | static PyObject* ast2obj_withitem(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 450 | _Py_IDENTIFIER(context_expr); |
| 451 | _Py_IDENTIFIER(optional_vars); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 452 | static char *withitem_fields[]={ |
| 453 | "context_expr", |
| 454 | "optional_vars", |
| 455 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 456 | |
| 457 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 458 | typedef struct { |
Victor Stinner | 45e50de | 2012-03-13 01:17:31 +0100 | [diff] [blame^] | 459 | PyObject_HEAD |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 460 | PyObject *dict; |
| 461 | } AST_object; |
| 462 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 463 | static int |
| 464 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 465 | { |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 466 | _Py_IDENTIFIER(_fields); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 467 | Py_ssize_t i, numfields = 0; |
| 468 | int res = -1; |
| 469 | PyObject *key, *value, *fields; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 470 | fields = _PyObject_GetAttrId((PyObject*)Py_TYPE(self), &PyId__fields); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 471 | if (!fields) |
| 472 | PyErr_Clear(); |
| 473 | if (fields) { |
| 474 | numfields = PySequence_Size(fields); |
| 475 | if (numfields == -1) |
| 476 | goto cleanup; |
| 477 | } |
| 478 | res = 0; /* if no error occurs, this stays 0 to the end */ |
| 479 | if (PyTuple_GET_SIZE(args) > 0) { |
| 480 | if (numfields != PyTuple_GET_SIZE(args)) { |
| 481 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes %s" |
Amaury Forgeot d'Arc | 245c70b | 2008-09-10 22:24:24 +0000 | [diff] [blame] | 482 | "%zd positional argument%s", |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 483 | Py_TYPE(self)->tp_name, |
| 484 | numfields == 0 ? "" : "either 0 or ", |
| 485 | numfields, numfields == 1 ? "" : "s"); |
| 486 | res = -1; |
| 487 | goto cleanup; |
| 488 | } |
| 489 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
| 490 | /* cannot be reached when fields is NULL */ |
| 491 | PyObject *name = PySequence_GetItem(fields, i); |
| 492 | if (!name) { |
| 493 | res = -1; |
| 494 | goto cleanup; |
| 495 | } |
| 496 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
| 497 | Py_DECREF(name); |
| 498 | if (res < 0) |
| 499 | goto cleanup; |
| 500 | } |
| 501 | } |
| 502 | if (kw) { |
| 503 | i = 0; /* needed by PyDict_Next */ |
| 504 | while (PyDict_Next(kw, &i, &key, &value)) { |
| 505 | res = PyObject_SetAttr(self, key, value); |
| 506 | if (res < 0) |
| 507 | goto cleanup; |
| 508 | } |
| 509 | } |
| 510 | cleanup: |
| 511 | Py_XDECREF(fields); |
| 512 | return res; |
| 513 | } |
| 514 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 515 | /* Pickling support */ |
| 516 | static PyObject * |
| 517 | ast_type_reduce(PyObject *self, PyObject *unused) |
| 518 | { |
| 519 | PyObject *res; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 520 | _Py_IDENTIFIER(__dict__); |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 521 | PyObject *dict = _PyObject_GetAttrId(self, &PyId___dict__); |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 522 | if (dict == NULL) { |
| 523 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) |
| 524 | PyErr_Clear(); |
| 525 | else |
| 526 | return NULL; |
| 527 | } |
| 528 | if (dict) { |
| 529 | res = Py_BuildValue("O()O", Py_TYPE(self), dict); |
| 530 | Py_DECREF(dict); |
| 531 | return res; |
| 532 | } |
| 533 | return Py_BuildValue("O()", Py_TYPE(self)); |
| 534 | } |
| 535 | |
| 536 | static PyMethodDef ast_type_methods[] = { |
| 537 | {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, |
| 538 | {NULL} |
| 539 | }; |
| 540 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 541 | static PyGetSetDef ast_type_getsets[] = { |
| 542 | {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict}, |
| 543 | {NULL} |
| 544 | }; |
| 545 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 546 | static PyTypeObject AST_type = { |
| 547 | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 548 | "_ast.AST", |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 549 | sizeof(AST_object), |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 550 | 0, |
| 551 | 0, /* tp_dealloc */ |
| 552 | 0, /* tp_print */ |
| 553 | 0, /* tp_getattr */ |
| 554 | 0, /* tp_setattr */ |
Mark Dickinson | e94c679 | 2009-02-02 20:36:42 +0000 | [diff] [blame] | 555 | 0, /* tp_reserved */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 556 | 0, /* tp_repr */ |
| 557 | 0, /* tp_as_number */ |
| 558 | 0, /* tp_as_sequence */ |
| 559 | 0, /* tp_as_mapping */ |
| 560 | 0, /* tp_hash */ |
| 561 | 0, /* tp_call */ |
| 562 | 0, /* tp_str */ |
| 563 | PyObject_GenericGetAttr, /* tp_getattro */ |
| 564 | PyObject_GenericSetAttr, /* tp_setattro */ |
| 565 | 0, /* tp_as_buffer */ |
| 566 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
| 567 | 0, /* tp_doc */ |
| 568 | 0, /* tp_traverse */ |
| 569 | 0, /* tp_clear */ |
| 570 | 0, /* tp_richcompare */ |
| 571 | 0, /* tp_weaklistoffset */ |
| 572 | 0, /* tp_iter */ |
| 573 | 0, /* tp_iternext */ |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 574 | ast_type_methods, /* tp_methods */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 575 | 0, /* tp_members */ |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 576 | ast_type_getsets, /* tp_getset */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 577 | 0, /* tp_base */ |
| 578 | 0, /* tp_dict */ |
| 579 | 0, /* tp_descr_get */ |
| 580 | 0, /* tp_descr_set */ |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 581 | offsetof(AST_object, dict),/* tp_dictoffset */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 582 | (initproc)ast_type_init, /* tp_init */ |
| 583 | PyType_GenericAlloc, /* tp_alloc */ |
| 584 | PyType_GenericNew, /* tp_new */ |
| 585 | PyObject_Del, /* tp_free */ |
| 586 | }; |
| 587 | |
| 588 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 589 | static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields) |
| 590 | { |
| 591 | PyObject *fnames, *result; |
| 592 | int i; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 593 | fnames = PyTuple_New(num_fields); |
| 594 | if (!fnames) return NULL; |
| 595 | for (i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 596 | PyObject *field = PyUnicode_FromString(fields[i]); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 597 | if (!field) { |
| 598 | Py_DECREF(fnames); |
| 599 | return NULL; |
| 600 | } |
| 601 | PyTuple_SET_ITEM(fnames, i, field); |
| 602 | } |
Victor Stinner | 7eeb5b5 | 2010-06-07 19:57:46 +0000 | [diff] [blame] | 603 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 604 | type, base, "_fields", fnames, "__module__", "_ast"); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 605 | Py_DECREF(fnames); |
| 606 | return (PyTypeObject*)result; |
| 607 | } |
| 608 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 609 | static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) |
| 610 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 611 | int i, result; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 612 | _Py_IDENTIFIER(_attributes); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 613 | PyObject *s, *l = PyTuple_New(num_fields); |
Benjamin Peterson | 3e5cd1d | 2010-06-27 21:45:24 +0000 | [diff] [blame] | 614 | if (!l) |
| 615 | return 0; |
| 616 | for (i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 617 | s = PyUnicode_FromString(attrs[i]); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 618 | if (!s) { |
| 619 | Py_DECREF(l); |
| 620 | return 0; |
| 621 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 622 | PyTuple_SET_ITEM(l, i, s); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 623 | } |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 624 | result = _PyObject_SetAttrId((PyObject*)type, &PyId__attributes, l) >= 0; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 625 | Py_DECREF(l); |
| 626 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 627 | } |
| 628 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 629 | /* Conversion AST -> Python */ |
| 630 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 631 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 632 | { |
| 633 | int i, n = asdl_seq_LEN(seq); |
| 634 | PyObject *result = PyList_New(n); |
| 635 | PyObject *value; |
| 636 | if (!result) |
| 637 | return NULL; |
| 638 | for (i = 0; i < n; i++) { |
| 639 | value = func(asdl_seq_GET(seq, i)); |
| 640 | if (!value) { |
| 641 | Py_DECREF(result); |
| 642 | return NULL; |
| 643 | } |
| 644 | PyList_SET_ITEM(result, i, value); |
| 645 | } |
| 646 | return result; |
| 647 | } |
| 648 | |
| 649 | static PyObject* ast2obj_object(void *o) |
| 650 | { |
| 651 | if (!o) |
| 652 | o = Py_None; |
| 653 | Py_INCREF((PyObject*)o); |
| 654 | return (PyObject*)o; |
| 655 | } |
| 656 | #define ast2obj_identifier ast2obj_object |
| 657 | #define ast2obj_string ast2obj_object |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 658 | #define ast2obj_bytes ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 659 | |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 660 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 661 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 662 | return PyLong_FromLong(b); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 663 | } |
| 664 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 665 | /* Conversion Python -> AST */ |
| 666 | |
| 667 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 668 | { |
| 669 | if (obj == Py_None) |
| 670 | obj = NULL; |
| 671 | if (obj) |
| 672 | PyArena_AddPyObject(arena, obj); |
| 673 | Py_XINCREF(obj); |
| 674 | *out = obj; |
| 675 | return 0; |
| 676 | } |
| 677 | |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 678 | static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 679 | { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 680 | if (!PyUnicode_CheckExact(obj) && obj != Py_None) { |
| 681 | PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 682 | return 1; |
| 683 | } |
| 684 | return obj2ast_object(obj, out, arena); |
| 685 | } |
| 686 | |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 687 | static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) |
| 688 | { |
Benjamin Peterson | 0224d4e | 2011-08-31 22:13:03 -0400 | [diff] [blame] | 689 | if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 690 | PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); |
| 691 | return 1; |
| 692 | } |
| 693 | return obj2ast_object(obj, out, arena); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 694 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 695 | |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 696 | static int obj2ast_bytes(PyObject* obj, PyObject** out, PyArena* arena) |
| 697 | { |
| 698 | if (!PyBytes_CheckExact(obj)) { |
| 699 | PyErr_SetString(PyExc_TypeError, "AST bytes must be of type bytes"); |
| 700 | return 1; |
| 701 | } |
| 702 | return obj2ast_object(obj, out, arena); |
| 703 | } |
| 704 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 705 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 706 | { |
| 707 | int i; |
| 708 | if (!PyLong_Check(obj)) { |
Amaury Forgeot d'Arc | 5e8f810 | 2011-11-22 21:52:30 +0100 | [diff] [blame] | 709 | PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 710 | return 1; |
| 711 | } |
| 712 | |
| 713 | i = (int)PyLong_AsLong(obj); |
| 714 | if (i == -1 && PyErr_Occurred()) |
| 715 | return 1; |
| 716 | *out = i; |
| 717 | return 0; |
| 718 | } |
| 719 | |
Benjamin Peterson | 1a6e0d0 | 2008-10-25 15:49:17 +0000 | [diff] [blame] | 720 | static int add_ast_fields(void) |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 721 | { |
| 722 | PyObject *empty_tuple, *d; |
| 723 | if (PyType_Ready(&AST_type) < 0) |
| 724 | return -1; |
| 725 | d = AST_type.tp_dict; |
| 726 | empty_tuple = PyTuple_New(0); |
| 727 | if (!empty_tuple || |
| 728 | PyDict_SetItemString(d, "_fields", empty_tuple) < 0 || |
| 729 | PyDict_SetItemString(d, "_attributes", empty_tuple) < 0) { |
| 730 | Py_XDECREF(empty_tuple); |
| 731 | return -1; |
| 732 | } |
| 733 | Py_DECREF(empty_tuple); |
| 734 | return 0; |
| 735 | } |
| 736 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 737 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 738 | static int init_types(void) |
| 739 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 740 | static int initialized; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 741 | if (initialized) return 1; |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 742 | if (add_ast_fields() < 0) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 743 | mod_type = make_type("mod", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 744 | if (!mod_type) return 0; |
| 745 | if (!add_attributes(mod_type, NULL, 0)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 746 | Module_type = make_type("Module", mod_type, Module_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 747 | if (!Module_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 748 | Interactive_type = make_type("Interactive", mod_type, |
| 749 | Interactive_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 750 | if (!Interactive_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 751 | Expression_type = make_type("Expression", mod_type, Expression_fields, |
| 752 | 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 753 | if (!Expression_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 754 | Suite_type = make_type("Suite", mod_type, Suite_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 755 | if (!Suite_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 756 | stmt_type = make_type("stmt", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 757 | if (!stmt_type) return 0; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 758 | if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 759 | FunctionDef_type = make_type("FunctionDef", stmt_type, |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 760 | FunctionDef_fields, 5); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 761 | if (!FunctionDef_type) return 0; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 762 | ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 7); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 763 | if (!ClassDef_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 764 | Return_type = make_type("Return", stmt_type, Return_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 765 | if (!Return_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 766 | Delete_type = make_type("Delete", stmt_type, Delete_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 767 | if (!Delete_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 768 | Assign_type = make_type("Assign", stmt_type, Assign_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 769 | if (!Assign_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 770 | AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 771 | if (!AugAssign_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 772 | For_type = make_type("For", stmt_type, For_fields, 4); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 773 | if (!For_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 774 | While_type = make_type("While", stmt_type, While_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 775 | if (!While_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 776 | If_type = make_type("If", stmt_type, If_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 777 | if (!If_type) return 0; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 778 | With_type = make_type("With", stmt_type, With_fields, 2); |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 779 | if (!With_type) return 0; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 780 | Raise_type = make_type("Raise", stmt_type, Raise_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 781 | if (!Raise_type) return 0; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 782 | Try_type = make_type("Try", stmt_type, Try_fields, 4); |
| 783 | if (!Try_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 784 | Assert_type = make_type("Assert", stmt_type, Assert_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 785 | if (!Assert_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 786 | Import_type = make_type("Import", stmt_type, Import_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 787 | if (!Import_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 788 | ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 789 | 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 790 | if (!ImportFrom_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 791 | Global_type = make_type("Global", stmt_type, Global_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 792 | if (!Global_type) return 0; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 793 | Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1); |
| 794 | if (!Nonlocal_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 795 | Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 796 | if (!Expr_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 797 | Pass_type = make_type("Pass", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 798 | if (!Pass_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 799 | Break_type = make_type("Break", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 800 | if (!Break_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 801 | Continue_type = make_type("Continue", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 802 | if (!Continue_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 803 | expr_type = make_type("expr", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 804 | if (!expr_type) return 0; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 805 | if (!add_attributes(expr_type, expr_attributes, 2)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 806 | BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 807 | if (!BoolOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 808 | BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 809 | if (!BinOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 810 | UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 811 | if (!UnaryOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 812 | Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 813 | if (!Lambda_type) return 0; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 814 | IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 815 | if (!IfExp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 816 | Dict_type = make_type("Dict", expr_type, Dict_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 817 | if (!Dict_type) return 0; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 818 | Set_type = make_type("Set", expr_type, Set_fields, 1); |
| 819 | if (!Set_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 820 | ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 821 | if (!ListComp_type) return 0; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 822 | SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2); |
| 823 | if (!SetComp_type) return 0; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 824 | DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3); |
| 825 | if (!DictComp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 826 | GeneratorExp_type = make_type("GeneratorExp", expr_type, |
| 827 | GeneratorExp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 828 | if (!GeneratorExp_type) return 0; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 829 | Yield_type = make_type("Yield", expr_type, Yield_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 830 | if (!Yield_type) return 0; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 831 | YieldFrom_type = make_type("YieldFrom", expr_type, YieldFrom_fields, 1); |
| 832 | if (!YieldFrom_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 833 | Compare_type = make_type("Compare", expr_type, Compare_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 834 | if (!Compare_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 835 | Call_type = make_type("Call", expr_type, Call_fields, 5); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 836 | if (!Call_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 837 | Num_type = make_type("Num", expr_type, Num_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 838 | if (!Num_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 839 | Str_type = make_type("Str", expr_type, Str_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 840 | if (!Str_type) return 0; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 841 | Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1); |
| 842 | if (!Bytes_type) return 0; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 843 | Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0); |
| 844 | if (!Ellipsis_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 845 | Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 846 | if (!Attribute_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 847 | Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 848 | if (!Subscript_type) return 0; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 849 | Starred_type = make_type("Starred", expr_type, Starred_fields, 2); |
| 850 | if (!Starred_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 851 | Name_type = make_type("Name", expr_type, Name_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 852 | if (!Name_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 853 | List_type = make_type("List", expr_type, List_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 854 | if (!List_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 855 | Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 856 | if (!Tuple_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 857 | expr_context_type = make_type("expr_context", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 858 | if (!expr_context_type) return 0; |
| 859 | if (!add_attributes(expr_context_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 860 | Load_type = make_type("Load", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 861 | if (!Load_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 862 | Load_singleton = PyType_GenericNew(Load_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 863 | if (!Load_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 864 | Store_type = make_type("Store", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 865 | if (!Store_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 866 | Store_singleton = PyType_GenericNew(Store_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 867 | if (!Store_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 868 | Del_type = make_type("Del", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 869 | if (!Del_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 870 | Del_singleton = PyType_GenericNew(Del_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 871 | if (!Del_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 872 | AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 873 | if (!AugLoad_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 874 | AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 875 | if (!AugLoad_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 876 | AugStore_type = make_type("AugStore", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 877 | if (!AugStore_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 878 | AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 879 | if (!AugStore_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 880 | Param_type = make_type("Param", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 881 | if (!Param_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 882 | Param_singleton = PyType_GenericNew(Param_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 883 | if (!Param_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 884 | slice_type = make_type("slice", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 885 | if (!slice_type) return 0; |
| 886 | if (!add_attributes(slice_type, NULL, 0)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 887 | Slice_type = make_type("Slice", slice_type, Slice_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 888 | if (!Slice_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 889 | ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 890 | if (!ExtSlice_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 891 | Index_type = make_type("Index", slice_type, Index_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 892 | if (!Index_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 893 | boolop_type = make_type("boolop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 894 | if (!boolop_type) return 0; |
| 895 | if (!add_attributes(boolop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 896 | And_type = make_type("And", boolop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 897 | if (!And_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 898 | And_singleton = PyType_GenericNew(And_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 899 | if (!And_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 900 | Or_type = make_type("Or", boolop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 901 | if (!Or_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 902 | Or_singleton = PyType_GenericNew(Or_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 903 | if (!Or_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 904 | operator_type = make_type("operator", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 905 | if (!operator_type) return 0; |
| 906 | if (!add_attributes(operator_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 907 | Add_type = make_type("Add", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 908 | if (!Add_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 909 | Add_singleton = PyType_GenericNew(Add_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 910 | if (!Add_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 911 | Sub_type = make_type("Sub", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 912 | if (!Sub_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 913 | Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 914 | if (!Sub_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 915 | Mult_type = make_type("Mult", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 916 | if (!Mult_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 917 | Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 918 | if (!Mult_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 919 | Div_type = make_type("Div", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 920 | if (!Div_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 921 | Div_singleton = PyType_GenericNew(Div_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 922 | if (!Div_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 923 | Mod_type = make_type("Mod", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 924 | if (!Mod_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 925 | Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 926 | if (!Mod_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 927 | Pow_type = make_type("Pow", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 928 | if (!Pow_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 929 | Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 930 | if (!Pow_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 931 | LShift_type = make_type("LShift", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 932 | if (!LShift_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 933 | LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 934 | if (!LShift_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 935 | RShift_type = make_type("RShift", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 936 | if (!RShift_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 937 | RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 938 | if (!RShift_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 939 | BitOr_type = make_type("BitOr", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 940 | if (!BitOr_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 941 | BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 942 | if (!BitOr_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 943 | BitXor_type = make_type("BitXor", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 944 | if (!BitXor_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 945 | BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 946 | if (!BitXor_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 947 | BitAnd_type = make_type("BitAnd", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 948 | if (!BitAnd_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 949 | BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 950 | if (!BitAnd_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 951 | FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 952 | if (!FloorDiv_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 953 | FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 954 | if (!FloorDiv_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 955 | unaryop_type = make_type("unaryop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 956 | if (!unaryop_type) return 0; |
| 957 | if (!add_attributes(unaryop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 958 | Invert_type = make_type("Invert", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 959 | if (!Invert_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 960 | Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 961 | if (!Invert_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 962 | Not_type = make_type("Not", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 963 | if (!Not_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 964 | Not_singleton = PyType_GenericNew(Not_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 965 | if (!Not_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 966 | UAdd_type = make_type("UAdd", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 967 | if (!UAdd_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 968 | UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 969 | if (!UAdd_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 970 | USub_type = make_type("USub", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 971 | if (!USub_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 972 | USub_singleton = PyType_GenericNew(USub_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 973 | if (!USub_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 974 | cmpop_type = make_type("cmpop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 975 | if (!cmpop_type) return 0; |
| 976 | if (!add_attributes(cmpop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 977 | Eq_type = make_type("Eq", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 978 | if (!Eq_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 979 | Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 980 | if (!Eq_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 981 | NotEq_type = make_type("NotEq", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 982 | if (!NotEq_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 983 | NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 984 | if (!NotEq_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 985 | Lt_type = make_type("Lt", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 986 | if (!Lt_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 987 | Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 988 | if (!Lt_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 989 | LtE_type = make_type("LtE", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 990 | if (!LtE_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 991 | LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 992 | if (!LtE_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 993 | Gt_type = make_type("Gt", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 994 | if (!Gt_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 995 | Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 996 | if (!Gt_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 997 | GtE_type = make_type("GtE", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 998 | if (!GtE_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 999 | GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1000 | if (!GtE_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1001 | Is_type = make_type("Is", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1002 | if (!Is_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1003 | Is_singleton = PyType_GenericNew(Is_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1004 | if (!Is_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1005 | IsNot_type = make_type("IsNot", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1006 | if (!IsNot_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1007 | IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1008 | if (!IsNot_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1009 | In_type = make_type("In", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1010 | if (!In_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1011 | In_singleton = PyType_GenericNew(In_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1012 | if (!In_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1013 | NotIn_type = make_type("NotIn", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1014 | if (!NotIn_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1015 | NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1016 | if (!NotIn_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1017 | comprehension_type = make_type("comprehension", &AST_type, |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1018 | comprehension_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1019 | if (!comprehension_type) return 0; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 1020 | excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1021 | if (!excepthandler_type) return 0; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 1022 | if (!add_attributes(excepthandler_type, excepthandler_attributes, 2)) |
| 1023 | return 0; |
| 1024 | ExceptHandler_type = make_type("ExceptHandler", excepthandler_type, |
| 1025 | ExceptHandler_fields, 3); |
| 1026 | if (!ExceptHandler_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1027 | arguments_type = make_type("arguments", &AST_type, arguments_fields, 8); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1028 | if (!arguments_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1029 | arg_type = make_type("arg", &AST_type, arg_fields, 2); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1030 | if (!arg_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1031 | keyword_type = make_type("keyword", &AST_type, keyword_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1032 | if (!keyword_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1033 | alias_type = make_type("alias", &AST_type, alias_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1034 | if (!alias_type) return 0; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1035 | withitem_type = make_type("withitem", &AST_type, withitem_fields, 2); |
| 1036 | if (!withitem_type) return 0; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1037 | initialized = 1; |
| 1038 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1039 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 1040 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1041 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 1042 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 1043 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 1044 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 1045 | arena); |
| 1046 | static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena); |
| 1047 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 1048 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 1049 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 1050 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 1051 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 1052 | arena); |
| 1053 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 1054 | arena); |
| 1055 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 1056 | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
| 1057 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 1058 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1059 | static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1060 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1061 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1062 | Module(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1063 | { |
| 1064 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1065 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1066 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1067 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1068 | p->kind = Module_kind; |
| 1069 | p->v.Module.body = body; |
| 1070 | return p; |
| 1071 | } |
| 1072 | |
| 1073 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1074 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1075 | { |
| 1076 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1077 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1078 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1079 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1080 | p->kind = Interactive_kind; |
| 1081 | p->v.Interactive.body = body; |
| 1082 | return p; |
| 1083 | } |
| 1084 | |
| 1085 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1086 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1087 | { |
| 1088 | mod_ty p; |
| 1089 | if (!body) { |
| 1090 | PyErr_SetString(PyExc_ValueError, |
| 1091 | "field body is required for Expression"); |
| 1092 | return NULL; |
| 1093 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1094 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1095 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1096 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1097 | p->kind = Expression_kind; |
| 1098 | p->v.Expression.body = body; |
| 1099 | return p; |
| 1100 | } |
| 1101 | |
| 1102 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1103 | Suite(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1104 | { |
| 1105 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1106 | p = (mod_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 = Suite_kind; |
| 1110 | p->v.Suite.body = body; |
| 1111 | return p; |
| 1112 | } |
| 1113 | |
| 1114 | stmt_ty |
| 1115 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1116 | decorator_list, expr_ty returns, int lineno, int col_offset, |
| 1117 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1118 | { |
| 1119 | stmt_ty p; |
| 1120 | if (!name) { |
| 1121 | PyErr_SetString(PyExc_ValueError, |
| 1122 | "field name is required for FunctionDef"); |
| 1123 | return NULL; |
| 1124 | } |
| 1125 | if (!args) { |
| 1126 | PyErr_SetString(PyExc_ValueError, |
| 1127 | "field args is required for FunctionDef"); |
| 1128 | return NULL; |
| 1129 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1130 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1131 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1132 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1133 | p->kind = FunctionDef_kind; |
| 1134 | p->v.FunctionDef.name = name; |
| 1135 | p->v.FunctionDef.args = args; |
| 1136 | p->v.FunctionDef.body = body; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1137 | p->v.FunctionDef.decorator_list = decorator_list; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1138 | p->v.FunctionDef.returns = returns; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1139 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1140 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1141 | return p; |
| 1142 | } |
| 1143 | |
| 1144 | stmt_ty |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 1145 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, expr_ty |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1146 | starargs, expr_ty kwargs, asdl_seq * body, asdl_seq * decorator_list, |
| 1147 | int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1148 | { |
| 1149 | stmt_ty p; |
| 1150 | if (!name) { |
| 1151 | PyErr_SetString(PyExc_ValueError, |
| 1152 | "field name is required for ClassDef"); |
| 1153 | return NULL; |
| 1154 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1155 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1156 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1157 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1158 | p->kind = ClassDef_kind; |
| 1159 | p->v.ClassDef.name = name; |
| 1160 | p->v.ClassDef.bases = bases; |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 1161 | p->v.ClassDef.keywords = keywords; |
| 1162 | p->v.ClassDef.starargs = starargs; |
| 1163 | p->v.ClassDef.kwargs = kwargs; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1164 | p->v.ClassDef.body = body; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1165 | p->v.ClassDef.decorator_list = decorator_list; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 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 | Return(expr_ty value, 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 = Return_kind; |
| 1179 | p->v.Return.value = value; |
| 1180 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1181 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1182 | return p; |
| 1183 | } |
| 1184 | |
| 1185 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1186 | Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1187 | { |
| 1188 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1189 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1190 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1191 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1192 | p->kind = Delete_kind; |
| 1193 | p->v.Delete.targets = targets; |
| 1194 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1195 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1196 | return p; |
| 1197 | } |
| 1198 | |
| 1199 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1200 | Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena |
| 1201 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1202 | { |
| 1203 | stmt_ty p; |
| 1204 | if (!value) { |
| 1205 | PyErr_SetString(PyExc_ValueError, |
| 1206 | "field value is required for Assign"); |
| 1207 | return NULL; |
| 1208 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1209 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1210 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1211 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1212 | p->kind = Assign_kind; |
| 1213 | p->v.Assign.targets = targets; |
| 1214 | p->v.Assign.value = value; |
| 1215 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1216 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1217 | return p; |
| 1218 | } |
| 1219 | |
| 1220 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1221 | AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int |
| 1222 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1223 | { |
| 1224 | stmt_ty p; |
| 1225 | if (!target) { |
| 1226 | PyErr_SetString(PyExc_ValueError, |
| 1227 | "field target is required for AugAssign"); |
| 1228 | return NULL; |
| 1229 | } |
| 1230 | if (!op) { |
| 1231 | PyErr_SetString(PyExc_ValueError, |
| 1232 | "field op is required for AugAssign"); |
| 1233 | return NULL; |
| 1234 | } |
| 1235 | if (!value) { |
| 1236 | PyErr_SetString(PyExc_ValueError, |
| 1237 | "field value is required for AugAssign"); |
| 1238 | return NULL; |
| 1239 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1240 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1241 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1242 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1243 | p->kind = AugAssign_kind; |
| 1244 | p->v.AugAssign.target = target; |
| 1245 | p->v.AugAssign.op = op; |
| 1246 | p->v.AugAssign.value = value; |
| 1247 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1248 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1249 | return p; |
| 1250 | } |
| 1251 | |
| 1252 | stmt_ty |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1253 | 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] | 1254 | lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1255 | { |
| 1256 | stmt_ty p; |
| 1257 | if (!target) { |
| 1258 | PyErr_SetString(PyExc_ValueError, |
| 1259 | "field target is required for For"); |
| 1260 | return NULL; |
| 1261 | } |
| 1262 | if (!iter) { |
| 1263 | PyErr_SetString(PyExc_ValueError, |
| 1264 | "field iter is required for For"); |
| 1265 | return NULL; |
| 1266 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1267 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1268 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1269 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1270 | p->kind = For_kind; |
| 1271 | p->v.For.target = target; |
| 1272 | p->v.For.iter = iter; |
| 1273 | p->v.For.body = body; |
| 1274 | p->v.For.orelse = orelse; |
| 1275 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1276 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1277 | return p; |
| 1278 | } |
| 1279 | |
| 1280 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1281 | While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1282 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1283 | { |
| 1284 | stmt_ty p; |
| 1285 | if (!test) { |
| 1286 | PyErr_SetString(PyExc_ValueError, |
| 1287 | "field test is required for While"); |
| 1288 | return NULL; |
| 1289 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1290 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1291 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1292 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1293 | p->kind = While_kind; |
| 1294 | p->v.While.test = test; |
| 1295 | p->v.While.body = body; |
| 1296 | p->v.While.orelse = orelse; |
| 1297 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1298 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1299 | return p; |
| 1300 | } |
| 1301 | |
| 1302 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1303 | If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1304 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1305 | { |
| 1306 | stmt_ty p; |
| 1307 | if (!test) { |
| 1308 | PyErr_SetString(PyExc_ValueError, |
| 1309 | "field test is required for If"); |
| 1310 | return NULL; |
| 1311 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1312 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1313 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1314 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1315 | p->kind = If_kind; |
| 1316 | p->v.If.test = test; |
| 1317 | p->v.If.body = body; |
| 1318 | p->v.If.orelse = orelse; |
| 1319 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1320 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1321 | return p; |
| 1322 | } |
| 1323 | |
| 1324 | stmt_ty |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1325 | With(asdl_seq * items, asdl_seq * body, int lineno, int col_offset, PyArena |
| 1326 | *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1327 | { |
| 1328 | stmt_ty p; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1329 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1330 | if (!p) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1331 | return NULL; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1332 | p->kind = With_kind; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1333 | p->v.With.items = items; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1334 | p->v.With.body = body; |
| 1335 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1336 | p->col_offset = col_offset; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1337 | return p; |
| 1338 | } |
| 1339 | |
| 1340 | stmt_ty |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 1341 | Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1342 | { |
| 1343 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1344 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1345 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1346 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1347 | p->kind = Raise_kind; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 1348 | p->v.Raise.exc = exc; |
| 1349 | p->v.Raise.cause = cause; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1350 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1351 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1352 | return p; |
| 1353 | } |
| 1354 | |
| 1355 | stmt_ty |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 1356 | Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * |
| 1357 | finalbody, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1358 | { |
| 1359 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1360 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1361 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1362 | return NULL; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 1363 | p->kind = Try_kind; |
| 1364 | p->v.Try.body = body; |
| 1365 | p->v.Try.handlers = handlers; |
| 1366 | p->v.Try.orelse = orelse; |
| 1367 | p->v.Try.finalbody = finalbody; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1368 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1369 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1370 | return p; |
| 1371 | } |
| 1372 | |
| 1373 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1374 | 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] | 1375 | { |
| 1376 | stmt_ty p; |
| 1377 | if (!test) { |
| 1378 | PyErr_SetString(PyExc_ValueError, |
| 1379 | "field test is required for Assert"); |
| 1380 | return NULL; |
| 1381 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1382 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1383 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1384 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1385 | p->kind = Assert_kind; |
| 1386 | p->v.Assert.test = test; |
| 1387 | p->v.Assert.msg = msg; |
| 1388 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1389 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1390 | return p; |
| 1391 | } |
| 1392 | |
| 1393 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1394 | Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1395 | { |
| 1396 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1397 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1398 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1399 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1400 | p->kind = Import_kind; |
| 1401 | p->v.Import.names = names; |
| 1402 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1403 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1404 | return p; |
| 1405 | } |
| 1406 | |
| 1407 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1408 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
| 1409 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1410 | { |
| 1411 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1412 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1413 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1414 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1415 | p->kind = ImportFrom_kind; |
| 1416 | p->v.ImportFrom.module = module; |
| 1417 | p->v.ImportFrom.names = names; |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 1418 | p->v.ImportFrom.level = level; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1419 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1420 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1421 | return p; |
| 1422 | } |
| 1423 | |
| 1424 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1425 | Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1426 | { |
| 1427 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1428 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1429 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1430 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1431 | p->kind = Global_kind; |
| 1432 | p->v.Global.names = names; |
| 1433 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1434 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1435 | return p; |
| 1436 | } |
| 1437 | |
| 1438 | stmt_ty |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 1439 | Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
| 1440 | { |
| 1441 | stmt_ty p; |
| 1442 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1443 | if (!p) |
| 1444 | return NULL; |
| 1445 | p->kind = Nonlocal_kind; |
| 1446 | p->v.Nonlocal.names = names; |
| 1447 | p->lineno = lineno; |
| 1448 | p->col_offset = col_offset; |
| 1449 | return p; |
| 1450 | } |
| 1451 | |
| 1452 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1453 | Expr(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1454 | { |
| 1455 | stmt_ty p; |
| 1456 | if (!value) { |
| 1457 | PyErr_SetString(PyExc_ValueError, |
| 1458 | "field value is required for Expr"); |
| 1459 | return NULL; |
| 1460 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1461 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1462 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1463 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1464 | p->kind = Expr_kind; |
| 1465 | p->v.Expr.value = value; |
| 1466 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1467 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1468 | return p; |
| 1469 | } |
| 1470 | |
| 1471 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1472 | Pass(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1473 | { |
| 1474 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1475 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1476 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1477 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1478 | p->kind = Pass_kind; |
| 1479 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1480 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1481 | return p; |
| 1482 | } |
| 1483 | |
| 1484 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1485 | Break(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1486 | { |
| 1487 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1488 | p = (stmt_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 = Break_kind; |
| 1492 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1493 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1494 | return p; |
| 1495 | } |
| 1496 | |
| 1497 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1498 | Continue(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1499 | { |
| 1500 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1501 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1502 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1503 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1504 | p->kind = Continue_kind; |
| 1505 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1506 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1507 | return p; |
| 1508 | } |
| 1509 | |
| 1510 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1511 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1512 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1513 | { |
| 1514 | expr_ty p; |
| 1515 | if (!op) { |
| 1516 | PyErr_SetString(PyExc_ValueError, |
| 1517 | "field op is required for BoolOp"); |
| 1518 | return NULL; |
| 1519 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1520 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1521 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1522 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1523 | p->kind = BoolOp_kind; |
| 1524 | p->v.BoolOp.op = op; |
| 1525 | p->v.BoolOp.values = values; |
| 1526 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1527 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1528 | return p; |
| 1529 | } |
| 1530 | |
| 1531 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1532 | BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset, |
| 1533 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1534 | { |
| 1535 | expr_ty p; |
| 1536 | if (!left) { |
| 1537 | PyErr_SetString(PyExc_ValueError, |
| 1538 | "field left is required for BinOp"); |
| 1539 | return NULL; |
| 1540 | } |
| 1541 | if (!op) { |
| 1542 | PyErr_SetString(PyExc_ValueError, |
| 1543 | "field op is required for BinOp"); |
| 1544 | return NULL; |
| 1545 | } |
| 1546 | if (!right) { |
| 1547 | PyErr_SetString(PyExc_ValueError, |
| 1548 | "field right is required for BinOp"); |
| 1549 | return NULL; |
| 1550 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1551 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1552 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1553 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1554 | p->kind = BinOp_kind; |
| 1555 | p->v.BinOp.left = left; |
| 1556 | p->v.BinOp.op = op; |
| 1557 | p->v.BinOp.right = right; |
| 1558 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1559 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1560 | return p; |
| 1561 | } |
| 1562 | |
| 1563 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1564 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena |
| 1565 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1566 | { |
| 1567 | expr_ty p; |
| 1568 | if (!op) { |
| 1569 | PyErr_SetString(PyExc_ValueError, |
| 1570 | "field op is required for UnaryOp"); |
| 1571 | return NULL; |
| 1572 | } |
| 1573 | if (!operand) { |
| 1574 | PyErr_SetString(PyExc_ValueError, |
| 1575 | "field operand is required for UnaryOp"); |
| 1576 | return NULL; |
| 1577 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1578 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1579 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1580 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1581 | p->kind = UnaryOp_kind; |
| 1582 | p->v.UnaryOp.op = op; |
| 1583 | p->v.UnaryOp.operand = operand; |
| 1584 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1585 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1586 | return p; |
| 1587 | } |
| 1588 | |
| 1589 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1590 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena |
| 1591 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1592 | { |
| 1593 | expr_ty p; |
| 1594 | if (!args) { |
| 1595 | PyErr_SetString(PyExc_ValueError, |
| 1596 | "field args is required for Lambda"); |
| 1597 | return NULL; |
| 1598 | } |
| 1599 | if (!body) { |
| 1600 | PyErr_SetString(PyExc_ValueError, |
| 1601 | "field body is required for Lambda"); |
| 1602 | return NULL; |
| 1603 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1604 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1605 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1606 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1607 | p->kind = Lambda_kind; |
| 1608 | p->v.Lambda.args = args; |
| 1609 | p->v.Lambda.body = body; |
| 1610 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1611 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1612 | return p; |
| 1613 | } |
| 1614 | |
| 1615 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1616 | IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset, |
| 1617 | PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1618 | { |
| 1619 | expr_ty p; |
| 1620 | if (!test) { |
| 1621 | PyErr_SetString(PyExc_ValueError, |
| 1622 | "field test is required for IfExp"); |
| 1623 | return NULL; |
| 1624 | } |
| 1625 | if (!body) { |
| 1626 | PyErr_SetString(PyExc_ValueError, |
| 1627 | "field body is required for IfExp"); |
| 1628 | return NULL; |
| 1629 | } |
| 1630 | if (!orelse) { |
| 1631 | PyErr_SetString(PyExc_ValueError, |
| 1632 | "field orelse is required for IfExp"); |
| 1633 | return NULL; |
| 1634 | } |
| 1635 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1636 | if (!p) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1637 | return NULL; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1638 | p->kind = IfExp_kind; |
| 1639 | p->v.IfExp.test = test; |
| 1640 | p->v.IfExp.body = body; |
| 1641 | p->v.IfExp.orelse = orelse; |
| 1642 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1643 | p->col_offset = col_offset; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1644 | return p; |
| 1645 | } |
| 1646 | |
| 1647 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1648 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1649 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1650 | { |
| 1651 | expr_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1652 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1653 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1654 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1655 | p->kind = Dict_kind; |
| 1656 | p->v.Dict.keys = keys; |
| 1657 | p->v.Dict.values = values; |
| 1658 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1659 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1660 | return p; |
| 1661 | } |
| 1662 | |
| 1663 | expr_ty |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1664 | Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena) |
| 1665 | { |
| 1666 | expr_ty p; |
| 1667 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1668 | if (!p) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1669 | return NULL; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1670 | p->kind = Set_kind; |
| 1671 | p->v.Set.elts = elts; |
| 1672 | p->lineno = lineno; |
| 1673 | p->col_offset = col_offset; |
| 1674 | return p; |
| 1675 | } |
| 1676 | |
| 1677 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1678 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1679 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1680 | { |
| 1681 | expr_ty p; |
| 1682 | if (!elt) { |
| 1683 | PyErr_SetString(PyExc_ValueError, |
| 1684 | "field elt is required for ListComp"); |
| 1685 | return NULL; |
| 1686 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1687 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1688 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1689 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1690 | p->kind = ListComp_kind; |
| 1691 | p->v.ListComp.elt = elt; |
| 1692 | p->v.ListComp.generators = generators; |
| 1693 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1694 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1695 | return p; |
| 1696 | } |
| 1697 | |
| 1698 | expr_ty |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 1699 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena |
| 1700 | *arena) |
| 1701 | { |
| 1702 | expr_ty p; |
| 1703 | if (!elt) { |
| 1704 | PyErr_SetString(PyExc_ValueError, |
| 1705 | "field elt is required for SetComp"); |
| 1706 | return NULL; |
| 1707 | } |
| 1708 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1709 | if (!p) |
| 1710 | return NULL; |
| 1711 | p->kind = SetComp_kind; |
| 1712 | p->v.SetComp.elt = elt; |
| 1713 | p->v.SetComp.generators = generators; |
| 1714 | p->lineno = lineno; |
| 1715 | p->col_offset = col_offset; |
| 1716 | return p; |
| 1717 | } |
| 1718 | |
| 1719 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 1720 | DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int |
| 1721 | col_offset, PyArena *arena) |
| 1722 | { |
| 1723 | expr_ty p; |
| 1724 | if (!key) { |
| 1725 | PyErr_SetString(PyExc_ValueError, |
| 1726 | "field key is required for DictComp"); |
| 1727 | return NULL; |
| 1728 | } |
| 1729 | if (!value) { |
| 1730 | PyErr_SetString(PyExc_ValueError, |
| 1731 | "field value is required for DictComp"); |
| 1732 | return NULL; |
| 1733 | } |
| 1734 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1735 | if (!p) |
| 1736 | return NULL; |
| 1737 | p->kind = DictComp_kind; |
| 1738 | p->v.DictComp.key = key; |
| 1739 | p->v.DictComp.value = value; |
| 1740 | p->v.DictComp.generators = generators; |
| 1741 | p->lineno = lineno; |
| 1742 | p->col_offset = col_offset; |
| 1743 | return p; |
| 1744 | } |
| 1745 | |
| 1746 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1747 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1748 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1749 | { |
| 1750 | expr_ty p; |
| 1751 | if (!elt) { |
| 1752 | PyErr_SetString(PyExc_ValueError, |
| 1753 | "field elt is required for GeneratorExp"); |
| 1754 | return NULL; |
| 1755 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1756 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1757 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1758 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1759 | p->kind = GeneratorExp_kind; |
| 1760 | p->v.GeneratorExp.elt = elt; |
| 1761 | p->v.GeneratorExp.generators = generators; |
| 1762 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1763 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1764 | return p; |
| 1765 | } |
| 1766 | |
| 1767 | expr_ty |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 1768 | Yield(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1769 | { |
| 1770 | expr_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1771 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1772 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1773 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1774 | p->kind = Yield_kind; |
| 1775 | p->v.Yield.value = value; |
| 1776 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1777 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1778 | return p; |
| 1779 | } |
| 1780 | |
| 1781 | expr_ty |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 1782 | YieldFrom(expr_ty value, int lineno, int col_offset, PyArena *arena) |
| 1783 | { |
| 1784 | expr_ty p; |
| 1785 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1786 | if (!p) |
| 1787 | return NULL; |
| 1788 | p->kind = YieldFrom_kind; |
| 1789 | p->v.YieldFrom.value = value; |
| 1790 | p->lineno = lineno; |
| 1791 | p->col_offset = col_offset; |
| 1792 | return p; |
| 1793 | } |
| 1794 | |
| 1795 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1796 | Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno, |
| 1797 | int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1798 | { |
| 1799 | expr_ty p; |
| 1800 | if (!left) { |
| 1801 | PyErr_SetString(PyExc_ValueError, |
| 1802 | "field left is required for Compare"); |
| 1803 | return NULL; |
| 1804 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1805 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1806 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1807 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1808 | p->kind = Compare_kind; |
| 1809 | p->v.Compare.left = left; |
| 1810 | p->v.Compare.ops = ops; |
| 1811 | p->v.Compare.comparators = comparators; |
| 1812 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1813 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1814 | return p; |
| 1815 | } |
| 1816 | |
| 1817 | expr_ty |
| 1818 | 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] | 1819 | expr_ty kwargs, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1820 | { |
| 1821 | expr_ty p; |
| 1822 | if (!func) { |
| 1823 | PyErr_SetString(PyExc_ValueError, |
| 1824 | "field func is required for Call"); |
| 1825 | return NULL; |
| 1826 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1827 | p = (expr_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->kind = Call_kind; |
| 1831 | p->v.Call.func = func; |
| 1832 | p->v.Call.args = args; |
| 1833 | p->v.Call.keywords = keywords; |
| 1834 | p->v.Call.starargs = starargs; |
| 1835 | p->v.Call.kwargs = kwargs; |
| 1836 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1837 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1838 | return p; |
| 1839 | } |
| 1840 | |
| 1841 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1842 | Num(object n, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1843 | { |
| 1844 | expr_ty p; |
| 1845 | if (!n) { |
| 1846 | PyErr_SetString(PyExc_ValueError, |
| 1847 | "field n is required for Num"); |
| 1848 | return NULL; |
| 1849 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1850 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1851 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1852 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1853 | p->kind = Num_kind; |
| 1854 | p->v.Num.n = n; |
| 1855 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1856 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1857 | return p; |
| 1858 | } |
| 1859 | |
| 1860 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1861 | Str(string s, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1862 | { |
| 1863 | expr_ty p; |
| 1864 | if (!s) { |
| 1865 | PyErr_SetString(PyExc_ValueError, |
| 1866 | "field s is required for Str"); |
| 1867 | return NULL; |
| 1868 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1869 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1870 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1871 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1872 | p->kind = Str_kind; |
| 1873 | p->v.Str.s = s; |
| 1874 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1875 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1876 | return p; |
| 1877 | } |
| 1878 | |
| 1879 | expr_ty |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 1880 | Bytes(bytes s, int lineno, int col_offset, PyArena *arena) |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1881 | { |
| 1882 | expr_ty p; |
| 1883 | if (!s) { |
| 1884 | PyErr_SetString(PyExc_ValueError, |
| 1885 | "field s is required for Bytes"); |
| 1886 | return NULL; |
| 1887 | } |
| 1888 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1889 | if (!p) |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1890 | return NULL; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1891 | p->kind = Bytes_kind; |
| 1892 | p->v.Bytes.s = s; |
| 1893 | p->lineno = lineno; |
| 1894 | p->col_offset = col_offset; |
| 1895 | return p; |
| 1896 | } |
| 1897 | |
| 1898 | expr_ty |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1899 | Ellipsis(int lineno, int col_offset, PyArena *arena) |
| 1900 | { |
| 1901 | expr_ty p; |
| 1902 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1903 | if (!p) |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1904 | return NULL; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1905 | p->kind = Ellipsis_kind; |
| 1906 | p->lineno = lineno; |
| 1907 | p->col_offset = col_offset; |
| 1908 | return p; |
| 1909 | } |
| 1910 | |
| 1911 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1912 | Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int |
| 1913 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1914 | { |
| 1915 | expr_ty p; |
| 1916 | if (!value) { |
| 1917 | PyErr_SetString(PyExc_ValueError, |
| 1918 | "field value is required for Attribute"); |
| 1919 | return NULL; |
| 1920 | } |
| 1921 | if (!attr) { |
| 1922 | PyErr_SetString(PyExc_ValueError, |
| 1923 | "field attr is required for Attribute"); |
| 1924 | return NULL; |
| 1925 | } |
| 1926 | if (!ctx) { |
| 1927 | PyErr_SetString(PyExc_ValueError, |
| 1928 | "field ctx is required for Attribute"); |
| 1929 | return NULL; |
| 1930 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1931 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1932 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1933 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1934 | p->kind = Attribute_kind; |
| 1935 | p->v.Attribute.value = value; |
| 1936 | p->v.Attribute.attr = attr; |
| 1937 | p->v.Attribute.ctx = ctx; |
| 1938 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1939 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1940 | return p; |
| 1941 | } |
| 1942 | |
| 1943 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1944 | Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int |
| 1945 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1946 | { |
| 1947 | expr_ty p; |
| 1948 | if (!value) { |
| 1949 | PyErr_SetString(PyExc_ValueError, |
| 1950 | "field value is required for Subscript"); |
| 1951 | return NULL; |
| 1952 | } |
| 1953 | if (!slice) { |
| 1954 | PyErr_SetString(PyExc_ValueError, |
| 1955 | "field slice is required for Subscript"); |
| 1956 | return NULL; |
| 1957 | } |
| 1958 | if (!ctx) { |
| 1959 | PyErr_SetString(PyExc_ValueError, |
| 1960 | "field ctx is required for Subscript"); |
| 1961 | return NULL; |
| 1962 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1963 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1964 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1965 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1966 | p->kind = Subscript_kind; |
| 1967 | p->v.Subscript.value = value; |
| 1968 | p->v.Subscript.slice = slice; |
| 1969 | p->v.Subscript.ctx = ctx; |
| 1970 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1971 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1972 | return p; |
| 1973 | } |
| 1974 | |
| 1975 | expr_ty |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 1976 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1977 | *arena) |
| 1978 | { |
| 1979 | expr_ty p; |
| 1980 | if (!value) { |
| 1981 | PyErr_SetString(PyExc_ValueError, |
| 1982 | "field value is required for Starred"); |
| 1983 | return NULL; |
| 1984 | } |
| 1985 | if (!ctx) { |
| 1986 | PyErr_SetString(PyExc_ValueError, |
| 1987 | "field ctx is required for Starred"); |
| 1988 | return NULL; |
| 1989 | } |
| 1990 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1991 | if (!p) |
| 1992 | return NULL; |
| 1993 | p->kind = Starred_kind; |
| 1994 | p->v.Starred.value = value; |
| 1995 | p->v.Starred.ctx = ctx; |
| 1996 | p->lineno = lineno; |
| 1997 | p->col_offset = col_offset; |
| 1998 | return p; |
| 1999 | } |
| 2000 | |
| 2001 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2002 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 2003 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2004 | { |
| 2005 | expr_ty p; |
| 2006 | if (!id) { |
| 2007 | PyErr_SetString(PyExc_ValueError, |
| 2008 | "field id is required for Name"); |
| 2009 | return NULL; |
| 2010 | } |
| 2011 | if (!ctx) { |
| 2012 | PyErr_SetString(PyExc_ValueError, |
| 2013 | "field ctx is required for Name"); |
| 2014 | return NULL; |
| 2015 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2016 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2017 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2018 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2019 | p->kind = Name_kind; |
| 2020 | p->v.Name.id = id; |
| 2021 | p->v.Name.ctx = ctx; |
| 2022 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2023 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2024 | return p; |
| 2025 | } |
| 2026 | |
| 2027 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2028 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 2029 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2030 | { |
| 2031 | expr_ty p; |
| 2032 | if (!ctx) { |
| 2033 | PyErr_SetString(PyExc_ValueError, |
| 2034 | "field ctx is required for List"); |
| 2035 | return NULL; |
| 2036 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2037 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2038 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2039 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2040 | p->kind = List_kind; |
| 2041 | p->v.List.elts = elts; |
| 2042 | p->v.List.ctx = ctx; |
| 2043 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2044 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2045 | return p; |
| 2046 | } |
| 2047 | |
| 2048 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2049 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 2050 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2051 | { |
| 2052 | expr_ty p; |
| 2053 | if (!ctx) { |
| 2054 | PyErr_SetString(PyExc_ValueError, |
| 2055 | "field ctx is required for Tuple"); |
| 2056 | return NULL; |
| 2057 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2058 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2059 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2060 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2061 | p->kind = Tuple_kind; |
| 2062 | p->v.Tuple.elts = elts; |
| 2063 | p->v.Tuple.ctx = ctx; |
| 2064 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2065 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2066 | return p; |
| 2067 | } |
| 2068 | |
| 2069 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2070 | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2071 | { |
| 2072 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2073 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2074 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2075 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2076 | p->kind = Slice_kind; |
| 2077 | p->v.Slice.lower = lower; |
| 2078 | p->v.Slice.upper = upper; |
| 2079 | p->v.Slice.step = step; |
| 2080 | return p; |
| 2081 | } |
| 2082 | |
| 2083 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2084 | ExtSlice(asdl_seq * dims, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2085 | { |
| 2086 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2087 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2088 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2089 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2090 | p->kind = ExtSlice_kind; |
| 2091 | p->v.ExtSlice.dims = dims; |
| 2092 | return p; |
| 2093 | } |
| 2094 | |
| 2095 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2096 | Index(expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2097 | { |
| 2098 | slice_ty p; |
| 2099 | if (!value) { |
| 2100 | PyErr_SetString(PyExc_ValueError, |
| 2101 | "field value is required for Index"); |
| 2102 | return NULL; |
| 2103 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2104 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2105 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2106 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2107 | p->kind = Index_kind; |
| 2108 | p->v.Index.value = value; |
| 2109 | return p; |
| 2110 | } |
| 2111 | |
| 2112 | comprehension_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2113 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2114 | { |
| 2115 | comprehension_ty p; |
| 2116 | if (!target) { |
| 2117 | PyErr_SetString(PyExc_ValueError, |
| 2118 | "field target is required for comprehension"); |
| 2119 | return NULL; |
| 2120 | } |
| 2121 | if (!iter) { |
| 2122 | PyErr_SetString(PyExc_ValueError, |
| 2123 | "field iter is required for comprehension"); |
| 2124 | return NULL; |
| 2125 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2126 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2127 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2128 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2129 | p->target = target; |
| 2130 | p->iter = iter; |
| 2131 | p->ifs = ifs; |
| 2132 | return p; |
| 2133 | } |
| 2134 | |
| 2135 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 2136 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2137 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2138 | { |
| 2139 | excepthandler_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2140 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2141 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2142 | return NULL; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 2143 | p->kind = ExceptHandler_kind; |
| 2144 | p->v.ExceptHandler.type = type; |
| 2145 | p->v.ExceptHandler.name = name; |
| 2146 | p->v.ExceptHandler.body = body; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2147 | p->lineno = lineno; |
| 2148 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2149 | return p; |
| 2150 | } |
| 2151 | |
| 2152 | arguments_ty |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2153 | arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation, |
| 2154 | asdl_seq * kwonlyargs, identifier kwarg, expr_ty kwargannotation, |
| 2155 | asdl_seq * defaults, asdl_seq * kw_defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2156 | { |
| 2157 | arguments_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2158 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2159 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2160 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2161 | p->args = args; |
| 2162 | p->vararg = vararg; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2163 | p->varargannotation = varargannotation; |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 2164 | p->kwonlyargs = kwonlyargs; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2165 | p->kwarg = kwarg; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2166 | p->kwargannotation = kwargannotation; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2167 | p->defaults = defaults; |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 2168 | p->kw_defaults = kw_defaults; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2169 | return p; |
| 2170 | } |
| 2171 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2172 | arg_ty |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2173 | arg(identifier arg, expr_ty annotation, PyArena *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2174 | { |
| 2175 | arg_ty p; |
| 2176 | if (!arg) { |
| 2177 | PyErr_SetString(PyExc_ValueError, |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2178 | "field arg is required for arg"); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2179 | return NULL; |
| 2180 | } |
| 2181 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2182 | if (!p) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2183 | return NULL; |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2184 | p->arg = arg; |
| 2185 | p->annotation = annotation; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2186 | return p; |
| 2187 | } |
| 2188 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2189 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2190 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2191 | { |
| 2192 | keyword_ty p; |
| 2193 | if (!arg) { |
| 2194 | PyErr_SetString(PyExc_ValueError, |
| 2195 | "field arg is required for keyword"); |
| 2196 | return NULL; |
| 2197 | } |
| 2198 | if (!value) { |
| 2199 | PyErr_SetString(PyExc_ValueError, |
| 2200 | "field value is required for keyword"); |
| 2201 | return NULL; |
| 2202 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2203 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2204 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2205 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2206 | p->arg = arg; |
| 2207 | p->value = value; |
| 2208 | return p; |
| 2209 | } |
| 2210 | |
| 2211 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2212 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2213 | { |
| 2214 | alias_ty p; |
| 2215 | if (!name) { |
| 2216 | PyErr_SetString(PyExc_ValueError, |
| 2217 | "field name is required for alias"); |
| 2218 | return NULL; |
| 2219 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2220 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2221 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2222 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2223 | p->name = name; |
| 2224 | p->asname = asname; |
| 2225 | return p; |
| 2226 | } |
| 2227 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2228 | withitem_ty |
| 2229 | withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) |
| 2230 | { |
| 2231 | withitem_ty p; |
| 2232 | if (!context_expr) { |
| 2233 | PyErr_SetString(PyExc_ValueError, |
| 2234 | "field context_expr is required for withitem"); |
| 2235 | return NULL; |
| 2236 | } |
| 2237 | p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2238 | if (!p) |
| 2239 | return NULL; |
| 2240 | p->context_expr = context_expr; |
| 2241 | p->optional_vars = optional_vars; |
| 2242 | return p; |
| 2243 | } |
| 2244 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2245 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2246 | PyObject* |
| 2247 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2248 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2249 | mod_ty o = (mod_ty)_o; |
| 2250 | PyObject *result = NULL, *value = NULL; |
| 2251 | if (!o) { |
| 2252 | Py_INCREF(Py_None); |
| 2253 | return Py_None; |
| 2254 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2255 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2256 | switch (o->kind) { |
| 2257 | case Module_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2258 | result = PyType_GenericNew(Module_type, NULL, NULL); |
| 2259 | if (!result) goto failed; |
| 2260 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 2261 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2262 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2263 | goto failed; |
| 2264 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2265 | break; |
| 2266 | case Interactive_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2267 | result = PyType_GenericNew(Interactive_type, NULL, NULL); |
| 2268 | if (!result) goto failed; |
| 2269 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 2270 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2271 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2272 | goto failed; |
| 2273 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2274 | break; |
| 2275 | case Expression_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2276 | result = PyType_GenericNew(Expression_type, NULL, NULL); |
| 2277 | if (!result) goto failed; |
| 2278 | value = ast2obj_expr(o->v.Expression.body); |
| 2279 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2280 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2281 | goto failed; |
| 2282 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2283 | break; |
| 2284 | case Suite_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2285 | result = PyType_GenericNew(Suite_type, NULL, NULL); |
| 2286 | if (!result) goto failed; |
| 2287 | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
| 2288 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2289 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2290 | goto failed; |
| 2291 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2292 | break; |
| 2293 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2294 | return result; |
| 2295 | failed: |
| 2296 | Py_XDECREF(value); |
| 2297 | Py_XDECREF(result); |
| 2298 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2299 | } |
| 2300 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2301 | PyObject* |
| 2302 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2303 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2304 | stmt_ty o = (stmt_ty)_o; |
| 2305 | PyObject *result = NULL, *value = NULL; |
| 2306 | if (!o) { |
| 2307 | Py_INCREF(Py_None); |
| 2308 | return Py_None; |
| 2309 | } |
| 2310 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2311 | switch (o->kind) { |
| 2312 | case FunctionDef_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2313 | result = PyType_GenericNew(FunctionDef_type, NULL, NULL); |
| 2314 | if (!result) goto failed; |
| 2315 | value = ast2obj_identifier(o->v.FunctionDef.name); |
| 2316 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2317 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2318 | goto failed; |
| 2319 | Py_DECREF(value); |
| 2320 | value = ast2obj_arguments(o->v.FunctionDef.args); |
| 2321 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2322 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2323 | goto failed; |
| 2324 | Py_DECREF(value); |
| 2325 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 2326 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2327 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2328 | goto failed; |
| 2329 | Py_DECREF(value); |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2330 | value = ast2obj_list(o->v.FunctionDef.decorator_list, |
| 2331 | ast2obj_expr); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2332 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2333 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2334 | -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2335 | goto failed; |
| 2336 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2337 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 2338 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2339 | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2340 | goto failed; |
| 2341 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2342 | break; |
| 2343 | case ClassDef_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2344 | result = PyType_GenericNew(ClassDef_type, NULL, NULL); |
| 2345 | if (!result) goto failed; |
| 2346 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 2347 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2348 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2349 | goto failed; |
| 2350 | Py_DECREF(value); |
| 2351 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 2352 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2353 | if (_PyObject_SetAttrId(result, &PyId_bases, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2354 | goto failed; |
| 2355 | Py_DECREF(value); |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 2356 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 2357 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2358 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 2359 | goto failed; |
| 2360 | Py_DECREF(value); |
| 2361 | value = ast2obj_expr(o->v.ClassDef.starargs); |
| 2362 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2363 | if (_PyObject_SetAttrId(result, &PyId_starargs, value) == -1) |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 2364 | goto failed; |
| 2365 | Py_DECREF(value); |
| 2366 | value = ast2obj_expr(o->v.ClassDef.kwargs); |
| 2367 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2368 | if (_PyObject_SetAttrId(result, &PyId_kwargs, value) == -1) |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 2369 | goto failed; |
| 2370 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2371 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 2372 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2373 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2374 | goto failed; |
| 2375 | Py_DECREF(value); |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2376 | value = ast2obj_list(o->v.ClassDef.decorator_list, |
| 2377 | ast2obj_expr); |
| 2378 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2379 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2380 | -1) |
| 2381 | goto failed; |
| 2382 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2383 | break; |
| 2384 | case Return_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2385 | result = PyType_GenericNew(Return_type, NULL, NULL); |
| 2386 | if (!result) goto failed; |
| 2387 | value = ast2obj_expr(o->v.Return.value); |
| 2388 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2389 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2390 | goto failed; |
| 2391 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2392 | break; |
| 2393 | case Delete_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2394 | result = PyType_GenericNew(Delete_type, NULL, NULL); |
| 2395 | if (!result) goto failed; |
| 2396 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 2397 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2398 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2399 | goto failed; |
| 2400 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2401 | break; |
| 2402 | case Assign_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2403 | result = PyType_GenericNew(Assign_type, NULL, NULL); |
| 2404 | if (!result) goto failed; |
| 2405 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 2406 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2407 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2408 | goto failed; |
| 2409 | Py_DECREF(value); |
| 2410 | value = ast2obj_expr(o->v.Assign.value); |
| 2411 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2412 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2413 | goto failed; |
| 2414 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2415 | break; |
| 2416 | case AugAssign_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2417 | result = PyType_GenericNew(AugAssign_type, NULL, NULL); |
| 2418 | if (!result) goto failed; |
| 2419 | value = ast2obj_expr(o->v.AugAssign.target); |
| 2420 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2421 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2422 | goto failed; |
| 2423 | Py_DECREF(value); |
| 2424 | value = ast2obj_operator(o->v.AugAssign.op); |
| 2425 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2426 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2427 | goto failed; |
| 2428 | Py_DECREF(value); |
| 2429 | value = ast2obj_expr(o->v.AugAssign.value); |
| 2430 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2431 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2432 | goto failed; |
| 2433 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2434 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2435 | case For_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2436 | result = PyType_GenericNew(For_type, NULL, NULL); |
| 2437 | if (!result) goto failed; |
| 2438 | value = ast2obj_expr(o->v.For.target); |
| 2439 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2440 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2441 | goto failed; |
| 2442 | Py_DECREF(value); |
| 2443 | value = ast2obj_expr(o->v.For.iter); |
| 2444 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2445 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2446 | goto failed; |
| 2447 | Py_DECREF(value); |
| 2448 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 2449 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2450 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2451 | goto failed; |
| 2452 | Py_DECREF(value); |
| 2453 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 2454 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2455 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2456 | goto failed; |
| 2457 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2458 | break; |
| 2459 | case While_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2460 | result = PyType_GenericNew(While_type, NULL, NULL); |
| 2461 | if (!result) goto failed; |
| 2462 | value = ast2obj_expr(o->v.While.test); |
| 2463 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2464 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2465 | goto failed; |
| 2466 | Py_DECREF(value); |
| 2467 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 2468 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2469 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2470 | goto failed; |
| 2471 | Py_DECREF(value); |
| 2472 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 2473 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2474 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2475 | goto failed; |
| 2476 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2477 | break; |
| 2478 | case If_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2479 | result = PyType_GenericNew(If_type, NULL, NULL); |
| 2480 | if (!result) goto failed; |
| 2481 | value = ast2obj_expr(o->v.If.test); |
| 2482 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2483 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2484 | goto failed; |
| 2485 | Py_DECREF(value); |
| 2486 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 2487 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2488 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2489 | goto failed; |
| 2490 | Py_DECREF(value); |
| 2491 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 2492 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2493 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2494 | goto failed; |
| 2495 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2496 | break; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2497 | case With_kind: |
| 2498 | result = PyType_GenericNew(With_type, NULL, NULL); |
| 2499 | if (!result) goto failed; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2500 | value = ast2obj_list(o->v.With.items, ast2obj_withitem); |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2501 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2502 | if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2503 | goto failed; |
| 2504 | Py_DECREF(value); |
| 2505 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 2506 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2507 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2508 | goto failed; |
| 2509 | Py_DECREF(value); |
| 2510 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2511 | case Raise_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2512 | result = PyType_GenericNew(Raise_type, NULL, NULL); |
| 2513 | if (!result) goto failed; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2514 | value = ast2obj_expr(o->v.Raise.exc); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2515 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2516 | if (_PyObject_SetAttrId(result, &PyId_exc, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2517 | goto failed; |
| 2518 | Py_DECREF(value); |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2519 | value = ast2obj_expr(o->v.Raise.cause); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2520 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2521 | if (_PyObject_SetAttrId(result, &PyId_cause, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2522 | goto failed; |
| 2523 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2524 | break; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2525 | case Try_kind: |
| 2526 | result = PyType_GenericNew(Try_type, NULL, NULL); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2527 | if (!result) goto failed; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2528 | value = ast2obj_list(o->v.Try.body, ast2obj_stmt); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2529 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2530 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2531 | goto failed; |
| 2532 | Py_DECREF(value); |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2533 | value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2534 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2535 | if (_PyObject_SetAttrId(result, &PyId_handlers, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2536 | goto failed; |
| 2537 | Py_DECREF(value); |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2538 | value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2539 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2540 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2541 | goto failed; |
| 2542 | Py_DECREF(value); |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2543 | value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2544 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2545 | if (_PyObject_SetAttrId(result, &PyId_finalbody, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2546 | goto failed; |
| 2547 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2548 | break; |
| 2549 | case Assert_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2550 | result = PyType_GenericNew(Assert_type, NULL, NULL); |
| 2551 | if (!result) goto failed; |
| 2552 | value = ast2obj_expr(o->v.Assert.test); |
| 2553 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2554 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2555 | goto failed; |
| 2556 | Py_DECREF(value); |
| 2557 | value = ast2obj_expr(o->v.Assert.msg); |
| 2558 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2559 | if (_PyObject_SetAttrId(result, &PyId_msg, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2560 | goto failed; |
| 2561 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2562 | break; |
| 2563 | case Import_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2564 | result = PyType_GenericNew(Import_type, NULL, NULL); |
| 2565 | if (!result) goto failed; |
| 2566 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 2567 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2568 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2569 | goto failed; |
| 2570 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2571 | break; |
| 2572 | case ImportFrom_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2573 | result = PyType_GenericNew(ImportFrom_type, NULL, NULL); |
| 2574 | if (!result) goto failed; |
| 2575 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 2576 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2577 | if (_PyObject_SetAttrId(result, &PyId_module, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2578 | goto failed; |
| 2579 | Py_DECREF(value); |
| 2580 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 2581 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2582 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2583 | goto failed; |
| 2584 | Py_DECREF(value); |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 2585 | value = ast2obj_int(o->v.ImportFrom.level); |
| 2586 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2587 | if (_PyObject_SetAttrId(result, &PyId_level, value) == -1) |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 2588 | goto failed; |
| 2589 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2590 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2591 | case Global_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2592 | result = PyType_GenericNew(Global_type, NULL, NULL); |
| 2593 | if (!result) goto failed; |
| 2594 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 2595 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2596 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2597 | goto failed; |
| 2598 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2599 | break; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2600 | case Nonlocal_kind: |
| 2601 | result = PyType_GenericNew(Nonlocal_type, NULL, NULL); |
| 2602 | if (!result) goto failed; |
| 2603 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 2604 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2605 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2606 | goto failed; |
| 2607 | Py_DECREF(value); |
| 2608 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2609 | case Expr_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2610 | result = PyType_GenericNew(Expr_type, NULL, NULL); |
| 2611 | if (!result) goto failed; |
| 2612 | value = ast2obj_expr(o->v.Expr.value); |
| 2613 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2614 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2615 | goto failed; |
| 2616 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2617 | break; |
| 2618 | case Pass_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2619 | result = PyType_GenericNew(Pass_type, NULL, NULL); |
| 2620 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2621 | break; |
| 2622 | case Break_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2623 | result = PyType_GenericNew(Break_type, NULL, NULL); |
| 2624 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2625 | break; |
| 2626 | case Continue_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2627 | result = PyType_GenericNew(Continue_type, NULL, NULL); |
| 2628 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2629 | break; |
| 2630 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2631 | value = ast2obj_int(o->lineno); |
| 2632 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2633 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2634 | goto failed; |
| 2635 | Py_DECREF(value); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2636 | value = ast2obj_int(o->col_offset); |
| 2637 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2638 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2639 | goto failed; |
| 2640 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2641 | return result; |
| 2642 | failed: |
| 2643 | Py_XDECREF(value); |
| 2644 | Py_XDECREF(result); |
| 2645 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2646 | } |
| 2647 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2648 | PyObject* |
| 2649 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2650 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2651 | expr_ty o = (expr_ty)_o; |
| 2652 | PyObject *result = NULL, *value = NULL; |
| 2653 | if (!o) { |
| 2654 | Py_INCREF(Py_None); |
| 2655 | return Py_None; |
| 2656 | } |
| 2657 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2658 | switch (o->kind) { |
| 2659 | case BoolOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2660 | result = PyType_GenericNew(BoolOp_type, NULL, NULL); |
| 2661 | if (!result) goto failed; |
| 2662 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 2663 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2664 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2665 | goto failed; |
| 2666 | Py_DECREF(value); |
| 2667 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 2668 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2669 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2670 | goto failed; |
| 2671 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2672 | break; |
| 2673 | case BinOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2674 | result = PyType_GenericNew(BinOp_type, NULL, NULL); |
| 2675 | if (!result) goto failed; |
| 2676 | value = ast2obj_expr(o->v.BinOp.left); |
| 2677 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2678 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2679 | goto failed; |
| 2680 | Py_DECREF(value); |
| 2681 | value = ast2obj_operator(o->v.BinOp.op); |
| 2682 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2683 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2684 | goto failed; |
| 2685 | Py_DECREF(value); |
| 2686 | value = ast2obj_expr(o->v.BinOp.right); |
| 2687 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2688 | if (_PyObject_SetAttrId(result, &PyId_right, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2689 | goto failed; |
| 2690 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2691 | break; |
| 2692 | case UnaryOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2693 | result = PyType_GenericNew(UnaryOp_type, NULL, NULL); |
| 2694 | if (!result) goto failed; |
| 2695 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 2696 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2697 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2698 | goto failed; |
| 2699 | Py_DECREF(value); |
| 2700 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 2701 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2702 | if (_PyObject_SetAttrId(result, &PyId_operand, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2703 | goto failed; |
| 2704 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2705 | break; |
| 2706 | case Lambda_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2707 | result = PyType_GenericNew(Lambda_type, NULL, NULL); |
| 2708 | if (!result) goto failed; |
| 2709 | value = ast2obj_arguments(o->v.Lambda.args); |
| 2710 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2711 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2712 | goto failed; |
| 2713 | Py_DECREF(value); |
| 2714 | value = ast2obj_expr(o->v.Lambda.body); |
| 2715 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2716 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2717 | goto failed; |
| 2718 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2719 | break; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2720 | case IfExp_kind: |
| 2721 | result = PyType_GenericNew(IfExp_type, NULL, NULL); |
| 2722 | if (!result) goto failed; |
| 2723 | value = ast2obj_expr(o->v.IfExp.test); |
| 2724 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2725 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2726 | goto failed; |
| 2727 | Py_DECREF(value); |
| 2728 | value = ast2obj_expr(o->v.IfExp.body); |
| 2729 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2730 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2731 | goto failed; |
| 2732 | Py_DECREF(value); |
| 2733 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 2734 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2735 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2736 | goto failed; |
| 2737 | Py_DECREF(value); |
| 2738 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2739 | case Dict_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2740 | result = PyType_GenericNew(Dict_type, NULL, NULL); |
| 2741 | if (!result) goto failed; |
| 2742 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 2743 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2744 | if (_PyObject_SetAttrId(result, &PyId_keys, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2745 | goto failed; |
| 2746 | Py_DECREF(value); |
| 2747 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 2748 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2749 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2750 | goto failed; |
| 2751 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2752 | break; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2753 | case Set_kind: |
| 2754 | result = PyType_GenericNew(Set_type, NULL, NULL); |
| 2755 | if (!result) goto failed; |
| 2756 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 2757 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2758 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2759 | goto failed; |
| 2760 | Py_DECREF(value); |
| 2761 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2762 | case ListComp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2763 | result = PyType_GenericNew(ListComp_type, NULL, NULL); |
| 2764 | if (!result) goto failed; |
| 2765 | value = ast2obj_expr(o->v.ListComp.elt); |
| 2766 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2767 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2768 | goto failed; |
| 2769 | Py_DECREF(value); |
| 2770 | value = ast2obj_list(o->v.ListComp.generators, |
| 2771 | ast2obj_comprehension); |
| 2772 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2773 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2774 | goto failed; |
| 2775 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2776 | break; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2777 | case SetComp_kind: |
| 2778 | result = PyType_GenericNew(SetComp_type, NULL, NULL); |
| 2779 | if (!result) goto failed; |
| 2780 | value = ast2obj_expr(o->v.SetComp.elt); |
| 2781 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2782 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2783 | goto failed; |
| 2784 | Py_DECREF(value); |
| 2785 | value = ast2obj_list(o->v.SetComp.generators, |
| 2786 | ast2obj_comprehension); |
| 2787 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2788 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2789 | goto failed; |
| 2790 | Py_DECREF(value); |
| 2791 | break; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2792 | case DictComp_kind: |
| 2793 | result = PyType_GenericNew(DictComp_type, NULL, NULL); |
| 2794 | if (!result) goto failed; |
| 2795 | value = ast2obj_expr(o->v.DictComp.key); |
| 2796 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2797 | if (_PyObject_SetAttrId(result, &PyId_key, value) == -1) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2798 | goto failed; |
| 2799 | Py_DECREF(value); |
| 2800 | value = ast2obj_expr(o->v.DictComp.value); |
| 2801 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2802 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2803 | goto failed; |
| 2804 | Py_DECREF(value); |
| 2805 | value = ast2obj_list(o->v.DictComp.generators, |
| 2806 | ast2obj_comprehension); |
| 2807 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2808 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2809 | goto failed; |
| 2810 | Py_DECREF(value); |
| 2811 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2812 | case GeneratorExp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2813 | result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); |
| 2814 | if (!result) goto failed; |
| 2815 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 2816 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2817 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2818 | goto failed; |
| 2819 | Py_DECREF(value); |
| 2820 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 2821 | ast2obj_comprehension); |
| 2822 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2823 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2824 | goto failed; |
| 2825 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2826 | break; |
| 2827 | case Yield_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2828 | result = PyType_GenericNew(Yield_type, NULL, NULL); |
| 2829 | if (!result) goto failed; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2830 | value = ast2obj_expr(o->v.Yield.value); |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 2831 | if (!value) goto failed; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2832 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 2833 | goto failed; |
| 2834 | Py_DECREF(value); |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2835 | break; |
| 2836 | case YieldFrom_kind: |
| 2837 | result = PyType_GenericNew(YieldFrom_type, NULL, NULL); |
| 2838 | if (!result) goto failed; |
| 2839 | value = ast2obj_expr(o->v.YieldFrom.value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2840 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2841 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2842 | goto failed; |
| 2843 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2844 | break; |
| 2845 | case Compare_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2846 | result = PyType_GenericNew(Compare_type, NULL, NULL); |
| 2847 | if (!result) goto failed; |
| 2848 | value = ast2obj_expr(o->v.Compare.left); |
| 2849 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2850 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2851 | goto failed; |
| 2852 | Py_DECREF(value); |
Martin v. Löwis | ce1d5d2 | 2006-02-26 20:51:25 +0000 | [diff] [blame] | 2853 | { |
| 2854 | int i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 2855 | value = PyList_New(n); |
| 2856 | if (!value) goto failed; |
| 2857 | for(i = 0; i < n; i++) |
| 2858 | PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i))); |
| 2859 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2860 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2861 | if (_PyObject_SetAttrId(result, &PyId_ops, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2862 | goto failed; |
| 2863 | Py_DECREF(value); |
| 2864 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
| 2865 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2866 | if (_PyObject_SetAttrId(result, &PyId_comparators, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2867 | goto failed; |
| 2868 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2869 | break; |
| 2870 | case Call_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2871 | result = PyType_GenericNew(Call_type, NULL, NULL); |
| 2872 | if (!result) goto failed; |
| 2873 | value = ast2obj_expr(o->v.Call.func); |
| 2874 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2875 | if (_PyObject_SetAttrId(result, &PyId_func, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2876 | goto failed; |
| 2877 | Py_DECREF(value); |
| 2878 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 2879 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2880 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2881 | goto failed; |
| 2882 | Py_DECREF(value); |
| 2883 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 2884 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2885 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2886 | goto failed; |
| 2887 | Py_DECREF(value); |
| 2888 | value = ast2obj_expr(o->v.Call.starargs); |
| 2889 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2890 | if (_PyObject_SetAttrId(result, &PyId_starargs, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2891 | goto failed; |
| 2892 | Py_DECREF(value); |
| 2893 | value = ast2obj_expr(o->v.Call.kwargs); |
| 2894 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2895 | if (_PyObject_SetAttrId(result, &PyId_kwargs, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2896 | goto failed; |
| 2897 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2898 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2899 | case Num_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2900 | result = PyType_GenericNew(Num_type, NULL, NULL); |
| 2901 | if (!result) goto failed; |
| 2902 | value = ast2obj_object(o->v.Num.n); |
| 2903 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2904 | if (_PyObject_SetAttrId(result, &PyId_n, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2905 | goto failed; |
| 2906 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2907 | break; |
| 2908 | case Str_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2909 | result = PyType_GenericNew(Str_type, NULL, NULL); |
| 2910 | if (!result) goto failed; |
| 2911 | value = ast2obj_string(o->v.Str.s); |
| 2912 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2913 | if (_PyObject_SetAttrId(result, &PyId_s, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2914 | goto failed; |
| 2915 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2916 | break; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 2917 | case Bytes_kind: |
| 2918 | result = PyType_GenericNew(Bytes_type, NULL, NULL); |
| 2919 | if (!result) goto failed; |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 2920 | value = ast2obj_bytes(o->v.Bytes.s); |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 2921 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2922 | if (_PyObject_SetAttrId(result, &PyId_s, value) == -1) |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 2923 | goto failed; |
| 2924 | Py_DECREF(value); |
| 2925 | break; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 2926 | case Ellipsis_kind: |
| 2927 | result = PyType_GenericNew(Ellipsis_type, NULL, NULL); |
| 2928 | if (!result) goto failed; |
| 2929 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2930 | case Attribute_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2931 | result = PyType_GenericNew(Attribute_type, NULL, NULL); |
| 2932 | if (!result) goto failed; |
| 2933 | value = ast2obj_expr(o->v.Attribute.value); |
| 2934 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2935 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2936 | goto failed; |
| 2937 | Py_DECREF(value); |
| 2938 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 2939 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2940 | if (_PyObject_SetAttrId(result, &PyId_attr, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2941 | goto failed; |
| 2942 | Py_DECREF(value); |
| 2943 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 2944 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2945 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2946 | goto failed; |
| 2947 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2948 | break; |
| 2949 | case Subscript_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2950 | result = PyType_GenericNew(Subscript_type, NULL, NULL); |
| 2951 | if (!result) goto failed; |
| 2952 | value = ast2obj_expr(o->v.Subscript.value); |
| 2953 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2954 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2955 | goto failed; |
| 2956 | Py_DECREF(value); |
| 2957 | value = ast2obj_slice(o->v.Subscript.slice); |
| 2958 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2959 | if (_PyObject_SetAttrId(result, &PyId_slice, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2960 | goto failed; |
| 2961 | Py_DECREF(value); |
| 2962 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 2963 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2964 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2965 | goto failed; |
| 2966 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2967 | break; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2968 | case Starred_kind: |
| 2969 | result = PyType_GenericNew(Starred_type, NULL, NULL); |
| 2970 | if (!result) goto failed; |
| 2971 | value = ast2obj_expr(o->v.Starred.value); |
| 2972 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2973 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2974 | goto failed; |
| 2975 | Py_DECREF(value); |
| 2976 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 2977 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2978 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2979 | goto failed; |
| 2980 | Py_DECREF(value); |
| 2981 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2982 | case Name_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2983 | result = PyType_GenericNew(Name_type, NULL, NULL); |
| 2984 | if (!result) goto failed; |
| 2985 | value = ast2obj_identifier(o->v.Name.id); |
| 2986 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2987 | if (_PyObject_SetAttrId(result, &PyId_id, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2988 | goto failed; |
| 2989 | Py_DECREF(value); |
| 2990 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 2991 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2992 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2993 | goto failed; |
| 2994 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2995 | break; |
| 2996 | case List_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2997 | result = PyType_GenericNew(List_type, NULL, NULL); |
| 2998 | if (!result) goto failed; |
| 2999 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 3000 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3001 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3002 | goto failed; |
| 3003 | Py_DECREF(value); |
| 3004 | value = ast2obj_expr_context(o->v.List.ctx); |
| 3005 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3006 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3007 | goto failed; |
| 3008 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3009 | break; |
| 3010 | case Tuple_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3011 | result = PyType_GenericNew(Tuple_type, NULL, NULL); |
| 3012 | if (!result) goto failed; |
| 3013 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 3014 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3015 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3016 | goto failed; |
| 3017 | Py_DECREF(value); |
| 3018 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 3019 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3020 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3021 | goto failed; |
| 3022 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3023 | break; |
| 3024 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 3025 | value = ast2obj_int(o->lineno); |
| 3026 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3027 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3028 | goto failed; |
| 3029 | Py_DECREF(value); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3030 | value = ast2obj_int(o->col_offset); |
| 3031 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3032 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3033 | goto failed; |
| 3034 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3035 | return result; |
| 3036 | failed: |
| 3037 | Py_XDECREF(value); |
| 3038 | Py_XDECREF(result); |
| 3039 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3040 | } |
| 3041 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3042 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3043 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3044 | switch(o) { |
| 3045 | case Load: |
| 3046 | Py_INCREF(Load_singleton); |
| 3047 | return Load_singleton; |
| 3048 | case Store: |
| 3049 | Py_INCREF(Store_singleton); |
| 3050 | return Store_singleton; |
| 3051 | case Del: |
| 3052 | Py_INCREF(Del_singleton); |
| 3053 | return Del_singleton; |
| 3054 | case AugLoad: |
| 3055 | Py_INCREF(AugLoad_singleton); |
| 3056 | return AugLoad_singleton; |
| 3057 | case AugStore: |
| 3058 | Py_INCREF(AugStore_singleton); |
| 3059 | return AugStore_singleton; |
| 3060 | case Param: |
| 3061 | Py_INCREF(Param_singleton); |
| 3062 | return Param_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3063 | default: |
| 3064 | /* should never happen, but just in case ... */ |
| 3065 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 3066 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3067 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3068 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3069 | PyObject* |
| 3070 | ast2obj_slice(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3071 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3072 | slice_ty o = (slice_ty)_o; |
| 3073 | PyObject *result = NULL, *value = NULL; |
| 3074 | if (!o) { |
| 3075 | Py_INCREF(Py_None); |
| 3076 | return Py_None; |
| 3077 | } |
| 3078 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3079 | switch (o->kind) { |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3080 | case Slice_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3081 | result = PyType_GenericNew(Slice_type, NULL, NULL); |
| 3082 | if (!result) goto failed; |
| 3083 | value = ast2obj_expr(o->v.Slice.lower); |
| 3084 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3085 | if (_PyObject_SetAttrId(result, &PyId_lower, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3086 | goto failed; |
| 3087 | Py_DECREF(value); |
| 3088 | value = ast2obj_expr(o->v.Slice.upper); |
| 3089 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3090 | if (_PyObject_SetAttrId(result, &PyId_upper, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3091 | goto failed; |
| 3092 | Py_DECREF(value); |
| 3093 | value = ast2obj_expr(o->v.Slice.step); |
| 3094 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3095 | if (_PyObject_SetAttrId(result, &PyId_step, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3096 | goto failed; |
| 3097 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3098 | break; |
| 3099 | case ExtSlice_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3100 | result = PyType_GenericNew(ExtSlice_type, NULL, NULL); |
| 3101 | if (!result) goto failed; |
| 3102 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 3103 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3104 | if (_PyObject_SetAttrId(result, &PyId_dims, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3105 | goto failed; |
| 3106 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3107 | break; |
| 3108 | case Index_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3109 | result = PyType_GenericNew(Index_type, NULL, NULL); |
| 3110 | if (!result) goto failed; |
| 3111 | value = ast2obj_expr(o->v.Index.value); |
| 3112 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3113 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3114 | goto failed; |
| 3115 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3116 | break; |
| 3117 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3118 | return result; |
| 3119 | failed: |
| 3120 | Py_XDECREF(value); |
| 3121 | Py_XDECREF(result); |
| 3122 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3123 | } |
| 3124 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3125 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3126 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3127 | switch(o) { |
| 3128 | case And: |
| 3129 | Py_INCREF(And_singleton); |
| 3130 | return And_singleton; |
| 3131 | case Or: |
| 3132 | Py_INCREF(Or_singleton); |
| 3133 | return Or_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3134 | default: |
| 3135 | /* should never happen, but just in case ... */ |
| 3136 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 3137 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3138 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3139 | } |
| 3140 | PyObject* ast2obj_operator(operator_ty o) |
| 3141 | { |
| 3142 | switch(o) { |
| 3143 | case Add: |
| 3144 | Py_INCREF(Add_singleton); |
| 3145 | return Add_singleton; |
| 3146 | case Sub: |
| 3147 | Py_INCREF(Sub_singleton); |
| 3148 | return Sub_singleton; |
| 3149 | case Mult: |
| 3150 | Py_INCREF(Mult_singleton); |
| 3151 | return Mult_singleton; |
| 3152 | case Div: |
| 3153 | Py_INCREF(Div_singleton); |
| 3154 | return Div_singleton; |
| 3155 | case Mod: |
| 3156 | Py_INCREF(Mod_singleton); |
| 3157 | return Mod_singleton; |
| 3158 | case Pow: |
| 3159 | Py_INCREF(Pow_singleton); |
| 3160 | return Pow_singleton; |
| 3161 | case LShift: |
| 3162 | Py_INCREF(LShift_singleton); |
| 3163 | return LShift_singleton; |
| 3164 | case RShift: |
| 3165 | Py_INCREF(RShift_singleton); |
| 3166 | return RShift_singleton; |
| 3167 | case BitOr: |
| 3168 | Py_INCREF(BitOr_singleton); |
| 3169 | return BitOr_singleton; |
| 3170 | case BitXor: |
| 3171 | Py_INCREF(BitXor_singleton); |
| 3172 | return BitXor_singleton; |
| 3173 | case BitAnd: |
| 3174 | Py_INCREF(BitAnd_singleton); |
| 3175 | return BitAnd_singleton; |
| 3176 | case FloorDiv: |
| 3177 | Py_INCREF(FloorDiv_singleton); |
| 3178 | return FloorDiv_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3179 | default: |
| 3180 | /* should never happen, but just in case ... */ |
| 3181 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 3182 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3183 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3184 | } |
| 3185 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 3186 | { |
| 3187 | switch(o) { |
| 3188 | case Invert: |
| 3189 | Py_INCREF(Invert_singleton); |
| 3190 | return Invert_singleton; |
| 3191 | case Not: |
| 3192 | Py_INCREF(Not_singleton); |
| 3193 | return Not_singleton; |
| 3194 | case UAdd: |
| 3195 | Py_INCREF(UAdd_singleton); |
| 3196 | return UAdd_singleton; |
| 3197 | case USub: |
| 3198 | Py_INCREF(USub_singleton); |
| 3199 | return USub_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3200 | default: |
| 3201 | /* should never happen, but just in case ... */ |
| 3202 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 3203 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3204 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3205 | } |
| 3206 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 3207 | { |
| 3208 | switch(o) { |
| 3209 | case Eq: |
| 3210 | Py_INCREF(Eq_singleton); |
| 3211 | return Eq_singleton; |
| 3212 | case NotEq: |
| 3213 | Py_INCREF(NotEq_singleton); |
| 3214 | return NotEq_singleton; |
| 3215 | case Lt: |
| 3216 | Py_INCREF(Lt_singleton); |
| 3217 | return Lt_singleton; |
| 3218 | case LtE: |
| 3219 | Py_INCREF(LtE_singleton); |
| 3220 | return LtE_singleton; |
| 3221 | case Gt: |
| 3222 | Py_INCREF(Gt_singleton); |
| 3223 | return Gt_singleton; |
| 3224 | case GtE: |
| 3225 | Py_INCREF(GtE_singleton); |
| 3226 | return GtE_singleton; |
| 3227 | case Is: |
| 3228 | Py_INCREF(Is_singleton); |
| 3229 | return Is_singleton; |
| 3230 | case IsNot: |
| 3231 | Py_INCREF(IsNot_singleton); |
| 3232 | return IsNot_singleton; |
| 3233 | case In: |
| 3234 | Py_INCREF(In_singleton); |
| 3235 | return In_singleton; |
| 3236 | case NotIn: |
| 3237 | Py_INCREF(NotIn_singleton); |
| 3238 | return NotIn_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3239 | default: |
| 3240 | /* should never happen, but just in case ... */ |
| 3241 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 3242 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3243 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3244 | } |
| 3245 | PyObject* |
| 3246 | ast2obj_comprehension(void* _o) |
| 3247 | { |
| 3248 | comprehension_ty o = (comprehension_ty)_o; |
| 3249 | PyObject *result = NULL, *value = NULL; |
| 3250 | if (!o) { |
| 3251 | Py_INCREF(Py_None); |
| 3252 | return Py_None; |
| 3253 | } |
| 3254 | |
| 3255 | result = PyType_GenericNew(comprehension_type, NULL, NULL); |
| 3256 | if (!result) return NULL; |
| 3257 | value = ast2obj_expr(o->target); |
| 3258 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3259 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3260 | goto failed; |
| 3261 | Py_DECREF(value); |
| 3262 | value = ast2obj_expr(o->iter); |
| 3263 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3264 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3265 | goto failed; |
| 3266 | Py_DECREF(value); |
| 3267 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 3268 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3269 | if (_PyObject_SetAttrId(result, &PyId_ifs, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3270 | goto failed; |
| 3271 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3272 | return result; |
| 3273 | failed: |
| 3274 | Py_XDECREF(value); |
| 3275 | Py_XDECREF(result); |
| 3276 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3277 | } |
| 3278 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3279 | PyObject* |
| 3280 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3281 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3282 | excepthandler_ty o = (excepthandler_ty)_o; |
| 3283 | PyObject *result = NULL, *value = NULL; |
| 3284 | if (!o) { |
| 3285 | Py_INCREF(Py_None); |
| 3286 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3287 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3288 | |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3289 | switch (o->kind) { |
| 3290 | case ExceptHandler_kind: |
| 3291 | result = PyType_GenericNew(ExceptHandler_type, NULL, NULL); |
| 3292 | if (!result) goto failed; |
| 3293 | value = ast2obj_expr(o->v.ExceptHandler.type); |
| 3294 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3295 | if (_PyObject_SetAttrId(result, &PyId_type, value) == -1) |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3296 | goto failed; |
| 3297 | Py_DECREF(value); |
| 3298 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
| 3299 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3300 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3301 | goto failed; |
| 3302 | Py_DECREF(value); |
| 3303 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 3304 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3305 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3306 | goto failed; |
| 3307 | Py_DECREF(value); |
| 3308 | break; |
| 3309 | } |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3310 | value = ast2obj_int(o->lineno); |
| 3311 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3312 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3313 | goto failed; |
| 3314 | Py_DECREF(value); |
| 3315 | value = ast2obj_int(o->col_offset); |
| 3316 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3317 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3318 | goto failed; |
| 3319 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3320 | return result; |
| 3321 | failed: |
| 3322 | Py_XDECREF(value); |
| 3323 | Py_XDECREF(result); |
| 3324 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3325 | } |
| 3326 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3327 | PyObject* |
| 3328 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3329 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3330 | arguments_ty o = (arguments_ty)_o; |
| 3331 | PyObject *result = NULL, *value = NULL; |
| 3332 | if (!o) { |
| 3333 | Py_INCREF(Py_None); |
| 3334 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3335 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3336 | |
| 3337 | result = PyType_GenericNew(arguments_type, NULL, NULL); |
| 3338 | if (!result) return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3339 | value = ast2obj_list(o->args, ast2obj_arg); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3340 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3341 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3342 | goto failed; |
| 3343 | Py_DECREF(value); |
| 3344 | value = ast2obj_identifier(o->vararg); |
| 3345 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3346 | if (_PyObject_SetAttrId(result, &PyId_vararg, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3347 | goto failed; |
| 3348 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3349 | value = ast2obj_expr(o->varargannotation); |
| 3350 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3351 | if (_PyObject_SetAttrId(result, &PyId_varargannotation, value) == -1) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3352 | goto failed; |
| 3353 | Py_DECREF(value); |
| 3354 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 3355 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3356 | if (_PyObject_SetAttrId(result, &PyId_kwonlyargs, value) == -1) |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 3357 | goto failed; |
| 3358 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3359 | value = ast2obj_identifier(o->kwarg); |
| 3360 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3361 | if (_PyObject_SetAttrId(result, &PyId_kwarg, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3362 | goto failed; |
| 3363 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3364 | value = ast2obj_expr(o->kwargannotation); |
| 3365 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3366 | if (_PyObject_SetAttrId(result, &PyId_kwargannotation, value) == -1) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3367 | goto failed; |
| 3368 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3369 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 3370 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3371 | if (_PyObject_SetAttrId(result, &PyId_defaults, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3372 | goto failed; |
| 3373 | Py_DECREF(value); |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 3374 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
| 3375 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3376 | if (_PyObject_SetAttrId(result, &PyId_kw_defaults, value) == -1) |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 3377 | goto failed; |
| 3378 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3379 | return result; |
| 3380 | failed: |
| 3381 | Py_XDECREF(value); |
| 3382 | Py_XDECREF(result); |
| 3383 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3384 | } |
| 3385 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3386 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3387 | ast2obj_arg(void* _o) |
| 3388 | { |
| 3389 | arg_ty o = (arg_ty)_o; |
| 3390 | PyObject *result = NULL, *value = NULL; |
| 3391 | if (!o) { |
| 3392 | Py_INCREF(Py_None); |
| 3393 | return Py_None; |
| 3394 | } |
| 3395 | |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 3396 | result = PyType_GenericNew(arg_type, NULL, NULL); |
| 3397 | if (!result) return NULL; |
| 3398 | value = ast2obj_identifier(o->arg); |
| 3399 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3400 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 3401 | goto failed; |
| 3402 | Py_DECREF(value); |
| 3403 | value = ast2obj_expr(o->annotation); |
| 3404 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3405 | if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 3406 | goto failed; |
| 3407 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3408 | return result; |
| 3409 | failed: |
| 3410 | Py_XDECREF(value); |
| 3411 | Py_XDECREF(result); |
| 3412 | return NULL; |
| 3413 | } |
| 3414 | |
| 3415 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3416 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3417 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3418 | keyword_ty o = (keyword_ty)_o; |
| 3419 | PyObject *result = NULL, *value = NULL; |
| 3420 | if (!o) { |
| 3421 | Py_INCREF(Py_None); |
| 3422 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3423 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3424 | |
| 3425 | result = PyType_GenericNew(keyword_type, NULL, NULL); |
| 3426 | if (!result) return NULL; |
| 3427 | value = ast2obj_identifier(o->arg); |
| 3428 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3429 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3430 | goto failed; |
| 3431 | Py_DECREF(value); |
| 3432 | value = ast2obj_expr(o->value); |
| 3433 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3434 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3435 | goto failed; |
| 3436 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3437 | return result; |
| 3438 | failed: |
| 3439 | Py_XDECREF(value); |
| 3440 | Py_XDECREF(result); |
| 3441 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3442 | } |
| 3443 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3444 | PyObject* |
| 3445 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3446 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3447 | alias_ty o = (alias_ty)_o; |
| 3448 | PyObject *result = NULL, *value = NULL; |
| 3449 | if (!o) { |
| 3450 | Py_INCREF(Py_None); |
| 3451 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3452 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3453 | |
| 3454 | result = PyType_GenericNew(alias_type, NULL, NULL); |
| 3455 | if (!result) return NULL; |
| 3456 | value = ast2obj_identifier(o->name); |
| 3457 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3458 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3459 | goto failed; |
| 3460 | Py_DECREF(value); |
| 3461 | value = ast2obj_identifier(o->asname); |
| 3462 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3463 | if (_PyObject_SetAttrId(result, &PyId_asname, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3464 | goto failed; |
| 3465 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3466 | return result; |
| 3467 | failed: |
| 3468 | Py_XDECREF(value); |
| 3469 | Py_XDECREF(result); |
| 3470 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3471 | } |
| 3472 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3473 | PyObject* |
| 3474 | ast2obj_withitem(void* _o) |
| 3475 | { |
| 3476 | withitem_ty o = (withitem_ty)_o; |
| 3477 | PyObject *result = NULL, *value = NULL; |
| 3478 | if (!o) { |
| 3479 | Py_INCREF(Py_None); |
| 3480 | return Py_None; |
| 3481 | } |
| 3482 | |
| 3483 | result = PyType_GenericNew(withitem_type, NULL, NULL); |
| 3484 | if (!result) return NULL; |
| 3485 | value = ast2obj_expr(o->context_expr); |
| 3486 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3487 | if (_PyObject_SetAttrId(result, &PyId_context_expr, value) == -1) |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3488 | goto failed; |
| 3489 | Py_DECREF(value); |
| 3490 | value = ast2obj_expr(o->optional_vars); |
| 3491 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3492 | if (_PyObject_SetAttrId(result, &PyId_optional_vars, value) == -1) |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3493 | goto failed; |
| 3494 | Py_DECREF(value); |
| 3495 | return result; |
| 3496 | failed: |
| 3497 | Py_XDECREF(value); |
| 3498 | Py_XDECREF(result); |
| 3499 | return NULL; |
| 3500 | } |
| 3501 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3502 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3503 | int |
| 3504 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 3505 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3506 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3507 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 3508 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3509 | |
| 3510 | if (obj == Py_None) { |
| 3511 | *out = NULL; |
| 3512 | return 0; |
| 3513 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3514 | isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type); |
| 3515 | if (isinstance == -1) { |
| 3516 | return 1; |
| 3517 | } |
| 3518 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3519 | asdl_seq* body; |
| 3520 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3521 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3522 | int res; |
| 3523 | Py_ssize_t len; |
| 3524 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3525 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3526 | if (tmp == NULL) goto failed; |
| 3527 | if (!PyList_Check(tmp)) { |
| 3528 | PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3529 | goto failed; |
| 3530 | } |
| 3531 | len = PyList_GET_SIZE(tmp); |
| 3532 | body = asdl_seq_new(len, arena); |
| 3533 | if (body == NULL) goto failed; |
| 3534 | for (i = 0; i < len; i++) { |
| 3535 | stmt_ty value; |
| 3536 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3537 | if (res != 0) goto failed; |
| 3538 | asdl_seq_SET(body, i, value); |
| 3539 | } |
| 3540 | Py_XDECREF(tmp); |
| 3541 | tmp = NULL; |
| 3542 | } else { |
| 3543 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 3544 | return 1; |
| 3545 | } |
| 3546 | *out = Module(body, arena); |
| 3547 | if (*out == NULL) goto failed; |
| 3548 | return 0; |
| 3549 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3550 | isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type); |
| 3551 | if (isinstance == -1) { |
| 3552 | return 1; |
| 3553 | } |
| 3554 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3555 | asdl_seq* body; |
| 3556 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3557 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3558 | int res; |
| 3559 | Py_ssize_t len; |
| 3560 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3561 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3562 | if (tmp == NULL) goto failed; |
| 3563 | if (!PyList_Check(tmp)) { |
| 3564 | PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3565 | goto failed; |
| 3566 | } |
| 3567 | len = PyList_GET_SIZE(tmp); |
| 3568 | body = asdl_seq_new(len, arena); |
| 3569 | if (body == NULL) goto failed; |
| 3570 | for (i = 0; i < len; i++) { |
| 3571 | stmt_ty value; |
| 3572 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3573 | if (res != 0) goto failed; |
| 3574 | asdl_seq_SET(body, i, value); |
| 3575 | } |
| 3576 | Py_XDECREF(tmp); |
| 3577 | tmp = NULL; |
| 3578 | } else { |
| 3579 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 3580 | return 1; |
| 3581 | } |
| 3582 | *out = Interactive(body, arena); |
| 3583 | if (*out == NULL) goto failed; |
| 3584 | return 0; |
| 3585 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3586 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type); |
| 3587 | if (isinstance == -1) { |
| 3588 | return 1; |
| 3589 | } |
| 3590 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3591 | expr_ty body; |
| 3592 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3593 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3594 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3595 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3596 | if (tmp == NULL) goto failed; |
| 3597 | res = obj2ast_expr(tmp, &body, arena); |
| 3598 | if (res != 0) goto failed; |
| 3599 | Py_XDECREF(tmp); |
| 3600 | tmp = NULL; |
| 3601 | } else { |
| 3602 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 3603 | return 1; |
| 3604 | } |
| 3605 | *out = Expression(body, arena); |
| 3606 | if (*out == NULL) goto failed; |
| 3607 | return 0; |
| 3608 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3609 | isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type); |
| 3610 | if (isinstance == -1) { |
| 3611 | return 1; |
| 3612 | } |
| 3613 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3614 | asdl_seq* body; |
| 3615 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3616 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3617 | int res; |
| 3618 | Py_ssize_t len; |
| 3619 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3620 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3621 | if (tmp == NULL) goto failed; |
| 3622 | if (!PyList_Check(tmp)) { |
| 3623 | PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3624 | goto failed; |
| 3625 | } |
| 3626 | len = PyList_GET_SIZE(tmp); |
| 3627 | body = asdl_seq_new(len, arena); |
| 3628 | if (body == NULL) goto failed; |
| 3629 | for (i = 0; i < len; i++) { |
| 3630 | stmt_ty value; |
| 3631 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3632 | if (res != 0) goto failed; |
| 3633 | asdl_seq_SET(body, i, value); |
| 3634 | } |
| 3635 | Py_XDECREF(tmp); |
| 3636 | tmp = NULL; |
| 3637 | } else { |
| 3638 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite"); |
| 3639 | return 1; |
| 3640 | } |
| 3641 | *out = Suite(body, arena); |
| 3642 | if (*out == NULL) goto failed; |
| 3643 | return 0; |
| 3644 | } |
| 3645 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 3646 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
| 3647 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 3648 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3649 | return 1; |
| 3650 | } |
| 3651 | |
| 3652 | int |
| 3653 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 3654 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3655 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3656 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 3657 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3658 | int lineno; |
| 3659 | int col_offset; |
| 3660 | |
| 3661 | if (obj == Py_None) { |
| 3662 | *out = NULL; |
| 3663 | return 0; |
| 3664 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3665 | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3666 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3667 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3668 | if (tmp == NULL) goto failed; |
| 3669 | res = obj2ast_int(tmp, &lineno, arena); |
| 3670 | if (res != 0) goto failed; |
| 3671 | Py_XDECREF(tmp); |
| 3672 | tmp = NULL; |
| 3673 | } else { |
| 3674 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 3675 | return 1; |
| 3676 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3677 | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3678 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3679 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3680 | if (tmp == NULL) goto failed; |
| 3681 | res = obj2ast_int(tmp, &col_offset, arena); |
| 3682 | if (res != 0) goto failed; |
| 3683 | Py_XDECREF(tmp); |
| 3684 | tmp = NULL; |
| 3685 | } else { |
| 3686 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 3687 | return 1; |
| 3688 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3689 | isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type); |
| 3690 | if (isinstance == -1) { |
| 3691 | return 1; |
| 3692 | } |
| 3693 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3694 | identifier name; |
| 3695 | arguments_ty args; |
| 3696 | asdl_seq* body; |
| 3697 | asdl_seq* decorator_list; |
| 3698 | expr_ty returns; |
| 3699 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3700 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3701 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3702 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3703 | if (tmp == NULL) goto failed; |
| 3704 | res = obj2ast_identifier(tmp, &name, arena); |
| 3705 | if (res != 0) goto failed; |
| 3706 | Py_XDECREF(tmp); |
| 3707 | tmp = NULL; |
| 3708 | } else { |
| 3709 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 3710 | return 1; |
| 3711 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3712 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3713 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3714 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3715 | if (tmp == NULL) goto failed; |
| 3716 | res = obj2ast_arguments(tmp, &args, arena); |
| 3717 | if (res != 0) goto failed; |
| 3718 | Py_XDECREF(tmp); |
| 3719 | tmp = NULL; |
| 3720 | } else { |
| 3721 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 3722 | return 1; |
| 3723 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3724 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3725 | int res; |
| 3726 | Py_ssize_t len; |
| 3727 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3728 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3729 | if (tmp == NULL) goto failed; |
| 3730 | if (!PyList_Check(tmp)) { |
| 3731 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3732 | goto failed; |
| 3733 | } |
| 3734 | len = PyList_GET_SIZE(tmp); |
| 3735 | body = asdl_seq_new(len, arena); |
| 3736 | if (body == NULL) goto failed; |
| 3737 | for (i = 0; i < len; i++) { |
| 3738 | stmt_ty value; |
| 3739 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3740 | if (res != 0) goto failed; |
| 3741 | asdl_seq_SET(body, i, value); |
| 3742 | } |
| 3743 | Py_XDECREF(tmp); |
| 3744 | tmp = NULL; |
| 3745 | } else { |
| 3746 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 3747 | return 1; |
| 3748 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3749 | if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3750 | int res; |
| 3751 | Py_ssize_t len; |
| 3752 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3753 | tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3754 | if (tmp == NULL) goto failed; |
| 3755 | if (!PyList_Check(tmp)) { |
| 3756 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3757 | goto failed; |
| 3758 | } |
| 3759 | len = PyList_GET_SIZE(tmp); |
| 3760 | decorator_list = asdl_seq_new(len, arena); |
| 3761 | if (decorator_list == NULL) goto failed; |
| 3762 | for (i = 0; i < len; i++) { |
| 3763 | expr_ty value; |
| 3764 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3765 | if (res != 0) goto failed; |
| 3766 | asdl_seq_SET(decorator_list, i, value); |
| 3767 | } |
| 3768 | Py_XDECREF(tmp); |
| 3769 | tmp = NULL; |
| 3770 | } else { |
| 3771 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 3772 | return 1; |
| 3773 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3774 | if (_PyObject_HasAttrId(obj, &PyId_returns)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3775 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3776 | tmp = _PyObject_GetAttrId(obj, &PyId_returns); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3777 | if (tmp == NULL) goto failed; |
| 3778 | res = obj2ast_expr(tmp, &returns, arena); |
| 3779 | if (res != 0) goto failed; |
| 3780 | Py_XDECREF(tmp); |
| 3781 | tmp = NULL; |
| 3782 | } else { |
| 3783 | returns = NULL; |
| 3784 | } |
| 3785 | *out = FunctionDef(name, args, body, decorator_list, returns, |
| 3786 | lineno, col_offset, arena); |
| 3787 | if (*out == NULL) goto failed; |
| 3788 | return 0; |
| 3789 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3790 | isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type); |
| 3791 | if (isinstance == -1) { |
| 3792 | return 1; |
| 3793 | } |
| 3794 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3795 | identifier name; |
| 3796 | asdl_seq* bases; |
| 3797 | asdl_seq* keywords; |
| 3798 | expr_ty starargs; |
| 3799 | expr_ty kwargs; |
| 3800 | asdl_seq* body; |
| 3801 | asdl_seq* decorator_list; |
| 3802 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3803 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3804 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3805 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3806 | if (tmp == NULL) goto failed; |
| 3807 | res = obj2ast_identifier(tmp, &name, arena); |
| 3808 | if (res != 0) goto failed; |
| 3809 | Py_XDECREF(tmp); |
| 3810 | tmp = NULL; |
| 3811 | } else { |
| 3812 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 3813 | return 1; |
| 3814 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3815 | if (_PyObject_HasAttrId(obj, &PyId_bases)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3816 | int res; |
| 3817 | Py_ssize_t len; |
| 3818 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3819 | tmp = _PyObject_GetAttrId(obj, &PyId_bases); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3820 | if (tmp == NULL) goto failed; |
| 3821 | if (!PyList_Check(tmp)) { |
| 3822 | PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3823 | goto failed; |
| 3824 | } |
| 3825 | len = PyList_GET_SIZE(tmp); |
| 3826 | bases = asdl_seq_new(len, arena); |
| 3827 | if (bases == NULL) goto failed; |
| 3828 | for (i = 0; i < len; i++) { |
| 3829 | expr_ty value; |
| 3830 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3831 | if (res != 0) goto failed; |
| 3832 | asdl_seq_SET(bases, i, value); |
| 3833 | } |
| 3834 | Py_XDECREF(tmp); |
| 3835 | tmp = NULL; |
| 3836 | } else { |
| 3837 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 3838 | return 1; |
| 3839 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3840 | if (_PyObject_HasAttrId(obj, &PyId_keywords)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3841 | int res; |
| 3842 | Py_ssize_t len; |
| 3843 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3844 | tmp = _PyObject_GetAttrId(obj, &PyId_keywords); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3845 | if (tmp == NULL) goto failed; |
| 3846 | if (!PyList_Check(tmp)) { |
| 3847 | PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3848 | goto failed; |
| 3849 | } |
| 3850 | len = PyList_GET_SIZE(tmp); |
| 3851 | keywords = asdl_seq_new(len, arena); |
| 3852 | if (keywords == NULL) goto failed; |
| 3853 | for (i = 0; i < len; i++) { |
| 3854 | keyword_ty value; |
| 3855 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3856 | if (res != 0) goto failed; |
| 3857 | asdl_seq_SET(keywords, i, value); |
| 3858 | } |
| 3859 | Py_XDECREF(tmp); |
| 3860 | tmp = NULL; |
| 3861 | } else { |
| 3862 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 3863 | return 1; |
| 3864 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3865 | if (_PyObject_HasAttrId(obj, &PyId_starargs)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3866 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3867 | tmp = _PyObject_GetAttrId(obj, &PyId_starargs); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3868 | if (tmp == NULL) goto failed; |
| 3869 | res = obj2ast_expr(tmp, &starargs, arena); |
| 3870 | if (res != 0) goto failed; |
| 3871 | Py_XDECREF(tmp); |
| 3872 | tmp = NULL; |
| 3873 | } else { |
| 3874 | starargs = NULL; |
| 3875 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3876 | if (_PyObject_HasAttrId(obj, &PyId_kwargs)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3877 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3878 | tmp = _PyObject_GetAttrId(obj, &PyId_kwargs); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3879 | if (tmp == NULL) goto failed; |
| 3880 | res = obj2ast_expr(tmp, &kwargs, arena); |
| 3881 | if (res != 0) goto failed; |
| 3882 | Py_XDECREF(tmp); |
| 3883 | tmp = NULL; |
| 3884 | } else { |
| 3885 | kwargs = NULL; |
| 3886 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3887 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3888 | int res; |
| 3889 | Py_ssize_t len; |
| 3890 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3891 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3892 | if (tmp == NULL) goto failed; |
| 3893 | if (!PyList_Check(tmp)) { |
| 3894 | PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3895 | goto failed; |
| 3896 | } |
| 3897 | len = PyList_GET_SIZE(tmp); |
| 3898 | body = asdl_seq_new(len, arena); |
| 3899 | if (body == NULL) goto failed; |
| 3900 | for (i = 0; i < len; i++) { |
| 3901 | stmt_ty value; |
| 3902 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3903 | if (res != 0) goto failed; |
| 3904 | asdl_seq_SET(body, i, value); |
| 3905 | } |
| 3906 | Py_XDECREF(tmp); |
| 3907 | tmp = NULL; |
| 3908 | } else { |
| 3909 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 3910 | return 1; |
| 3911 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3912 | if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3913 | int res; |
| 3914 | Py_ssize_t len; |
| 3915 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3916 | tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3917 | if (tmp == NULL) goto failed; |
| 3918 | if (!PyList_Check(tmp)) { |
| 3919 | PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3920 | goto failed; |
| 3921 | } |
| 3922 | len = PyList_GET_SIZE(tmp); |
| 3923 | decorator_list = asdl_seq_new(len, arena); |
| 3924 | if (decorator_list == NULL) goto failed; |
| 3925 | for (i = 0; i < len; i++) { |
| 3926 | expr_ty value; |
| 3927 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3928 | if (res != 0) goto failed; |
| 3929 | asdl_seq_SET(decorator_list, i, value); |
| 3930 | } |
| 3931 | Py_XDECREF(tmp); |
| 3932 | tmp = NULL; |
| 3933 | } else { |
| 3934 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 3935 | return 1; |
| 3936 | } |
| 3937 | *out = ClassDef(name, bases, keywords, starargs, kwargs, body, |
| 3938 | decorator_list, lineno, col_offset, arena); |
| 3939 | if (*out == NULL) goto failed; |
| 3940 | return 0; |
| 3941 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3942 | isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type); |
| 3943 | if (isinstance == -1) { |
| 3944 | return 1; |
| 3945 | } |
| 3946 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3947 | expr_ty value; |
| 3948 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3949 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3950 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3951 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3952 | if (tmp == NULL) goto failed; |
| 3953 | res = obj2ast_expr(tmp, &value, arena); |
| 3954 | if (res != 0) goto failed; |
| 3955 | Py_XDECREF(tmp); |
| 3956 | tmp = NULL; |
| 3957 | } else { |
| 3958 | value = NULL; |
| 3959 | } |
| 3960 | *out = Return(value, lineno, col_offset, arena); |
| 3961 | if (*out == NULL) goto failed; |
| 3962 | return 0; |
| 3963 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3964 | isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type); |
| 3965 | if (isinstance == -1) { |
| 3966 | return 1; |
| 3967 | } |
| 3968 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3969 | asdl_seq* targets; |
| 3970 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3971 | if (_PyObject_HasAttrId(obj, &PyId_targets)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3972 | int res; |
| 3973 | Py_ssize_t len; |
| 3974 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3975 | tmp = _PyObject_GetAttrId(obj, &PyId_targets); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3976 | if (tmp == NULL) goto failed; |
| 3977 | if (!PyList_Check(tmp)) { |
| 3978 | PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3979 | goto failed; |
| 3980 | } |
| 3981 | len = PyList_GET_SIZE(tmp); |
| 3982 | targets = asdl_seq_new(len, arena); |
| 3983 | if (targets == NULL) goto failed; |
| 3984 | for (i = 0; i < len; i++) { |
| 3985 | expr_ty value; |
| 3986 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3987 | if (res != 0) goto failed; |
| 3988 | asdl_seq_SET(targets, i, value); |
| 3989 | } |
| 3990 | Py_XDECREF(tmp); |
| 3991 | tmp = NULL; |
| 3992 | } else { |
| 3993 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 3994 | return 1; |
| 3995 | } |
| 3996 | *out = Delete(targets, lineno, col_offset, arena); |
| 3997 | if (*out == NULL) goto failed; |
| 3998 | return 0; |
| 3999 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4000 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type); |
| 4001 | if (isinstance == -1) { |
| 4002 | return 1; |
| 4003 | } |
| 4004 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4005 | asdl_seq* targets; |
| 4006 | expr_ty value; |
| 4007 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4008 | if (_PyObject_HasAttrId(obj, &PyId_targets)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4009 | int res; |
| 4010 | Py_ssize_t len; |
| 4011 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4012 | tmp = _PyObject_GetAttrId(obj, &PyId_targets); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4013 | if (tmp == NULL) goto failed; |
| 4014 | if (!PyList_Check(tmp)) { |
| 4015 | PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4016 | goto failed; |
| 4017 | } |
| 4018 | len = PyList_GET_SIZE(tmp); |
| 4019 | targets = asdl_seq_new(len, arena); |
| 4020 | if (targets == NULL) goto failed; |
| 4021 | for (i = 0; i < len; i++) { |
| 4022 | expr_ty value; |
| 4023 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4024 | if (res != 0) goto failed; |
| 4025 | asdl_seq_SET(targets, i, value); |
| 4026 | } |
| 4027 | Py_XDECREF(tmp); |
| 4028 | tmp = NULL; |
| 4029 | } else { |
| 4030 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 4031 | return 1; |
| 4032 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4033 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4034 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4035 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4036 | if (tmp == NULL) goto failed; |
| 4037 | res = obj2ast_expr(tmp, &value, arena); |
| 4038 | if (res != 0) goto failed; |
| 4039 | Py_XDECREF(tmp); |
| 4040 | tmp = NULL; |
| 4041 | } else { |
| 4042 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 4043 | return 1; |
| 4044 | } |
| 4045 | *out = Assign(targets, value, lineno, col_offset, arena); |
| 4046 | if (*out == NULL) goto failed; |
| 4047 | return 0; |
| 4048 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4049 | isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type); |
| 4050 | if (isinstance == -1) { |
| 4051 | return 1; |
| 4052 | } |
| 4053 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4054 | expr_ty target; |
| 4055 | operator_ty op; |
| 4056 | expr_ty value; |
| 4057 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4058 | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4059 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4060 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4061 | if (tmp == NULL) goto failed; |
| 4062 | res = obj2ast_expr(tmp, &target, arena); |
| 4063 | if (res != 0) goto failed; |
| 4064 | Py_XDECREF(tmp); |
| 4065 | tmp = NULL; |
| 4066 | } else { |
| 4067 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 4068 | return 1; |
| 4069 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4070 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4071 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4072 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4073 | if (tmp == NULL) goto failed; |
| 4074 | res = obj2ast_operator(tmp, &op, arena); |
| 4075 | if (res != 0) goto failed; |
| 4076 | Py_XDECREF(tmp); |
| 4077 | tmp = NULL; |
| 4078 | } else { |
| 4079 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 4080 | return 1; |
| 4081 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4082 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4083 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4084 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4085 | if (tmp == NULL) goto failed; |
| 4086 | res = obj2ast_expr(tmp, &value, arena); |
| 4087 | if (res != 0) goto failed; |
| 4088 | Py_XDECREF(tmp); |
| 4089 | tmp = NULL; |
| 4090 | } else { |
| 4091 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 4092 | return 1; |
| 4093 | } |
| 4094 | *out = AugAssign(target, op, value, lineno, col_offset, arena); |
| 4095 | if (*out == NULL) goto failed; |
| 4096 | return 0; |
| 4097 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4098 | isinstance = PyObject_IsInstance(obj, (PyObject*)For_type); |
| 4099 | if (isinstance == -1) { |
| 4100 | return 1; |
| 4101 | } |
| 4102 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4103 | expr_ty target; |
| 4104 | expr_ty iter; |
| 4105 | asdl_seq* body; |
| 4106 | asdl_seq* orelse; |
| 4107 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4108 | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4109 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4110 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4111 | if (tmp == NULL) goto failed; |
| 4112 | res = obj2ast_expr(tmp, &target, arena); |
| 4113 | if (res != 0) goto failed; |
| 4114 | Py_XDECREF(tmp); |
| 4115 | tmp = NULL; |
| 4116 | } else { |
| 4117 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 4118 | return 1; |
| 4119 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4120 | if (_PyObject_HasAttrId(obj, &PyId_iter)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4121 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4122 | tmp = _PyObject_GetAttrId(obj, &PyId_iter); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4123 | if (tmp == NULL) goto failed; |
| 4124 | res = obj2ast_expr(tmp, &iter, arena); |
| 4125 | if (res != 0) goto failed; |
| 4126 | Py_XDECREF(tmp); |
| 4127 | tmp = NULL; |
| 4128 | } else { |
| 4129 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 4130 | return 1; |
| 4131 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4132 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4133 | int res; |
| 4134 | Py_ssize_t len; |
| 4135 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4136 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4137 | if (tmp == NULL) goto failed; |
| 4138 | if (!PyList_Check(tmp)) { |
| 4139 | PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4140 | goto failed; |
| 4141 | } |
| 4142 | len = PyList_GET_SIZE(tmp); |
| 4143 | body = asdl_seq_new(len, arena); |
| 4144 | if (body == NULL) goto failed; |
| 4145 | for (i = 0; i < len; i++) { |
| 4146 | stmt_ty value; |
| 4147 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4148 | if (res != 0) goto failed; |
| 4149 | asdl_seq_SET(body, i, value); |
| 4150 | } |
| 4151 | Py_XDECREF(tmp); |
| 4152 | tmp = NULL; |
| 4153 | } else { |
| 4154 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 4155 | return 1; |
| 4156 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4157 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4158 | int res; |
| 4159 | Py_ssize_t len; |
| 4160 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4161 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4162 | if (tmp == NULL) goto failed; |
| 4163 | if (!PyList_Check(tmp)) { |
| 4164 | PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4165 | goto failed; |
| 4166 | } |
| 4167 | len = PyList_GET_SIZE(tmp); |
| 4168 | orelse = asdl_seq_new(len, arena); |
| 4169 | if (orelse == NULL) goto failed; |
| 4170 | for (i = 0; i < len; i++) { |
| 4171 | stmt_ty value; |
| 4172 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4173 | if (res != 0) goto failed; |
| 4174 | asdl_seq_SET(orelse, i, value); |
| 4175 | } |
| 4176 | Py_XDECREF(tmp); |
| 4177 | tmp = NULL; |
| 4178 | } else { |
| 4179 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 4180 | return 1; |
| 4181 | } |
| 4182 | *out = For(target, iter, body, orelse, lineno, col_offset, |
| 4183 | arena); |
| 4184 | if (*out == NULL) goto failed; |
| 4185 | return 0; |
| 4186 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4187 | isinstance = PyObject_IsInstance(obj, (PyObject*)While_type); |
| 4188 | if (isinstance == -1) { |
| 4189 | return 1; |
| 4190 | } |
| 4191 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4192 | expr_ty test; |
| 4193 | asdl_seq* body; |
| 4194 | asdl_seq* orelse; |
| 4195 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4196 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4197 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4198 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4199 | if (tmp == NULL) goto failed; |
| 4200 | res = obj2ast_expr(tmp, &test, arena); |
| 4201 | if (res != 0) goto failed; |
| 4202 | Py_XDECREF(tmp); |
| 4203 | tmp = NULL; |
| 4204 | } else { |
| 4205 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 4206 | return 1; |
| 4207 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4208 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4209 | int res; |
| 4210 | Py_ssize_t len; |
| 4211 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4212 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4213 | if (tmp == NULL) goto failed; |
| 4214 | if (!PyList_Check(tmp)) { |
| 4215 | PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4216 | goto failed; |
| 4217 | } |
| 4218 | len = PyList_GET_SIZE(tmp); |
| 4219 | body = asdl_seq_new(len, arena); |
| 4220 | if (body == NULL) goto failed; |
| 4221 | for (i = 0; i < len; i++) { |
| 4222 | stmt_ty value; |
| 4223 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4224 | if (res != 0) goto failed; |
| 4225 | asdl_seq_SET(body, i, value); |
| 4226 | } |
| 4227 | Py_XDECREF(tmp); |
| 4228 | tmp = NULL; |
| 4229 | } else { |
| 4230 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 4231 | return 1; |
| 4232 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4233 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4234 | int res; |
| 4235 | Py_ssize_t len; |
| 4236 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4237 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4238 | if (tmp == NULL) goto failed; |
| 4239 | if (!PyList_Check(tmp)) { |
| 4240 | PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4241 | goto failed; |
| 4242 | } |
| 4243 | len = PyList_GET_SIZE(tmp); |
| 4244 | orelse = asdl_seq_new(len, arena); |
| 4245 | if (orelse == NULL) goto failed; |
| 4246 | for (i = 0; i < len; i++) { |
| 4247 | stmt_ty value; |
| 4248 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4249 | if (res != 0) goto failed; |
| 4250 | asdl_seq_SET(orelse, i, value); |
| 4251 | } |
| 4252 | Py_XDECREF(tmp); |
| 4253 | tmp = NULL; |
| 4254 | } else { |
| 4255 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 4256 | return 1; |
| 4257 | } |
| 4258 | *out = While(test, body, orelse, lineno, col_offset, arena); |
| 4259 | if (*out == NULL) goto failed; |
| 4260 | return 0; |
| 4261 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4262 | isinstance = PyObject_IsInstance(obj, (PyObject*)If_type); |
| 4263 | if (isinstance == -1) { |
| 4264 | return 1; |
| 4265 | } |
| 4266 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4267 | expr_ty test; |
| 4268 | asdl_seq* body; |
| 4269 | asdl_seq* orelse; |
| 4270 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4271 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4272 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4273 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4274 | if (tmp == NULL) goto failed; |
| 4275 | res = obj2ast_expr(tmp, &test, arena); |
| 4276 | if (res != 0) goto failed; |
| 4277 | Py_XDECREF(tmp); |
| 4278 | tmp = NULL; |
| 4279 | } else { |
| 4280 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 4281 | return 1; |
| 4282 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4283 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4284 | int res; |
| 4285 | Py_ssize_t len; |
| 4286 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4287 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4288 | if (tmp == NULL) goto failed; |
| 4289 | if (!PyList_Check(tmp)) { |
| 4290 | PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4291 | goto failed; |
| 4292 | } |
| 4293 | len = PyList_GET_SIZE(tmp); |
| 4294 | body = asdl_seq_new(len, arena); |
| 4295 | if (body == NULL) goto failed; |
| 4296 | for (i = 0; i < len; i++) { |
| 4297 | stmt_ty value; |
| 4298 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4299 | if (res != 0) goto failed; |
| 4300 | asdl_seq_SET(body, i, value); |
| 4301 | } |
| 4302 | Py_XDECREF(tmp); |
| 4303 | tmp = NULL; |
| 4304 | } else { |
| 4305 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 4306 | return 1; |
| 4307 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4308 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4309 | int res; |
| 4310 | Py_ssize_t len; |
| 4311 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4312 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4313 | if (tmp == NULL) goto failed; |
| 4314 | if (!PyList_Check(tmp)) { |
| 4315 | PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4316 | goto failed; |
| 4317 | } |
| 4318 | len = PyList_GET_SIZE(tmp); |
| 4319 | orelse = asdl_seq_new(len, arena); |
| 4320 | if (orelse == NULL) goto failed; |
| 4321 | for (i = 0; i < len; i++) { |
| 4322 | stmt_ty value; |
| 4323 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4324 | if (res != 0) goto failed; |
| 4325 | asdl_seq_SET(orelse, i, value); |
| 4326 | } |
| 4327 | Py_XDECREF(tmp); |
| 4328 | tmp = NULL; |
| 4329 | } else { |
| 4330 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 4331 | return 1; |
| 4332 | } |
| 4333 | *out = If(test, body, orelse, lineno, col_offset, arena); |
| 4334 | if (*out == NULL) goto failed; |
| 4335 | return 0; |
| 4336 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4337 | isinstance = PyObject_IsInstance(obj, (PyObject*)With_type); |
| 4338 | if (isinstance == -1) { |
| 4339 | return 1; |
| 4340 | } |
| 4341 | if (isinstance) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4342 | asdl_seq* items; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4343 | asdl_seq* body; |
| 4344 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4345 | if (_PyObject_HasAttrId(obj, &PyId_items)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4346 | int res; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4347 | Py_ssize_t len; |
| 4348 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4349 | tmp = _PyObject_GetAttrId(obj, &PyId_items); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4350 | if (tmp == NULL) goto failed; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4351 | if (!PyList_Check(tmp)) { |
| 4352 | PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4353 | goto failed; |
| 4354 | } |
| 4355 | len = PyList_GET_SIZE(tmp); |
| 4356 | items = asdl_seq_new(len, arena); |
| 4357 | if (items == NULL) goto failed; |
| 4358 | for (i = 0; i < len; i++) { |
| 4359 | withitem_ty value; |
| 4360 | res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4361 | if (res != 0) goto failed; |
| 4362 | asdl_seq_SET(items, i, value); |
| 4363 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4364 | Py_XDECREF(tmp); |
| 4365 | tmp = NULL; |
| 4366 | } else { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4367 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4368 | return 1; |
| 4369 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4370 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4371 | int res; |
| 4372 | Py_ssize_t len; |
| 4373 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4374 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4375 | if (tmp == NULL) goto failed; |
| 4376 | if (!PyList_Check(tmp)) { |
| 4377 | PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4378 | goto failed; |
| 4379 | } |
| 4380 | len = PyList_GET_SIZE(tmp); |
| 4381 | body = asdl_seq_new(len, arena); |
| 4382 | if (body == NULL) goto failed; |
| 4383 | for (i = 0; i < len; i++) { |
| 4384 | stmt_ty value; |
| 4385 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4386 | if (res != 0) goto failed; |
| 4387 | asdl_seq_SET(body, i, value); |
| 4388 | } |
| 4389 | Py_XDECREF(tmp); |
| 4390 | tmp = NULL; |
| 4391 | } else { |
| 4392 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 4393 | return 1; |
| 4394 | } |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4395 | *out = With(items, body, lineno, col_offset, arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4396 | if (*out == NULL) goto failed; |
| 4397 | return 0; |
| 4398 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4399 | isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type); |
| 4400 | if (isinstance == -1) { |
| 4401 | return 1; |
| 4402 | } |
| 4403 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4404 | expr_ty exc; |
| 4405 | expr_ty cause; |
| 4406 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4407 | if (_PyObject_HasAttrId(obj, &PyId_exc)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4408 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4409 | tmp = _PyObject_GetAttrId(obj, &PyId_exc); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4410 | if (tmp == NULL) goto failed; |
| 4411 | res = obj2ast_expr(tmp, &exc, arena); |
| 4412 | if (res != 0) goto failed; |
| 4413 | Py_XDECREF(tmp); |
| 4414 | tmp = NULL; |
| 4415 | } else { |
| 4416 | exc = NULL; |
| 4417 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4418 | if (_PyObject_HasAttrId(obj, &PyId_cause)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4419 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4420 | tmp = _PyObject_GetAttrId(obj, &PyId_cause); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4421 | if (tmp == NULL) goto failed; |
| 4422 | res = obj2ast_expr(tmp, &cause, arena); |
| 4423 | if (res != 0) goto failed; |
| 4424 | Py_XDECREF(tmp); |
| 4425 | tmp = NULL; |
| 4426 | } else { |
| 4427 | cause = NULL; |
| 4428 | } |
| 4429 | *out = Raise(exc, cause, lineno, col_offset, arena); |
| 4430 | if (*out == NULL) goto failed; |
| 4431 | return 0; |
| 4432 | } |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4433 | isinstance = PyObject_IsInstance(obj, (PyObject*)Try_type); |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4434 | if (isinstance == -1) { |
| 4435 | return 1; |
| 4436 | } |
| 4437 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4438 | asdl_seq* body; |
| 4439 | asdl_seq* handlers; |
| 4440 | asdl_seq* orelse; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4441 | asdl_seq* finalbody; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4442 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4443 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4444 | int res; |
| 4445 | Py_ssize_t len; |
| 4446 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4447 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4448 | if (tmp == NULL) goto failed; |
| 4449 | if (!PyList_Check(tmp)) { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4450 | PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4451 | goto failed; |
| 4452 | } |
| 4453 | len = PyList_GET_SIZE(tmp); |
| 4454 | body = asdl_seq_new(len, arena); |
| 4455 | if (body == NULL) goto failed; |
| 4456 | for (i = 0; i < len; i++) { |
| 4457 | stmt_ty value; |
| 4458 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4459 | if (res != 0) goto failed; |
| 4460 | asdl_seq_SET(body, i, value); |
| 4461 | } |
| 4462 | Py_XDECREF(tmp); |
| 4463 | tmp = NULL; |
| 4464 | } else { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4465 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4466 | return 1; |
| 4467 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4468 | if (_PyObject_HasAttrId(obj, &PyId_handlers)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4469 | int res; |
| 4470 | Py_ssize_t len; |
| 4471 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4472 | tmp = _PyObject_GetAttrId(obj, &PyId_handlers); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4473 | if (tmp == NULL) goto failed; |
| 4474 | if (!PyList_Check(tmp)) { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4475 | PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4476 | goto failed; |
| 4477 | } |
| 4478 | len = PyList_GET_SIZE(tmp); |
| 4479 | handlers = asdl_seq_new(len, arena); |
| 4480 | if (handlers == NULL) goto failed; |
| 4481 | for (i = 0; i < len; i++) { |
| 4482 | excepthandler_ty value; |
| 4483 | res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4484 | if (res != 0) goto failed; |
| 4485 | asdl_seq_SET(handlers, i, value); |
| 4486 | } |
| 4487 | Py_XDECREF(tmp); |
| 4488 | tmp = NULL; |
| 4489 | } else { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4490 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4491 | return 1; |
| 4492 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4493 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4494 | int res; |
| 4495 | Py_ssize_t len; |
| 4496 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4497 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4498 | if (tmp == NULL) goto failed; |
| 4499 | if (!PyList_Check(tmp)) { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4500 | PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4501 | goto failed; |
| 4502 | } |
| 4503 | len = PyList_GET_SIZE(tmp); |
| 4504 | orelse = asdl_seq_new(len, arena); |
| 4505 | if (orelse == NULL) goto failed; |
| 4506 | for (i = 0; i < len; i++) { |
| 4507 | stmt_ty value; |
| 4508 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4509 | if (res != 0) goto failed; |
| 4510 | asdl_seq_SET(orelse, i, value); |
| 4511 | } |
| 4512 | Py_XDECREF(tmp); |
| 4513 | tmp = NULL; |
| 4514 | } else { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4515 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4516 | return 1; |
| 4517 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4518 | if (_PyObject_HasAttrId(obj, &PyId_finalbody)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4519 | int res; |
| 4520 | Py_ssize_t len; |
| 4521 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4522 | tmp = _PyObject_GetAttrId(obj, &PyId_finalbody); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4523 | if (tmp == NULL) goto failed; |
| 4524 | if (!PyList_Check(tmp)) { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4525 | PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4526 | goto failed; |
| 4527 | } |
| 4528 | len = PyList_GET_SIZE(tmp); |
| 4529 | finalbody = asdl_seq_new(len, arena); |
| 4530 | if (finalbody == NULL) goto failed; |
| 4531 | for (i = 0; i < len; i++) { |
| 4532 | stmt_ty value; |
| 4533 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4534 | if (res != 0) goto failed; |
| 4535 | asdl_seq_SET(finalbody, i, value); |
| 4536 | } |
| 4537 | Py_XDECREF(tmp); |
| 4538 | tmp = NULL; |
| 4539 | } else { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4540 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4541 | return 1; |
| 4542 | } |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4543 | *out = Try(body, handlers, orelse, finalbody, lineno, |
| 4544 | col_offset, arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4545 | if (*out == NULL) goto failed; |
| 4546 | return 0; |
| 4547 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4548 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type); |
| 4549 | if (isinstance == -1) { |
| 4550 | return 1; |
| 4551 | } |
| 4552 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4553 | expr_ty test; |
| 4554 | expr_ty msg; |
| 4555 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4556 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4557 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4558 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4559 | if (tmp == NULL) goto failed; |
| 4560 | res = obj2ast_expr(tmp, &test, arena); |
| 4561 | if (res != 0) goto failed; |
| 4562 | Py_XDECREF(tmp); |
| 4563 | tmp = NULL; |
| 4564 | } else { |
| 4565 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 4566 | return 1; |
| 4567 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4568 | if (_PyObject_HasAttrId(obj, &PyId_msg)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4569 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4570 | tmp = _PyObject_GetAttrId(obj, &PyId_msg); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4571 | if (tmp == NULL) goto failed; |
| 4572 | res = obj2ast_expr(tmp, &msg, arena); |
| 4573 | if (res != 0) goto failed; |
| 4574 | Py_XDECREF(tmp); |
| 4575 | tmp = NULL; |
| 4576 | } else { |
| 4577 | msg = NULL; |
| 4578 | } |
| 4579 | *out = Assert(test, msg, lineno, col_offset, arena); |
| 4580 | if (*out == NULL) goto failed; |
| 4581 | return 0; |
| 4582 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4583 | isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type); |
| 4584 | if (isinstance == -1) { |
| 4585 | return 1; |
| 4586 | } |
| 4587 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4588 | asdl_seq* names; |
| 4589 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4590 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4591 | int res; |
| 4592 | Py_ssize_t len; |
| 4593 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4594 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4595 | if (tmp == NULL) goto failed; |
| 4596 | if (!PyList_Check(tmp)) { |
| 4597 | PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4598 | goto failed; |
| 4599 | } |
| 4600 | len = PyList_GET_SIZE(tmp); |
| 4601 | names = asdl_seq_new(len, arena); |
| 4602 | if (names == NULL) goto failed; |
| 4603 | for (i = 0; i < len; i++) { |
| 4604 | alias_ty value; |
| 4605 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4606 | if (res != 0) goto failed; |
| 4607 | asdl_seq_SET(names, i, value); |
| 4608 | } |
| 4609 | Py_XDECREF(tmp); |
| 4610 | tmp = NULL; |
| 4611 | } else { |
| 4612 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 4613 | return 1; |
| 4614 | } |
| 4615 | *out = Import(names, lineno, col_offset, arena); |
| 4616 | if (*out == NULL) goto failed; |
| 4617 | return 0; |
| 4618 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4619 | isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type); |
| 4620 | if (isinstance == -1) { |
| 4621 | return 1; |
| 4622 | } |
| 4623 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4624 | identifier module; |
| 4625 | asdl_seq* names; |
| 4626 | int level; |
| 4627 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4628 | if (_PyObject_HasAttrId(obj, &PyId_module)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4629 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4630 | tmp = _PyObject_GetAttrId(obj, &PyId_module); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4631 | if (tmp == NULL) goto failed; |
| 4632 | res = obj2ast_identifier(tmp, &module, arena); |
| 4633 | if (res != 0) goto failed; |
| 4634 | Py_XDECREF(tmp); |
| 4635 | tmp = NULL; |
| 4636 | } else { |
Benjamin Peterson | 78565b2 | 2009-06-28 19:19:51 +0000 | [diff] [blame] | 4637 | module = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4638 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4639 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4640 | int res; |
| 4641 | Py_ssize_t len; |
| 4642 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4643 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4644 | if (tmp == NULL) goto failed; |
| 4645 | if (!PyList_Check(tmp)) { |
| 4646 | PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4647 | goto failed; |
| 4648 | } |
| 4649 | len = PyList_GET_SIZE(tmp); |
| 4650 | names = asdl_seq_new(len, arena); |
| 4651 | if (names == NULL) goto failed; |
| 4652 | for (i = 0; i < len; i++) { |
| 4653 | alias_ty value; |
| 4654 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4655 | if (res != 0) goto failed; |
| 4656 | asdl_seq_SET(names, i, value); |
| 4657 | } |
| 4658 | Py_XDECREF(tmp); |
| 4659 | tmp = NULL; |
| 4660 | } else { |
| 4661 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 4662 | return 1; |
| 4663 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4664 | if (_PyObject_HasAttrId(obj, &PyId_level)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4665 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4666 | tmp = _PyObject_GetAttrId(obj, &PyId_level); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4667 | if (tmp == NULL) goto failed; |
| 4668 | res = obj2ast_int(tmp, &level, arena); |
| 4669 | if (res != 0) goto failed; |
| 4670 | Py_XDECREF(tmp); |
| 4671 | tmp = NULL; |
| 4672 | } else { |
| 4673 | level = 0; |
| 4674 | } |
| 4675 | *out = ImportFrom(module, names, level, lineno, col_offset, |
| 4676 | arena); |
| 4677 | if (*out == NULL) goto failed; |
| 4678 | return 0; |
| 4679 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4680 | isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type); |
| 4681 | if (isinstance == -1) { |
| 4682 | return 1; |
| 4683 | } |
| 4684 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4685 | asdl_seq* names; |
| 4686 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4687 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4688 | int res; |
| 4689 | Py_ssize_t len; |
| 4690 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4691 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4692 | if (tmp == NULL) goto failed; |
| 4693 | if (!PyList_Check(tmp)) { |
| 4694 | PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4695 | goto failed; |
| 4696 | } |
| 4697 | len = PyList_GET_SIZE(tmp); |
| 4698 | names = asdl_seq_new(len, arena); |
| 4699 | if (names == NULL) goto failed; |
| 4700 | for (i = 0; i < len; i++) { |
| 4701 | identifier value; |
| 4702 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4703 | if (res != 0) goto failed; |
| 4704 | asdl_seq_SET(names, i, value); |
| 4705 | } |
| 4706 | Py_XDECREF(tmp); |
| 4707 | tmp = NULL; |
| 4708 | } else { |
| 4709 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 4710 | return 1; |
| 4711 | } |
| 4712 | *out = Global(names, lineno, col_offset, arena); |
| 4713 | if (*out == NULL) goto failed; |
| 4714 | return 0; |
| 4715 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4716 | isinstance = PyObject_IsInstance(obj, (PyObject*)Nonlocal_type); |
| 4717 | if (isinstance == -1) { |
| 4718 | return 1; |
| 4719 | } |
| 4720 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4721 | asdl_seq* names; |
| 4722 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4723 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4724 | int res; |
| 4725 | Py_ssize_t len; |
| 4726 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4727 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4728 | if (tmp == NULL) goto failed; |
| 4729 | if (!PyList_Check(tmp)) { |
| 4730 | PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4731 | goto failed; |
| 4732 | } |
| 4733 | len = PyList_GET_SIZE(tmp); |
| 4734 | names = asdl_seq_new(len, arena); |
| 4735 | if (names == NULL) goto failed; |
| 4736 | for (i = 0; i < len; i++) { |
| 4737 | identifier value; |
| 4738 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4739 | if (res != 0) goto failed; |
| 4740 | asdl_seq_SET(names, i, value); |
| 4741 | } |
| 4742 | Py_XDECREF(tmp); |
| 4743 | tmp = NULL; |
| 4744 | } else { |
| 4745 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 4746 | return 1; |
| 4747 | } |
| 4748 | *out = Nonlocal(names, lineno, col_offset, arena); |
| 4749 | if (*out == NULL) goto failed; |
| 4750 | return 0; |
| 4751 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4752 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type); |
| 4753 | if (isinstance == -1) { |
| 4754 | return 1; |
| 4755 | } |
| 4756 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4757 | expr_ty value; |
| 4758 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4759 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4760 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4761 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4762 | if (tmp == NULL) goto failed; |
| 4763 | res = obj2ast_expr(tmp, &value, arena); |
| 4764 | if (res != 0) goto failed; |
| 4765 | Py_XDECREF(tmp); |
| 4766 | tmp = NULL; |
| 4767 | } else { |
| 4768 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 4769 | return 1; |
| 4770 | } |
| 4771 | *out = Expr(value, lineno, col_offset, arena); |
| 4772 | if (*out == NULL) goto failed; |
| 4773 | return 0; |
| 4774 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4775 | isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type); |
| 4776 | if (isinstance == -1) { |
| 4777 | return 1; |
| 4778 | } |
| 4779 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4780 | |
| 4781 | *out = Pass(lineno, col_offset, arena); |
| 4782 | if (*out == NULL) goto failed; |
| 4783 | return 0; |
| 4784 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4785 | isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type); |
| 4786 | if (isinstance == -1) { |
| 4787 | return 1; |
| 4788 | } |
| 4789 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4790 | |
| 4791 | *out = Break(lineno, col_offset, arena); |
| 4792 | if (*out == NULL) goto failed; |
| 4793 | return 0; |
| 4794 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4795 | isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type); |
| 4796 | if (isinstance == -1) { |
| 4797 | return 1; |
| 4798 | } |
| 4799 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4800 | |
| 4801 | *out = Continue(lineno, col_offset, arena); |
| 4802 | if (*out == NULL) goto failed; |
| 4803 | return 0; |
| 4804 | } |
| 4805 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 4806 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
| 4807 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 4808 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4809 | return 1; |
| 4810 | } |
| 4811 | |
| 4812 | int |
| 4813 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 4814 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4815 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4816 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 4817 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4818 | int lineno; |
| 4819 | int col_offset; |
| 4820 | |
| 4821 | if (obj == Py_None) { |
| 4822 | *out = NULL; |
| 4823 | return 0; |
| 4824 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4825 | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4826 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4827 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4828 | if (tmp == NULL) goto failed; |
| 4829 | res = obj2ast_int(tmp, &lineno, arena); |
| 4830 | if (res != 0) goto failed; |
| 4831 | Py_XDECREF(tmp); |
| 4832 | tmp = NULL; |
| 4833 | } else { |
| 4834 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 4835 | return 1; |
| 4836 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4837 | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4838 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4839 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4840 | if (tmp == NULL) goto failed; |
| 4841 | res = obj2ast_int(tmp, &col_offset, arena); |
| 4842 | if (res != 0) goto failed; |
| 4843 | Py_XDECREF(tmp); |
| 4844 | tmp = NULL; |
| 4845 | } else { |
| 4846 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 4847 | return 1; |
| 4848 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4849 | isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type); |
| 4850 | if (isinstance == -1) { |
| 4851 | return 1; |
| 4852 | } |
| 4853 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4854 | boolop_ty op; |
| 4855 | asdl_seq* values; |
| 4856 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4857 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4858 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4859 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4860 | if (tmp == NULL) goto failed; |
| 4861 | res = obj2ast_boolop(tmp, &op, arena); |
| 4862 | if (res != 0) goto failed; |
| 4863 | Py_XDECREF(tmp); |
| 4864 | tmp = NULL; |
| 4865 | } else { |
| 4866 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 4867 | return 1; |
| 4868 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4869 | if (_PyObject_HasAttrId(obj, &PyId_values)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4870 | int res; |
| 4871 | Py_ssize_t len; |
| 4872 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4873 | tmp = _PyObject_GetAttrId(obj, &PyId_values); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4874 | if (tmp == NULL) goto failed; |
| 4875 | if (!PyList_Check(tmp)) { |
| 4876 | PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4877 | goto failed; |
| 4878 | } |
| 4879 | len = PyList_GET_SIZE(tmp); |
| 4880 | values = asdl_seq_new(len, arena); |
| 4881 | if (values == NULL) goto failed; |
| 4882 | for (i = 0; i < len; i++) { |
| 4883 | expr_ty value; |
| 4884 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4885 | if (res != 0) goto failed; |
| 4886 | asdl_seq_SET(values, i, value); |
| 4887 | } |
| 4888 | Py_XDECREF(tmp); |
| 4889 | tmp = NULL; |
| 4890 | } else { |
| 4891 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 4892 | return 1; |
| 4893 | } |
| 4894 | *out = BoolOp(op, values, lineno, col_offset, arena); |
| 4895 | if (*out == NULL) goto failed; |
| 4896 | return 0; |
| 4897 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4898 | isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type); |
| 4899 | if (isinstance == -1) { |
| 4900 | return 1; |
| 4901 | } |
| 4902 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4903 | expr_ty left; |
| 4904 | operator_ty op; |
| 4905 | expr_ty right; |
| 4906 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4907 | if (_PyObject_HasAttrId(obj, &PyId_left)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4908 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4909 | tmp = _PyObject_GetAttrId(obj, &PyId_left); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4910 | if (tmp == NULL) goto failed; |
| 4911 | res = obj2ast_expr(tmp, &left, arena); |
| 4912 | if (res != 0) goto failed; |
| 4913 | Py_XDECREF(tmp); |
| 4914 | tmp = NULL; |
| 4915 | } else { |
| 4916 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 4917 | return 1; |
| 4918 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4919 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4920 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4921 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4922 | if (tmp == NULL) goto failed; |
| 4923 | res = obj2ast_operator(tmp, &op, arena); |
| 4924 | if (res != 0) goto failed; |
| 4925 | Py_XDECREF(tmp); |
| 4926 | tmp = NULL; |
| 4927 | } else { |
| 4928 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 4929 | return 1; |
| 4930 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4931 | if (_PyObject_HasAttrId(obj, &PyId_right)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4932 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4933 | tmp = _PyObject_GetAttrId(obj, &PyId_right); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4934 | if (tmp == NULL) goto failed; |
| 4935 | res = obj2ast_expr(tmp, &right, arena); |
| 4936 | if (res != 0) goto failed; |
| 4937 | Py_XDECREF(tmp); |
| 4938 | tmp = NULL; |
| 4939 | } else { |
| 4940 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 4941 | return 1; |
| 4942 | } |
| 4943 | *out = BinOp(left, op, right, lineno, col_offset, arena); |
| 4944 | if (*out == NULL) goto failed; |
| 4945 | return 0; |
| 4946 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4947 | isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type); |
| 4948 | if (isinstance == -1) { |
| 4949 | return 1; |
| 4950 | } |
| 4951 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4952 | unaryop_ty op; |
| 4953 | expr_ty operand; |
| 4954 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4955 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4956 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4957 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4958 | if (tmp == NULL) goto failed; |
| 4959 | res = obj2ast_unaryop(tmp, &op, arena); |
| 4960 | if (res != 0) goto failed; |
| 4961 | Py_XDECREF(tmp); |
| 4962 | tmp = NULL; |
| 4963 | } else { |
| 4964 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 4965 | return 1; |
| 4966 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4967 | if (_PyObject_HasAttrId(obj, &PyId_operand)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4968 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4969 | tmp = _PyObject_GetAttrId(obj, &PyId_operand); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4970 | if (tmp == NULL) goto failed; |
| 4971 | res = obj2ast_expr(tmp, &operand, arena); |
| 4972 | if (res != 0) goto failed; |
| 4973 | Py_XDECREF(tmp); |
| 4974 | tmp = NULL; |
| 4975 | } else { |
| 4976 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 4977 | return 1; |
| 4978 | } |
| 4979 | *out = UnaryOp(op, operand, lineno, col_offset, arena); |
| 4980 | if (*out == NULL) goto failed; |
| 4981 | return 0; |
| 4982 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4983 | isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type); |
| 4984 | if (isinstance == -1) { |
| 4985 | return 1; |
| 4986 | } |
| 4987 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4988 | arguments_ty args; |
| 4989 | expr_ty body; |
| 4990 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4991 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4992 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4993 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4994 | if (tmp == NULL) goto failed; |
| 4995 | res = obj2ast_arguments(tmp, &args, arena); |
| 4996 | if (res != 0) goto failed; |
| 4997 | Py_XDECREF(tmp); |
| 4998 | tmp = NULL; |
| 4999 | } else { |
| 5000 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 5001 | return 1; |
| 5002 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5003 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5004 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5005 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5006 | if (tmp == NULL) goto failed; |
| 5007 | res = obj2ast_expr(tmp, &body, arena); |
| 5008 | if (res != 0) goto failed; |
| 5009 | Py_XDECREF(tmp); |
| 5010 | tmp = NULL; |
| 5011 | } else { |
| 5012 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 5013 | return 1; |
| 5014 | } |
| 5015 | *out = Lambda(args, body, lineno, col_offset, arena); |
| 5016 | if (*out == NULL) goto failed; |
| 5017 | return 0; |
| 5018 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5019 | isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type); |
| 5020 | if (isinstance == -1) { |
| 5021 | return 1; |
| 5022 | } |
| 5023 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5024 | expr_ty test; |
| 5025 | expr_ty body; |
| 5026 | expr_ty orelse; |
| 5027 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5028 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5029 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5030 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5031 | if (tmp == NULL) goto failed; |
| 5032 | res = obj2ast_expr(tmp, &test, arena); |
| 5033 | if (res != 0) goto failed; |
| 5034 | Py_XDECREF(tmp); |
| 5035 | tmp = NULL; |
| 5036 | } else { |
| 5037 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 5038 | return 1; |
| 5039 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5040 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5041 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5042 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5043 | if (tmp == NULL) goto failed; |
| 5044 | res = obj2ast_expr(tmp, &body, arena); |
| 5045 | if (res != 0) goto failed; |
| 5046 | Py_XDECREF(tmp); |
| 5047 | tmp = NULL; |
| 5048 | } else { |
| 5049 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 5050 | return 1; |
| 5051 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5052 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5053 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5054 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5055 | if (tmp == NULL) goto failed; |
| 5056 | res = obj2ast_expr(tmp, &orelse, arena); |
| 5057 | if (res != 0) goto failed; |
| 5058 | Py_XDECREF(tmp); |
| 5059 | tmp = NULL; |
| 5060 | } else { |
| 5061 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 5062 | return 1; |
| 5063 | } |
| 5064 | *out = IfExp(test, body, orelse, lineno, col_offset, arena); |
| 5065 | if (*out == NULL) goto failed; |
| 5066 | return 0; |
| 5067 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5068 | isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type); |
| 5069 | if (isinstance == -1) { |
| 5070 | return 1; |
| 5071 | } |
| 5072 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5073 | asdl_seq* keys; |
| 5074 | asdl_seq* values; |
| 5075 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5076 | if (_PyObject_HasAttrId(obj, &PyId_keys)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5077 | int res; |
| 5078 | Py_ssize_t len; |
| 5079 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5080 | tmp = _PyObject_GetAttrId(obj, &PyId_keys); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5081 | if (tmp == NULL) goto failed; |
| 5082 | if (!PyList_Check(tmp)) { |
| 5083 | PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5084 | goto failed; |
| 5085 | } |
| 5086 | len = PyList_GET_SIZE(tmp); |
| 5087 | keys = asdl_seq_new(len, arena); |
| 5088 | if (keys == NULL) goto failed; |
| 5089 | for (i = 0; i < len; i++) { |
| 5090 | expr_ty value; |
| 5091 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5092 | if (res != 0) goto failed; |
| 5093 | asdl_seq_SET(keys, i, value); |
| 5094 | } |
| 5095 | Py_XDECREF(tmp); |
| 5096 | tmp = NULL; |
| 5097 | } else { |
| 5098 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 5099 | return 1; |
| 5100 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5101 | if (_PyObject_HasAttrId(obj, &PyId_values)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5102 | int res; |
| 5103 | Py_ssize_t len; |
| 5104 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5105 | tmp = _PyObject_GetAttrId(obj, &PyId_values); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5106 | if (tmp == NULL) goto failed; |
| 5107 | if (!PyList_Check(tmp)) { |
| 5108 | PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5109 | goto failed; |
| 5110 | } |
| 5111 | len = PyList_GET_SIZE(tmp); |
| 5112 | values = asdl_seq_new(len, arena); |
| 5113 | if (values == NULL) goto failed; |
| 5114 | for (i = 0; i < len; i++) { |
| 5115 | expr_ty value; |
| 5116 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5117 | if (res != 0) goto failed; |
| 5118 | asdl_seq_SET(values, i, value); |
| 5119 | } |
| 5120 | Py_XDECREF(tmp); |
| 5121 | tmp = NULL; |
| 5122 | } else { |
| 5123 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 5124 | return 1; |
| 5125 | } |
| 5126 | *out = Dict(keys, values, lineno, col_offset, arena); |
| 5127 | if (*out == NULL) goto failed; |
| 5128 | return 0; |
| 5129 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5130 | isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type); |
| 5131 | if (isinstance == -1) { |
| 5132 | return 1; |
| 5133 | } |
| 5134 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5135 | asdl_seq* elts; |
| 5136 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5137 | if (_PyObject_HasAttrId(obj, &PyId_elts)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5138 | int res; |
| 5139 | Py_ssize_t len; |
| 5140 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5141 | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5142 | if (tmp == NULL) goto failed; |
| 5143 | if (!PyList_Check(tmp)) { |
| 5144 | PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5145 | goto failed; |
| 5146 | } |
| 5147 | len = PyList_GET_SIZE(tmp); |
| 5148 | elts = asdl_seq_new(len, arena); |
| 5149 | if (elts == NULL) goto failed; |
| 5150 | for (i = 0; i < len; i++) { |
| 5151 | expr_ty value; |
| 5152 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5153 | if (res != 0) goto failed; |
| 5154 | asdl_seq_SET(elts, i, value); |
| 5155 | } |
| 5156 | Py_XDECREF(tmp); |
| 5157 | tmp = NULL; |
| 5158 | } else { |
| 5159 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 5160 | return 1; |
| 5161 | } |
| 5162 | *out = Set(elts, lineno, col_offset, arena); |
| 5163 | if (*out == NULL) goto failed; |
| 5164 | return 0; |
| 5165 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5166 | isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type); |
| 5167 | if (isinstance == -1) { |
| 5168 | return 1; |
| 5169 | } |
| 5170 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5171 | expr_ty elt; |
| 5172 | asdl_seq* generators; |
| 5173 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5174 | if (_PyObject_HasAttrId(obj, &PyId_elt)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5175 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5176 | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5177 | if (tmp == NULL) goto failed; |
| 5178 | res = obj2ast_expr(tmp, &elt, arena); |
| 5179 | if (res != 0) goto failed; |
| 5180 | Py_XDECREF(tmp); |
| 5181 | tmp = NULL; |
| 5182 | } else { |
| 5183 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 5184 | return 1; |
| 5185 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5186 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5187 | int res; |
| 5188 | Py_ssize_t len; |
| 5189 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5190 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5191 | if (tmp == NULL) goto failed; |
| 5192 | if (!PyList_Check(tmp)) { |
| 5193 | PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5194 | goto failed; |
| 5195 | } |
| 5196 | len = PyList_GET_SIZE(tmp); |
| 5197 | generators = asdl_seq_new(len, arena); |
| 5198 | if (generators == NULL) goto failed; |
| 5199 | for (i = 0; i < len; i++) { |
| 5200 | comprehension_ty value; |
| 5201 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5202 | if (res != 0) goto failed; |
| 5203 | asdl_seq_SET(generators, i, value); |
| 5204 | } |
| 5205 | Py_XDECREF(tmp); |
| 5206 | tmp = NULL; |
| 5207 | } else { |
| 5208 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 5209 | return 1; |
| 5210 | } |
| 5211 | *out = ListComp(elt, generators, lineno, col_offset, arena); |
| 5212 | if (*out == NULL) goto failed; |
| 5213 | return 0; |
| 5214 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5215 | isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type); |
| 5216 | if (isinstance == -1) { |
| 5217 | return 1; |
| 5218 | } |
| 5219 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5220 | expr_ty elt; |
| 5221 | asdl_seq* generators; |
| 5222 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5223 | if (_PyObject_HasAttrId(obj, &PyId_elt)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5224 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5225 | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5226 | if (tmp == NULL) goto failed; |
| 5227 | res = obj2ast_expr(tmp, &elt, arena); |
| 5228 | if (res != 0) goto failed; |
| 5229 | Py_XDECREF(tmp); |
| 5230 | tmp = NULL; |
| 5231 | } else { |
| 5232 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 5233 | return 1; |
| 5234 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5235 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5236 | int res; |
| 5237 | Py_ssize_t len; |
| 5238 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5239 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5240 | if (tmp == NULL) goto failed; |
| 5241 | if (!PyList_Check(tmp)) { |
| 5242 | PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5243 | goto failed; |
| 5244 | } |
| 5245 | len = PyList_GET_SIZE(tmp); |
| 5246 | generators = asdl_seq_new(len, arena); |
| 5247 | if (generators == NULL) goto failed; |
| 5248 | for (i = 0; i < len; i++) { |
| 5249 | comprehension_ty value; |
| 5250 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5251 | if (res != 0) goto failed; |
| 5252 | asdl_seq_SET(generators, i, value); |
| 5253 | } |
| 5254 | Py_XDECREF(tmp); |
| 5255 | tmp = NULL; |
| 5256 | } else { |
| 5257 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 5258 | return 1; |
| 5259 | } |
| 5260 | *out = SetComp(elt, generators, lineno, col_offset, arena); |
| 5261 | if (*out == NULL) goto failed; |
| 5262 | return 0; |
| 5263 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5264 | isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type); |
| 5265 | if (isinstance == -1) { |
| 5266 | return 1; |
| 5267 | } |
| 5268 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5269 | expr_ty key; |
| 5270 | expr_ty value; |
| 5271 | asdl_seq* generators; |
| 5272 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5273 | if (_PyObject_HasAttrId(obj, &PyId_key)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5274 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5275 | tmp = _PyObject_GetAttrId(obj, &PyId_key); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5276 | if (tmp == NULL) goto failed; |
| 5277 | res = obj2ast_expr(tmp, &key, arena); |
| 5278 | if (res != 0) goto failed; |
| 5279 | Py_XDECREF(tmp); |
| 5280 | tmp = NULL; |
| 5281 | } else { |
| 5282 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 5283 | return 1; |
| 5284 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5285 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5286 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5287 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5288 | if (tmp == NULL) goto failed; |
| 5289 | res = obj2ast_expr(tmp, &value, arena); |
| 5290 | if (res != 0) goto failed; |
| 5291 | Py_XDECREF(tmp); |
| 5292 | tmp = NULL; |
| 5293 | } else { |
| 5294 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 5295 | return 1; |
| 5296 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5297 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5298 | int res; |
| 5299 | Py_ssize_t len; |
| 5300 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5301 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5302 | if (tmp == NULL) goto failed; |
| 5303 | if (!PyList_Check(tmp)) { |
| 5304 | PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5305 | goto failed; |
| 5306 | } |
| 5307 | len = PyList_GET_SIZE(tmp); |
| 5308 | generators = asdl_seq_new(len, arena); |
| 5309 | if (generators == NULL) goto failed; |
| 5310 | for (i = 0; i < len; i++) { |
| 5311 | comprehension_ty value; |
| 5312 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5313 | if (res != 0) goto failed; |
| 5314 | asdl_seq_SET(generators, i, value); |
| 5315 | } |
| 5316 | Py_XDECREF(tmp); |
| 5317 | tmp = NULL; |
| 5318 | } else { |
| 5319 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 5320 | return 1; |
| 5321 | } |
| 5322 | *out = DictComp(key, value, generators, lineno, col_offset, |
| 5323 | arena); |
| 5324 | if (*out == NULL) goto failed; |
| 5325 | return 0; |
| 5326 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5327 | isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type); |
| 5328 | if (isinstance == -1) { |
| 5329 | return 1; |
| 5330 | } |
| 5331 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5332 | expr_ty elt; |
| 5333 | asdl_seq* generators; |
| 5334 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5335 | if (_PyObject_HasAttrId(obj, &PyId_elt)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5336 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5337 | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5338 | if (tmp == NULL) goto failed; |
| 5339 | res = obj2ast_expr(tmp, &elt, arena); |
| 5340 | if (res != 0) goto failed; |
| 5341 | Py_XDECREF(tmp); |
| 5342 | tmp = NULL; |
| 5343 | } else { |
| 5344 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 5345 | return 1; |
| 5346 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5347 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5348 | int res; |
| 5349 | Py_ssize_t len; |
| 5350 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5351 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5352 | if (tmp == NULL) goto failed; |
| 5353 | if (!PyList_Check(tmp)) { |
| 5354 | PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5355 | goto failed; |
| 5356 | } |
| 5357 | len = PyList_GET_SIZE(tmp); |
| 5358 | generators = asdl_seq_new(len, arena); |
| 5359 | if (generators == NULL) goto failed; |
| 5360 | for (i = 0; i < len; i++) { |
| 5361 | comprehension_ty value; |
| 5362 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5363 | if (res != 0) goto failed; |
| 5364 | asdl_seq_SET(generators, i, value); |
| 5365 | } |
| 5366 | Py_XDECREF(tmp); |
| 5367 | tmp = NULL; |
| 5368 | } else { |
| 5369 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 5370 | return 1; |
| 5371 | } |
| 5372 | *out = GeneratorExp(elt, generators, lineno, col_offset, arena); |
| 5373 | if (*out == NULL) goto failed; |
| 5374 | return 0; |
| 5375 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5376 | isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); |
| 5377 | if (isinstance == -1) { |
| 5378 | return 1; |
| 5379 | } |
| 5380 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5381 | expr_ty value; |
| 5382 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5383 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5384 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5385 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5386 | if (tmp == NULL) goto failed; |
| 5387 | res = obj2ast_expr(tmp, &value, arena); |
| 5388 | if (res != 0) goto failed; |
| 5389 | Py_XDECREF(tmp); |
| 5390 | tmp = NULL; |
| 5391 | } else { |
| 5392 | value = NULL; |
| 5393 | } |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 5394 | *out = Yield(value, lineno, col_offset, arena); |
| 5395 | if (*out == NULL) goto failed; |
| 5396 | return 0; |
| 5397 | } |
| 5398 | isinstance = PyObject_IsInstance(obj, (PyObject*)YieldFrom_type); |
| 5399 | if (isinstance == -1) { |
| 5400 | return 1; |
| 5401 | } |
| 5402 | if (isinstance) { |
| 5403 | expr_ty value; |
| 5404 | |
| 5405 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 5406 | int res; |
| 5407 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 5408 | if (tmp == NULL) goto failed; |
| 5409 | res = obj2ast_expr(tmp, &value, arena); |
| 5410 | if (res != 0) goto failed; |
| 5411 | Py_XDECREF(tmp); |
| 5412 | tmp = NULL; |
| 5413 | } else { |
| 5414 | value = NULL; |
| 5415 | } |
| 5416 | *out = YieldFrom(value, lineno, col_offset, arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5417 | if (*out == NULL) goto failed; |
| 5418 | return 0; |
| 5419 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5420 | isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); |
| 5421 | if (isinstance == -1) { |
| 5422 | return 1; |
| 5423 | } |
| 5424 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5425 | expr_ty left; |
| 5426 | asdl_int_seq* ops; |
| 5427 | asdl_seq* comparators; |
| 5428 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5429 | if (_PyObject_HasAttrId(obj, &PyId_left)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5430 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5431 | tmp = _PyObject_GetAttrId(obj, &PyId_left); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5432 | if (tmp == NULL) goto failed; |
| 5433 | res = obj2ast_expr(tmp, &left, arena); |
| 5434 | if (res != 0) goto failed; |
| 5435 | Py_XDECREF(tmp); |
| 5436 | tmp = NULL; |
| 5437 | } else { |
| 5438 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 5439 | return 1; |
| 5440 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5441 | if (_PyObject_HasAttrId(obj, &PyId_ops)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5442 | int res; |
| 5443 | Py_ssize_t len; |
| 5444 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5445 | tmp = _PyObject_GetAttrId(obj, &PyId_ops); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5446 | if (tmp == NULL) goto failed; |
| 5447 | if (!PyList_Check(tmp)) { |
| 5448 | PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5449 | goto failed; |
| 5450 | } |
| 5451 | len = PyList_GET_SIZE(tmp); |
| 5452 | ops = asdl_int_seq_new(len, arena); |
| 5453 | if (ops == NULL) goto failed; |
| 5454 | for (i = 0; i < len; i++) { |
| 5455 | cmpop_ty value; |
| 5456 | res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5457 | if (res != 0) goto failed; |
| 5458 | asdl_seq_SET(ops, i, value); |
| 5459 | } |
| 5460 | Py_XDECREF(tmp); |
| 5461 | tmp = NULL; |
| 5462 | } else { |
| 5463 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 5464 | return 1; |
| 5465 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5466 | if (_PyObject_HasAttrId(obj, &PyId_comparators)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5467 | int res; |
| 5468 | Py_ssize_t len; |
| 5469 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5470 | tmp = _PyObject_GetAttrId(obj, &PyId_comparators); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5471 | if (tmp == NULL) goto failed; |
| 5472 | if (!PyList_Check(tmp)) { |
| 5473 | PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5474 | goto failed; |
| 5475 | } |
| 5476 | len = PyList_GET_SIZE(tmp); |
| 5477 | comparators = asdl_seq_new(len, arena); |
| 5478 | if (comparators == NULL) goto failed; |
| 5479 | for (i = 0; i < len; i++) { |
| 5480 | expr_ty value; |
| 5481 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5482 | if (res != 0) goto failed; |
| 5483 | asdl_seq_SET(comparators, i, value); |
| 5484 | } |
| 5485 | Py_XDECREF(tmp); |
| 5486 | tmp = NULL; |
| 5487 | } else { |
| 5488 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 5489 | return 1; |
| 5490 | } |
| 5491 | *out = Compare(left, ops, comparators, lineno, col_offset, |
| 5492 | arena); |
| 5493 | if (*out == NULL) goto failed; |
| 5494 | return 0; |
| 5495 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5496 | isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type); |
| 5497 | if (isinstance == -1) { |
| 5498 | return 1; |
| 5499 | } |
| 5500 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5501 | expr_ty func; |
| 5502 | asdl_seq* args; |
| 5503 | asdl_seq* keywords; |
| 5504 | expr_ty starargs; |
| 5505 | expr_ty kwargs; |
| 5506 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5507 | if (_PyObject_HasAttrId(obj, &PyId_func)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5508 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5509 | tmp = _PyObject_GetAttrId(obj, &PyId_func); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5510 | if (tmp == NULL) goto failed; |
| 5511 | res = obj2ast_expr(tmp, &func, arena); |
| 5512 | if (res != 0) goto failed; |
| 5513 | Py_XDECREF(tmp); |
| 5514 | tmp = NULL; |
| 5515 | } else { |
| 5516 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 5517 | return 1; |
| 5518 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5519 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5520 | int res; |
| 5521 | Py_ssize_t len; |
| 5522 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5523 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5524 | if (tmp == NULL) goto failed; |
| 5525 | if (!PyList_Check(tmp)) { |
| 5526 | PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5527 | goto failed; |
| 5528 | } |
| 5529 | len = PyList_GET_SIZE(tmp); |
| 5530 | args = asdl_seq_new(len, arena); |
| 5531 | if (args == NULL) goto failed; |
| 5532 | for (i = 0; i < len; i++) { |
| 5533 | expr_ty value; |
| 5534 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5535 | if (res != 0) goto failed; |
| 5536 | asdl_seq_SET(args, i, value); |
| 5537 | } |
| 5538 | Py_XDECREF(tmp); |
| 5539 | tmp = NULL; |
| 5540 | } else { |
| 5541 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 5542 | return 1; |
| 5543 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5544 | if (_PyObject_HasAttrId(obj, &PyId_keywords)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5545 | int res; |
| 5546 | Py_ssize_t len; |
| 5547 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5548 | tmp = _PyObject_GetAttrId(obj, &PyId_keywords); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5549 | if (tmp == NULL) goto failed; |
| 5550 | if (!PyList_Check(tmp)) { |
| 5551 | PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5552 | goto failed; |
| 5553 | } |
| 5554 | len = PyList_GET_SIZE(tmp); |
| 5555 | keywords = asdl_seq_new(len, arena); |
| 5556 | if (keywords == NULL) goto failed; |
| 5557 | for (i = 0; i < len; i++) { |
| 5558 | keyword_ty value; |
| 5559 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5560 | if (res != 0) goto failed; |
| 5561 | asdl_seq_SET(keywords, i, value); |
| 5562 | } |
| 5563 | Py_XDECREF(tmp); |
| 5564 | tmp = NULL; |
| 5565 | } else { |
| 5566 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 5567 | return 1; |
| 5568 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5569 | if (_PyObject_HasAttrId(obj, &PyId_starargs)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5570 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5571 | tmp = _PyObject_GetAttrId(obj, &PyId_starargs); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5572 | if (tmp == NULL) goto failed; |
| 5573 | res = obj2ast_expr(tmp, &starargs, arena); |
| 5574 | if (res != 0) goto failed; |
| 5575 | Py_XDECREF(tmp); |
| 5576 | tmp = NULL; |
| 5577 | } else { |
| 5578 | starargs = NULL; |
| 5579 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5580 | if (_PyObject_HasAttrId(obj, &PyId_kwargs)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5581 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5582 | tmp = _PyObject_GetAttrId(obj, &PyId_kwargs); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5583 | if (tmp == NULL) goto failed; |
| 5584 | res = obj2ast_expr(tmp, &kwargs, arena); |
| 5585 | if (res != 0) goto failed; |
| 5586 | Py_XDECREF(tmp); |
| 5587 | tmp = NULL; |
| 5588 | } else { |
| 5589 | kwargs = NULL; |
| 5590 | } |
| 5591 | *out = Call(func, args, keywords, starargs, kwargs, lineno, |
| 5592 | col_offset, arena); |
| 5593 | if (*out == NULL) goto failed; |
| 5594 | return 0; |
| 5595 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5596 | isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type); |
| 5597 | if (isinstance == -1) { |
| 5598 | return 1; |
| 5599 | } |
| 5600 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5601 | object n; |
| 5602 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5603 | if (_PyObject_HasAttrId(obj, &PyId_n)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5604 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5605 | tmp = _PyObject_GetAttrId(obj, &PyId_n); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5606 | if (tmp == NULL) goto failed; |
| 5607 | res = obj2ast_object(tmp, &n, arena); |
| 5608 | if (res != 0) goto failed; |
| 5609 | Py_XDECREF(tmp); |
| 5610 | tmp = NULL; |
| 5611 | } else { |
| 5612 | PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num"); |
| 5613 | return 1; |
| 5614 | } |
| 5615 | *out = Num(n, lineno, col_offset, arena); |
| 5616 | if (*out == NULL) goto failed; |
| 5617 | return 0; |
| 5618 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5619 | isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type); |
| 5620 | if (isinstance == -1) { |
| 5621 | return 1; |
| 5622 | } |
| 5623 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5624 | string s; |
| 5625 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5626 | if (_PyObject_HasAttrId(obj, &PyId_s)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5627 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5628 | tmp = _PyObject_GetAttrId(obj, &PyId_s); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5629 | if (tmp == NULL) goto failed; |
| 5630 | res = obj2ast_string(tmp, &s, arena); |
| 5631 | if (res != 0) goto failed; |
| 5632 | Py_XDECREF(tmp); |
| 5633 | tmp = NULL; |
| 5634 | } else { |
| 5635 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str"); |
| 5636 | return 1; |
| 5637 | } |
| 5638 | *out = Str(s, lineno, col_offset, arena); |
| 5639 | if (*out == NULL) goto failed; |
| 5640 | return 0; |
| 5641 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5642 | isinstance = PyObject_IsInstance(obj, (PyObject*)Bytes_type); |
| 5643 | if (isinstance == -1) { |
| 5644 | return 1; |
| 5645 | } |
| 5646 | if (isinstance) { |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 5647 | bytes s; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5648 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5649 | if (_PyObject_HasAttrId(obj, &PyId_s)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5650 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5651 | tmp = _PyObject_GetAttrId(obj, &PyId_s); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5652 | if (tmp == NULL) goto failed; |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 5653 | res = obj2ast_bytes(tmp, &s, arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5654 | if (res != 0) goto failed; |
| 5655 | Py_XDECREF(tmp); |
| 5656 | tmp = NULL; |
| 5657 | } else { |
| 5658 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Bytes"); |
| 5659 | return 1; |
| 5660 | } |
| 5661 | *out = Bytes(s, lineno, col_offset, arena); |
| 5662 | if (*out == NULL) goto failed; |
| 5663 | return 0; |
| 5664 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5665 | isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type); |
| 5666 | if (isinstance == -1) { |
| 5667 | return 1; |
| 5668 | } |
| 5669 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5670 | |
| 5671 | *out = Ellipsis(lineno, col_offset, arena); |
| 5672 | if (*out == NULL) goto failed; |
| 5673 | return 0; |
| 5674 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5675 | isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type); |
| 5676 | if (isinstance == -1) { |
| 5677 | return 1; |
| 5678 | } |
| 5679 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5680 | expr_ty value; |
| 5681 | identifier attr; |
| 5682 | expr_context_ty ctx; |
| 5683 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5684 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5685 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5686 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5687 | if (tmp == NULL) goto failed; |
| 5688 | res = obj2ast_expr(tmp, &value, arena); |
| 5689 | if (res != 0) goto failed; |
| 5690 | Py_XDECREF(tmp); |
| 5691 | tmp = NULL; |
| 5692 | } else { |
| 5693 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 5694 | return 1; |
| 5695 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5696 | if (_PyObject_HasAttrId(obj, &PyId_attr)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5697 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5698 | tmp = _PyObject_GetAttrId(obj, &PyId_attr); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5699 | if (tmp == NULL) goto failed; |
| 5700 | res = obj2ast_identifier(tmp, &attr, arena); |
| 5701 | if (res != 0) goto failed; |
| 5702 | Py_XDECREF(tmp); |
| 5703 | tmp = NULL; |
| 5704 | } else { |
| 5705 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 5706 | return 1; |
| 5707 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5708 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5709 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5710 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5711 | if (tmp == NULL) goto failed; |
| 5712 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5713 | if (res != 0) goto failed; |
| 5714 | Py_XDECREF(tmp); |
| 5715 | tmp = NULL; |
| 5716 | } else { |
| 5717 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 5718 | return 1; |
| 5719 | } |
| 5720 | *out = Attribute(value, attr, ctx, lineno, col_offset, arena); |
| 5721 | if (*out == NULL) goto failed; |
| 5722 | return 0; |
| 5723 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5724 | isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type); |
| 5725 | if (isinstance == -1) { |
| 5726 | return 1; |
| 5727 | } |
| 5728 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5729 | expr_ty value; |
| 5730 | slice_ty slice; |
| 5731 | expr_context_ty ctx; |
| 5732 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5733 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5734 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5735 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5736 | if (tmp == NULL) goto failed; |
| 5737 | res = obj2ast_expr(tmp, &value, arena); |
| 5738 | if (res != 0) goto failed; |
| 5739 | Py_XDECREF(tmp); |
| 5740 | tmp = NULL; |
| 5741 | } else { |
| 5742 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 5743 | return 1; |
| 5744 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5745 | if (_PyObject_HasAttrId(obj, &PyId_slice)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5746 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5747 | tmp = _PyObject_GetAttrId(obj, &PyId_slice); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5748 | if (tmp == NULL) goto failed; |
| 5749 | res = obj2ast_slice(tmp, &slice, arena); |
| 5750 | if (res != 0) goto failed; |
| 5751 | Py_XDECREF(tmp); |
| 5752 | tmp = NULL; |
| 5753 | } else { |
| 5754 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 5755 | return 1; |
| 5756 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5757 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5758 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5759 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5760 | if (tmp == NULL) goto failed; |
| 5761 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5762 | if (res != 0) goto failed; |
| 5763 | Py_XDECREF(tmp); |
| 5764 | tmp = NULL; |
| 5765 | } else { |
| 5766 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 5767 | return 1; |
| 5768 | } |
| 5769 | *out = Subscript(value, slice, ctx, lineno, col_offset, arena); |
| 5770 | if (*out == NULL) goto failed; |
| 5771 | return 0; |
| 5772 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5773 | isinstance = PyObject_IsInstance(obj, (PyObject*)Starred_type); |
| 5774 | if (isinstance == -1) { |
| 5775 | return 1; |
| 5776 | } |
| 5777 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5778 | expr_ty value; |
| 5779 | expr_context_ty ctx; |
| 5780 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5781 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5782 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5783 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5784 | if (tmp == NULL) goto failed; |
| 5785 | res = obj2ast_expr(tmp, &value, arena); |
| 5786 | if (res != 0) goto failed; |
| 5787 | Py_XDECREF(tmp); |
| 5788 | tmp = NULL; |
| 5789 | } else { |
| 5790 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 5791 | return 1; |
| 5792 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5793 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5794 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5795 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5796 | if (tmp == NULL) goto failed; |
| 5797 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5798 | if (res != 0) goto failed; |
| 5799 | Py_XDECREF(tmp); |
| 5800 | tmp = NULL; |
| 5801 | } else { |
| 5802 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 5803 | return 1; |
| 5804 | } |
| 5805 | *out = Starred(value, ctx, lineno, col_offset, arena); |
| 5806 | if (*out == NULL) goto failed; |
| 5807 | return 0; |
| 5808 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5809 | isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type); |
| 5810 | if (isinstance == -1) { |
| 5811 | return 1; |
| 5812 | } |
| 5813 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5814 | identifier id; |
| 5815 | expr_context_ty ctx; |
| 5816 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5817 | if (_PyObject_HasAttrId(obj, &PyId_id)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5818 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5819 | tmp = _PyObject_GetAttrId(obj, &PyId_id); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5820 | if (tmp == NULL) goto failed; |
| 5821 | res = obj2ast_identifier(tmp, &id, arena); |
| 5822 | if (res != 0) goto failed; |
| 5823 | Py_XDECREF(tmp); |
| 5824 | tmp = NULL; |
| 5825 | } else { |
| 5826 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 5827 | return 1; |
| 5828 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5829 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5830 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5831 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5832 | if (tmp == NULL) goto failed; |
| 5833 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5834 | if (res != 0) goto failed; |
| 5835 | Py_XDECREF(tmp); |
| 5836 | tmp = NULL; |
| 5837 | } else { |
| 5838 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 5839 | return 1; |
| 5840 | } |
| 5841 | *out = Name(id, ctx, lineno, col_offset, arena); |
| 5842 | if (*out == NULL) goto failed; |
| 5843 | return 0; |
| 5844 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5845 | isinstance = PyObject_IsInstance(obj, (PyObject*)List_type); |
| 5846 | if (isinstance == -1) { |
| 5847 | return 1; |
| 5848 | } |
| 5849 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5850 | asdl_seq* elts; |
| 5851 | expr_context_ty ctx; |
| 5852 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5853 | if (_PyObject_HasAttrId(obj, &PyId_elts)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5854 | int res; |
| 5855 | Py_ssize_t len; |
| 5856 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5857 | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5858 | if (tmp == NULL) goto failed; |
| 5859 | if (!PyList_Check(tmp)) { |
| 5860 | PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5861 | goto failed; |
| 5862 | } |
| 5863 | len = PyList_GET_SIZE(tmp); |
| 5864 | elts = asdl_seq_new(len, arena); |
| 5865 | if (elts == NULL) goto failed; |
| 5866 | for (i = 0; i < len; i++) { |
| 5867 | expr_ty value; |
| 5868 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5869 | if (res != 0) goto failed; |
| 5870 | asdl_seq_SET(elts, i, value); |
| 5871 | } |
| 5872 | Py_XDECREF(tmp); |
| 5873 | tmp = NULL; |
| 5874 | } else { |
| 5875 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 5876 | return 1; |
| 5877 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5878 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5879 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5880 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5881 | if (tmp == NULL) goto failed; |
| 5882 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5883 | if (res != 0) goto failed; |
| 5884 | Py_XDECREF(tmp); |
| 5885 | tmp = NULL; |
| 5886 | } else { |
| 5887 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 5888 | return 1; |
| 5889 | } |
| 5890 | *out = List(elts, ctx, lineno, col_offset, arena); |
| 5891 | if (*out == NULL) goto failed; |
| 5892 | return 0; |
| 5893 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5894 | isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type); |
| 5895 | if (isinstance == -1) { |
| 5896 | return 1; |
| 5897 | } |
| 5898 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5899 | asdl_seq* elts; |
| 5900 | expr_context_ty ctx; |
| 5901 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5902 | if (_PyObject_HasAttrId(obj, &PyId_elts)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5903 | int res; |
| 5904 | Py_ssize_t len; |
| 5905 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5906 | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5907 | if (tmp == NULL) goto failed; |
| 5908 | if (!PyList_Check(tmp)) { |
| 5909 | PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5910 | goto failed; |
| 5911 | } |
| 5912 | len = PyList_GET_SIZE(tmp); |
| 5913 | elts = asdl_seq_new(len, arena); |
| 5914 | if (elts == NULL) goto failed; |
| 5915 | for (i = 0; i < len; i++) { |
| 5916 | expr_ty value; |
| 5917 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5918 | if (res != 0) goto failed; |
| 5919 | asdl_seq_SET(elts, i, value); |
| 5920 | } |
| 5921 | Py_XDECREF(tmp); |
| 5922 | tmp = NULL; |
| 5923 | } else { |
| 5924 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 5925 | return 1; |
| 5926 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5927 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5928 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5929 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5930 | if (tmp == NULL) goto failed; |
| 5931 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5932 | if (res != 0) goto failed; |
| 5933 | Py_XDECREF(tmp); |
| 5934 | tmp = NULL; |
| 5935 | } else { |
| 5936 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 5937 | return 1; |
| 5938 | } |
| 5939 | *out = Tuple(elts, ctx, lineno, col_offset, arena); |
| 5940 | if (*out == NULL) goto failed; |
| 5941 | return 0; |
| 5942 | } |
| 5943 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 5944 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
| 5945 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 5946 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5947 | return 1; |
| 5948 | } |
| 5949 | |
| 5950 | int |
| 5951 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 5952 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5953 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5954 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5955 | isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); |
| 5956 | if (isinstance == -1) { |
| 5957 | return 1; |
| 5958 | } |
| 5959 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5960 | *out = Load; |
| 5961 | return 0; |
| 5962 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5963 | isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type); |
| 5964 | if (isinstance == -1) { |
| 5965 | return 1; |
| 5966 | } |
| 5967 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5968 | *out = Store; |
| 5969 | return 0; |
| 5970 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5971 | isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type); |
| 5972 | if (isinstance == -1) { |
| 5973 | return 1; |
| 5974 | } |
| 5975 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5976 | *out = Del; |
| 5977 | return 0; |
| 5978 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5979 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type); |
| 5980 | if (isinstance == -1) { |
| 5981 | return 1; |
| 5982 | } |
| 5983 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5984 | *out = AugLoad; |
| 5985 | return 0; |
| 5986 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5987 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type); |
| 5988 | if (isinstance == -1) { |
| 5989 | return 1; |
| 5990 | } |
| 5991 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5992 | *out = AugStore; |
| 5993 | return 0; |
| 5994 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5995 | isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type); |
| 5996 | if (isinstance == -1) { |
| 5997 | return 1; |
| 5998 | } |
| 5999 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6000 | *out = Param; |
| 6001 | return 0; |
| 6002 | } |
| 6003 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6004 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6005 | return 1; |
| 6006 | } |
| 6007 | |
| 6008 | int |
| 6009 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
| 6010 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6011 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6012 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 6013 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6014 | |
| 6015 | if (obj == Py_None) { |
| 6016 | *out = NULL; |
| 6017 | return 0; |
| 6018 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6019 | isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type); |
| 6020 | if (isinstance == -1) { |
| 6021 | return 1; |
| 6022 | } |
| 6023 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6024 | expr_ty lower; |
| 6025 | expr_ty upper; |
| 6026 | expr_ty step; |
| 6027 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6028 | if (_PyObject_HasAttrId(obj, &PyId_lower)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6029 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6030 | tmp = _PyObject_GetAttrId(obj, &PyId_lower); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6031 | if (tmp == NULL) goto failed; |
| 6032 | res = obj2ast_expr(tmp, &lower, arena); |
| 6033 | if (res != 0) goto failed; |
| 6034 | Py_XDECREF(tmp); |
| 6035 | tmp = NULL; |
| 6036 | } else { |
| 6037 | lower = NULL; |
| 6038 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6039 | if (_PyObject_HasAttrId(obj, &PyId_upper)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6040 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6041 | tmp = _PyObject_GetAttrId(obj, &PyId_upper); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6042 | if (tmp == NULL) goto failed; |
| 6043 | res = obj2ast_expr(tmp, &upper, arena); |
| 6044 | if (res != 0) goto failed; |
| 6045 | Py_XDECREF(tmp); |
| 6046 | tmp = NULL; |
| 6047 | } else { |
| 6048 | upper = NULL; |
| 6049 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6050 | if (_PyObject_HasAttrId(obj, &PyId_step)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6051 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6052 | tmp = _PyObject_GetAttrId(obj, &PyId_step); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6053 | if (tmp == NULL) goto failed; |
| 6054 | res = obj2ast_expr(tmp, &step, arena); |
| 6055 | if (res != 0) goto failed; |
| 6056 | Py_XDECREF(tmp); |
| 6057 | tmp = NULL; |
| 6058 | } else { |
| 6059 | step = NULL; |
| 6060 | } |
| 6061 | *out = Slice(lower, upper, step, arena); |
| 6062 | if (*out == NULL) goto failed; |
| 6063 | return 0; |
| 6064 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6065 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type); |
| 6066 | if (isinstance == -1) { |
| 6067 | return 1; |
| 6068 | } |
| 6069 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6070 | asdl_seq* dims; |
| 6071 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6072 | if (_PyObject_HasAttrId(obj, &PyId_dims)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6073 | int res; |
| 6074 | Py_ssize_t len; |
| 6075 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6076 | tmp = _PyObject_GetAttrId(obj, &PyId_dims); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6077 | if (tmp == NULL) goto failed; |
| 6078 | if (!PyList_Check(tmp)) { |
| 6079 | PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6080 | goto failed; |
| 6081 | } |
| 6082 | len = PyList_GET_SIZE(tmp); |
| 6083 | dims = asdl_seq_new(len, arena); |
| 6084 | if (dims == NULL) goto failed; |
| 6085 | for (i = 0; i < len; i++) { |
| 6086 | slice_ty value; |
| 6087 | res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6088 | if (res != 0) goto failed; |
| 6089 | asdl_seq_SET(dims, i, value); |
| 6090 | } |
| 6091 | Py_XDECREF(tmp); |
| 6092 | tmp = NULL; |
| 6093 | } else { |
| 6094 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
| 6095 | return 1; |
| 6096 | } |
| 6097 | *out = ExtSlice(dims, arena); |
| 6098 | if (*out == NULL) goto failed; |
| 6099 | return 0; |
| 6100 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6101 | isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type); |
| 6102 | if (isinstance == -1) { |
| 6103 | return 1; |
| 6104 | } |
| 6105 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6106 | expr_ty value; |
| 6107 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6108 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6109 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6110 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6111 | if (tmp == NULL) goto failed; |
| 6112 | res = obj2ast_expr(tmp, &value, arena); |
| 6113 | if (res != 0) goto failed; |
| 6114 | Py_XDECREF(tmp); |
| 6115 | tmp = NULL; |
| 6116 | } else { |
| 6117 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
| 6118 | return 1; |
| 6119 | } |
| 6120 | *out = Index(value, arena); |
| 6121 | if (*out == NULL) goto failed; |
| 6122 | return 0; |
| 6123 | } |
| 6124 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6125 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj); |
| 6126 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 6127 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6128 | return 1; |
| 6129 | } |
| 6130 | |
| 6131 | int |
| 6132 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 6133 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6134 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6135 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6136 | isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); |
| 6137 | if (isinstance == -1) { |
| 6138 | return 1; |
| 6139 | } |
| 6140 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6141 | *out = And; |
| 6142 | return 0; |
| 6143 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6144 | isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type); |
| 6145 | if (isinstance == -1) { |
| 6146 | return 1; |
| 6147 | } |
| 6148 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6149 | *out = Or; |
| 6150 | return 0; |
| 6151 | } |
| 6152 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6153 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6154 | return 1; |
| 6155 | } |
| 6156 | |
| 6157 | int |
| 6158 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 6159 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6160 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6161 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6162 | isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); |
| 6163 | if (isinstance == -1) { |
| 6164 | return 1; |
| 6165 | } |
| 6166 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6167 | *out = Add; |
| 6168 | return 0; |
| 6169 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6170 | isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type); |
| 6171 | if (isinstance == -1) { |
| 6172 | return 1; |
| 6173 | } |
| 6174 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6175 | *out = Sub; |
| 6176 | return 0; |
| 6177 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6178 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type); |
| 6179 | if (isinstance == -1) { |
| 6180 | return 1; |
| 6181 | } |
| 6182 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6183 | *out = Mult; |
| 6184 | return 0; |
| 6185 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6186 | isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type); |
| 6187 | if (isinstance == -1) { |
| 6188 | return 1; |
| 6189 | } |
| 6190 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6191 | *out = Div; |
| 6192 | return 0; |
| 6193 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6194 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type); |
| 6195 | if (isinstance == -1) { |
| 6196 | return 1; |
| 6197 | } |
| 6198 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6199 | *out = Mod; |
| 6200 | return 0; |
| 6201 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6202 | isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type); |
| 6203 | if (isinstance == -1) { |
| 6204 | return 1; |
| 6205 | } |
| 6206 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6207 | *out = Pow; |
| 6208 | return 0; |
| 6209 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6210 | isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type); |
| 6211 | if (isinstance == -1) { |
| 6212 | return 1; |
| 6213 | } |
| 6214 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6215 | *out = LShift; |
| 6216 | return 0; |
| 6217 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6218 | isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type); |
| 6219 | if (isinstance == -1) { |
| 6220 | return 1; |
| 6221 | } |
| 6222 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6223 | *out = RShift; |
| 6224 | return 0; |
| 6225 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6226 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type); |
| 6227 | if (isinstance == -1) { |
| 6228 | return 1; |
| 6229 | } |
| 6230 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6231 | *out = BitOr; |
| 6232 | return 0; |
| 6233 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6234 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type); |
| 6235 | if (isinstance == -1) { |
| 6236 | return 1; |
| 6237 | } |
| 6238 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6239 | *out = BitXor; |
| 6240 | return 0; |
| 6241 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6242 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type); |
| 6243 | if (isinstance == -1) { |
| 6244 | return 1; |
| 6245 | } |
| 6246 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6247 | *out = BitAnd; |
| 6248 | return 0; |
| 6249 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6250 | isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type); |
| 6251 | if (isinstance == -1) { |
| 6252 | return 1; |
| 6253 | } |
| 6254 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6255 | *out = FloorDiv; |
| 6256 | return 0; |
| 6257 | } |
| 6258 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6259 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6260 | return 1; |
| 6261 | } |
| 6262 | |
| 6263 | int |
| 6264 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 6265 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6266 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6267 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6268 | isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); |
| 6269 | if (isinstance == -1) { |
| 6270 | return 1; |
| 6271 | } |
| 6272 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6273 | *out = Invert; |
| 6274 | return 0; |
| 6275 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6276 | isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type); |
| 6277 | if (isinstance == -1) { |
| 6278 | return 1; |
| 6279 | } |
| 6280 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6281 | *out = Not; |
| 6282 | return 0; |
| 6283 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6284 | isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type); |
| 6285 | if (isinstance == -1) { |
| 6286 | return 1; |
| 6287 | } |
| 6288 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6289 | *out = UAdd; |
| 6290 | return 0; |
| 6291 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6292 | isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type); |
| 6293 | if (isinstance == -1) { |
| 6294 | return 1; |
| 6295 | } |
| 6296 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6297 | *out = USub; |
| 6298 | return 0; |
| 6299 | } |
| 6300 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6301 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6302 | return 1; |
| 6303 | } |
| 6304 | |
| 6305 | int |
| 6306 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 6307 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6308 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6309 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6310 | isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); |
| 6311 | if (isinstance == -1) { |
| 6312 | return 1; |
| 6313 | } |
| 6314 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6315 | *out = Eq; |
| 6316 | return 0; |
| 6317 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6318 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type); |
| 6319 | if (isinstance == -1) { |
| 6320 | return 1; |
| 6321 | } |
| 6322 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6323 | *out = NotEq; |
| 6324 | return 0; |
| 6325 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6326 | isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type); |
| 6327 | if (isinstance == -1) { |
| 6328 | return 1; |
| 6329 | } |
| 6330 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6331 | *out = Lt; |
| 6332 | return 0; |
| 6333 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6334 | isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type); |
| 6335 | if (isinstance == -1) { |
| 6336 | return 1; |
| 6337 | } |
| 6338 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6339 | *out = LtE; |
| 6340 | return 0; |
| 6341 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6342 | isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type); |
| 6343 | if (isinstance == -1) { |
| 6344 | return 1; |
| 6345 | } |
| 6346 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6347 | *out = Gt; |
| 6348 | return 0; |
| 6349 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6350 | isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type); |
| 6351 | if (isinstance == -1) { |
| 6352 | return 1; |
| 6353 | } |
| 6354 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6355 | *out = GtE; |
| 6356 | return 0; |
| 6357 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6358 | isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type); |
| 6359 | if (isinstance == -1) { |
| 6360 | return 1; |
| 6361 | } |
| 6362 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6363 | *out = Is; |
| 6364 | return 0; |
| 6365 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6366 | isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type); |
| 6367 | if (isinstance == -1) { |
| 6368 | return 1; |
| 6369 | } |
| 6370 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6371 | *out = IsNot; |
| 6372 | return 0; |
| 6373 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6374 | isinstance = PyObject_IsInstance(obj, (PyObject *)In_type); |
| 6375 | if (isinstance == -1) { |
| 6376 | return 1; |
| 6377 | } |
| 6378 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6379 | *out = In; |
| 6380 | return 0; |
| 6381 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6382 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type); |
| 6383 | if (isinstance == -1) { |
| 6384 | return 1; |
| 6385 | } |
| 6386 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6387 | *out = NotIn; |
| 6388 | return 0; |
| 6389 | } |
| 6390 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6391 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6392 | return 1; |
| 6393 | } |
| 6394 | |
| 6395 | int |
| 6396 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 6397 | { |
| 6398 | PyObject* tmp = NULL; |
| 6399 | expr_ty target; |
| 6400 | expr_ty iter; |
| 6401 | asdl_seq* ifs; |
| 6402 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6403 | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6404 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6405 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6406 | if (tmp == NULL) goto failed; |
| 6407 | res = obj2ast_expr(tmp, &target, arena); |
| 6408 | if (res != 0) goto failed; |
| 6409 | Py_XDECREF(tmp); |
| 6410 | tmp = NULL; |
| 6411 | } else { |
| 6412 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 6413 | return 1; |
| 6414 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6415 | if (_PyObject_HasAttrId(obj, &PyId_iter)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6416 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6417 | tmp = _PyObject_GetAttrId(obj, &PyId_iter); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6418 | if (tmp == NULL) goto failed; |
| 6419 | res = obj2ast_expr(tmp, &iter, arena); |
| 6420 | if (res != 0) goto failed; |
| 6421 | Py_XDECREF(tmp); |
| 6422 | tmp = NULL; |
| 6423 | } else { |
| 6424 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 6425 | return 1; |
| 6426 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6427 | if (_PyObject_HasAttrId(obj, &PyId_ifs)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6428 | int res; |
| 6429 | Py_ssize_t len; |
| 6430 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6431 | tmp = _PyObject_GetAttrId(obj, &PyId_ifs); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6432 | if (tmp == NULL) goto failed; |
| 6433 | if (!PyList_Check(tmp)) { |
| 6434 | PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6435 | goto failed; |
| 6436 | } |
| 6437 | len = PyList_GET_SIZE(tmp); |
| 6438 | ifs = asdl_seq_new(len, arena); |
| 6439 | if (ifs == NULL) goto failed; |
| 6440 | for (i = 0; i < len; i++) { |
| 6441 | expr_ty value; |
| 6442 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6443 | if (res != 0) goto failed; |
| 6444 | asdl_seq_SET(ifs, i, value); |
| 6445 | } |
| 6446 | Py_XDECREF(tmp); |
| 6447 | tmp = NULL; |
| 6448 | } else { |
| 6449 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 6450 | return 1; |
| 6451 | } |
| 6452 | *out = comprehension(target, iter, ifs, arena); |
| 6453 | return 0; |
| 6454 | failed: |
| 6455 | Py_XDECREF(tmp); |
| 6456 | return 1; |
| 6457 | } |
| 6458 | |
| 6459 | int |
| 6460 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 6461 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6462 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6463 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 6464 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6465 | int lineno; |
| 6466 | int col_offset; |
| 6467 | |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6468 | if (obj == Py_None) { |
| 6469 | *out = NULL; |
| 6470 | return 0; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6471 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6472 | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6473 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6474 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6475 | if (tmp == NULL) goto failed; |
| 6476 | res = obj2ast_int(tmp, &lineno, arena); |
| 6477 | if (res != 0) goto failed; |
| 6478 | Py_XDECREF(tmp); |
| 6479 | tmp = NULL; |
| 6480 | } else { |
| 6481 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 6482 | return 1; |
| 6483 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6484 | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6485 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6486 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6487 | if (tmp == NULL) goto failed; |
| 6488 | res = obj2ast_int(tmp, &col_offset, arena); |
| 6489 | if (res != 0) goto failed; |
| 6490 | Py_XDECREF(tmp); |
| 6491 | tmp = NULL; |
| 6492 | } else { |
| 6493 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 6494 | return 1; |
| 6495 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6496 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type); |
| 6497 | if (isinstance == -1) { |
| 6498 | return 1; |
| 6499 | } |
| 6500 | if (isinstance) { |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6501 | expr_ty type; |
| 6502 | identifier name; |
| 6503 | asdl_seq* body; |
| 6504 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6505 | if (_PyObject_HasAttrId(obj, &PyId_type)) { |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6506 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6507 | tmp = _PyObject_GetAttrId(obj, &PyId_type); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6508 | if (tmp == NULL) goto failed; |
| 6509 | res = obj2ast_expr(tmp, &type, arena); |
| 6510 | if (res != 0) goto failed; |
| 6511 | Py_XDECREF(tmp); |
| 6512 | tmp = NULL; |
| 6513 | } else { |
| 6514 | type = NULL; |
| 6515 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6516 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6517 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6518 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6519 | if (tmp == NULL) goto failed; |
| 6520 | res = obj2ast_identifier(tmp, &name, arena); |
| 6521 | if (res != 0) goto failed; |
| 6522 | Py_XDECREF(tmp); |
| 6523 | tmp = NULL; |
| 6524 | } else { |
| 6525 | name = NULL; |
| 6526 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6527 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6528 | int res; |
| 6529 | Py_ssize_t len; |
| 6530 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6531 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6532 | if (tmp == NULL) goto failed; |
| 6533 | if (!PyList_Check(tmp)) { |
| 6534 | PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6535 | goto failed; |
| 6536 | } |
| 6537 | len = PyList_GET_SIZE(tmp); |
| 6538 | body = asdl_seq_new(len, arena); |
| 6539 | if (body == NULL) goto failed; |
| 6540 | for (i = 0; i < len; i++) { |
| 6541 | stmt_ty value; |
| 6542 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6543 | if (res != 0) goto failed; |
| 6544 | asdl_seq_SET(body, i, value); |
| 6545 | } |
| 6546 | Py_XDECREF(tmp); |
| 6547 | tmp = NULL; |
| 6548 | } else { |
| 6549 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 6550 | return 1; |
| 6551 | } |
| 6552 | *out = ExceptHandler(type, name, body, lineno, col_offset, |
| 6553 | arena); |
| 6554 | if (*out == NULL) goto failed; |
| 6555 | return 0; |
| 6556 | } |
| 6557 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6558 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
| 6559 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 6560 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6561 | return 1; |
| 6562 | } |
| 6563 | |
| 6564 | int |
| 6565 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 6566 | { |
| 6567 | PyObject* tmp = NULL; |
| 6568 | asdl_seq* args; |
| 6569 | identifier vararg; |
| 6570 | expr_ty varargannotation; |
| 6571 | asdl_seq* kwonlyargs; |
| 6572 | identifier kwarg; |
| 6573 | expr_ty kwargannotation; |
| 6574 | asdl_seq* defaults; |
| 6575 | asdl_seq* kw_defaults; |
| 6576 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6577 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6578 | int res; |
| 6579 | Py_ssize_t len; |
| 6580 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6581 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6582 | if (tmp == NULL) goto failed; |
| 6583 | if (!PyList_Check(tmp)) { |
| 6584 | PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6585 | goto failed; |
| 6586 | } |
| 6587 | len = PyList_GET_SIZE(tmp); |
| 6588 | args = asdl_seq_new(len, arena); |
| 6589 | if (args == NULL) goto failed; |
| 6590 | for (i = 0; i < len; i++) { |
| 6591 | arg_ty value; |
| 6592 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6593 | if (res != 0) goto failed; |
| 6594 | asdl_seq_SET(args, i, value); |
| 6595 | } |
| 6596 | Py_XDECREF(tmp); |
| 6597 | tmp = NULL; |
| 6598 | } else { |
| 6599 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 6600 | return 1; |
| 6601 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6602 | if (_PyObject_HasAttrId(obj, &PyId_vararg)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6603 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6604 | tmp = _PyObject_GetAttrId(obj, &PyId_vararg); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6605 | if (tmp == NULL) goto failed; |
| 6606 | res = obj2ast_identifier(tmp, &vararg, arena); |
| 6607 | if (res != 0) goto failed; |
| 6608 | Py_XDECREF(tmp); |
| 6609 | tmp = NULL; |
| 6610 | } else { |
| 6611 | vararg = NULL; |
| 6612 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6613 | if (_PyObject_HasAttrId(obj, &PyId_varargannotation)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6614 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6615 | tmp = _PyObject_GetAttrId(obj, &PyId_varargannotation); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6616 | if (tmp == NULL) goto failed; |
| 6617 | res = obj2ast_expr(tmp, &varargannotation, arena); |
| 6618 | if (res != 0) goto failed; |
| 6619 | Py_XDECREF(tmp); |
| 6620 | tmp = NULL; |
| 6621 | } else { |
| 6622 | varargannotation = NULL; |
| 6623 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6624 | if (_PyObject_HasAttrId(obj, &PyId_kwonlyargs)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6625 | int res; |
| 6626 | Py_ssize_t len; |
| 6627 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6628 | tmp = _PyObject_GetAttrId(obj, &PyId_kwonlyargs); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6629 | if (tmp == NULL) goto failed; |
| 6630 | if (!PyList_Check(tmp)) { |
| 6631 | PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6632 | goto failed; |
| 6633 | } |
| 6634 | len = PyList_GET_SIZE(tmp); |
| 6635 | kwonlyargs = asdl_seq_new(len, arena); |
| 6636 | if (kwonlyargs == NULL) goto failed; |
| 6637 | for (i = 0; i < len; i++) { |
| 6638 | arg_ty value; |
| 6639 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6640 | if (res != 0) goto failed; |
| 6641 | asdl_seq_SET(kwonlyargs, i, value); |
| 6642 | } |
| 6643 | Py_XDECREF(tmp); |
| 6644 | tmp = NULL; |
| 6645 | } else { |
| 6646 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 6647 | return 1; |
| 6648 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6649 | if (_PyObject_HasAttrId(obj, &PyId_kwarg)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6650 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6651 | tmp = _PyObject_GetAttrId(obj, &PyId_kwarg); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6652 | if (tmp == NULL) goto failed; |
| 6653 | res = obj2ast_identifier(tmp, &kwarg, arena); |
| 6654 | if (res != 0) goto failed; |
| 6655 | Py_XDECREF(tmp); |
| 6656 | tmp = NULL; |
| 6657 | } else { |
| 6658 | kwarg = NULL; |
| 6659 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6660 | if (_PyObject_HasAttrId(obj, &PyId_kwargannotation)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6661 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6662 | tmp = _PyObject_GetAttrId(obj, &PyId_kwargannotation); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6663 | if (tmp == NULL) goto failed; |
| 6664 | res = obj2ast_expr(tmp, &kwargannotation, arena); |
| 6665 | if (res != 0) goto failed; |
| 6666 | Py_XDECREF(tmp); |
| 6667 | tmp = NULL; |
| 6668 | } else { |
| 6669 | kwargannotation = NULL; |
| 6670 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6671 | if (_PyObject_HasAttrId(obj, &PyId_defaults)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6672 | int res; |
| 6673 | Py_ssize_t len; |
| 6674 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6675 | tmp = _PyObject_GetAttrId(obj, &PyId_defaults); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6676 | if (tmp == NULL) goto failed; |
| 6677 | if (!PyList_Check(tmp)) { |
| 6678 | PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6679 | goto failed; |
| 6680 | } |
| 6681 | len = PyList_GET_SIZE(tmp); |
| 6682 | defaults = asdl_seq_new(len, arena); |
| 6683 | if (defaults == NULL) goto failed; |
| 6684 | for (i = 0; i < len; i++) { |
| 6685 | expr_ty value; |
| 6686 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6687 | if (res != 0) goto failed; |
| 6688 | asdl_seq_SET(defaults, i, value); |
| 6689 | } |
| 6690 | Py_XDECREF(tmp); |
| 6691 | tmp = NULL; |
| 6692 | } else { |
| 6693 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 6694 | return 1; |
| 6695 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6696 | if (_PyObject_HasAttrId(obj, &PyId_kw_defaults)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6697 | int res; |
| 6698 | Py_ssize_t len; |
| 6699 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6700 | tmp = _PyObject_GetAttrId(obj, &PyId_kw_defaults); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6701 | if (tmp == NULL) goto failed; |
| 6702 | if (!PyList_Check(tmp)) { |
| 6703 | PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6704 | goto failed; |
| 6705 | } |
| 6706 | len = PyList_GET_SIZE(tmp); |
| 6707 | kw_defaults = asdl_seq_new(len, arena); |
| 6708 | if (kw_defaults == NULL) goto failed; |
| 6709 | for (i = 0; i < len; i++) { |
| 6710 | expr_ty value; |
| 6711 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6712 | if (res != 0) goto failed; |
| 6713 | asdl_seq_SET(kw_defaults, i, value); |
| 6714 | } |
| 6715 | Py_XDECREF(tmp); |
| 6716 | tmp = NULL; |
| 6717 | } else { |
| 6718 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 6719 | return 1; |
| 6720 | } |
| 6721 | *out = arguments(args, vararg, varargannotation, kwonlyargs, kwarg, |
| 6722 | kwargannotation, defaults, kw_defaults, arena); |
| 6723 | return 0; |
| 6724 | failed: |
| 6725 | Py_XDECREF(tmp); |
| 6726 | return 1; |
| 6727 | } |
| 6728 | |
| 6729 | int |
| 6730 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 6731 | { |
| 6732 | PyObject* tmp = NULL; |
| 6733 | identifier arg; |
| 6734 | expr_ty annotation; |
| 6735 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6736 | if (_PyObject_HasAttrId(obj, &PyId_arg)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6737 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6738 | tmp = _PyObject_GetAttrId(obj, &PyId_arg); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6739 | if (tmp == NULL) goto failed; |
| 6740 | res = obj2ast_identifier(tmp, &arg, arena); |
| 6741 | if (res != 0) goto failed; |
| 6742 | Py_XDECREF(tmp); |
| 6743 | tmp = NULL; |
| 6744 | } else { |
| 6745 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
| 6746 | return 1; |
| 6747 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6748 | if (_PyObject_HasAttrId(obj, &PyId_annotation)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6749 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6750 | tmp = _PyObject_GetAttrId(obj, &PyId_annotation); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6751 | if (tmp == NULL) goto failed; |
| 6752 | res = obj2ast_expr(tmp, &annotation, arena); |
| 6753 | if (res != 0) goto failed; |
| 6754 | Py_XDECREF(tmp); |
| 6755 | tmp = NULL; |
| 6756 | } else { |
| 6757 | annotation = NULL; |
| 6758 | } |
| 6759 | *out = arg(arg, annotation, arena); |
| 6760 | return 0; |
| 6761 | failed: |
| 6762 | Py_XDECREF(tmp); |
| 6763 | return 1; |
| 6764 | } |
| 6765 | |
| 6766 | int |
| 6767 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 6768 | { |
| 6769 | PyObject* tmp = NULL; |
| 6770 | identifier arg; |
| 6771 | expr_ty value; |
| 6772 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6773 | if (_PyObject_HasAttrId(obj, &PyId_arg)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6774 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6775 | tmp = _PyObject_GetAttrId(obj, &PyId_arg); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6776 | if (tmp == NULL) goto failed; |
| 6777 | res = obj2ast_identifier(tmp, &arg, arena); |
| 6778 | if (res != 0) goto failed; |
| 6779 | Py_XDECREF(tmp); |
| 6780 | tmp = NULL; |
| 6781 | } else { |
| 6782 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from keyword"); |
| 6783 | return 1; |
| 6784 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6785 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6786 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6787 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6788 | if (tmp == NULL) goto failed; |
| 6789 | res = obj2ast_expr(tmp, &value, arena); |
| 6790 | if (res != 0) goto failed; |
| 6791 | Py_XDECREF(tmp); |
| 6792 | tmp = NULL; |
| 6793 | } else { |
| 6794 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 6795 | return 1; |
| 6796 | } |
| 6797 | *out = keyword(arg, value, arena); |
| 6798 | return 0; |
| 6799 | failed: |
| 6800 | Py_XDECREF(tmp); |
| 6801 | return 1; |
| 6802 | } |
| 6803 | |
| 6804 | int |
| 6805 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 6806 | { |
| 6807 | PyObject* tmp = NULL; |
| 6808 | identifier name; |
| 6809 | identifier asname; |
| 6810 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6811 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6812 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6813 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6814 | if (tmp == NULL) goto failed; |
| 6815 | res = obj2ast_identifier(tmp, &name, arena); |
| 6816 | if (res != 0) goto failed; |
| 6817 | Py_XDECREF(tmp); |
| 6818 | tmp = NULL; |
| 6819 | } else { |
| 6820 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 6821 | return 1; |
| 6822 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6823 | if (_PyObject_HasAttrId(obj, &PyId_asname)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6824 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6825 | tmp = _PyObject_GetAttrId(obj, &PyId_asname); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6826 | if (tmp == NULL) goto failed; |
| 6827 | res = obj2ast_identifier(tmp, &asname, arena); |
| 6828 | if (res != 0) goto failed; |
| 6829 | Py_XDECREF(tmp); |
| 6830 | tmp = NULL; |
| 6831 | } else { |
| 6832 | asname = NULL; |
| 6833 | } |
| 6834 | *out = alias(name, asname, arena); |
| 6835 | return 0; |
| 6836 | failed: |
| 6837 | Py_XDECREF(tmp); |
| 6838 | return 1; |
| 6839 | } |
| 6840 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6841 | int |
| 6842 | obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) |
| 6843 | { |
| 6844 | PyObject* tmp = NULL; |
| 6845 | expr_ty context_expr; |
| 6846 | expr_ty optional_vars; |
| 6847 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6848 | if (_PyObject_HasAttrId(obj, &PyId_context_expr)) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6849 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6850 | tmp = _PyObject_GetAttrId(obj, &PyId_context_expr); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6851 | if (tmp == NULL) goto failed; |
| 6852 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 6853 | if (res != 0) goto failed; |
| 6854 | Py_XDECREF(tmp); |
| 6855 | tmp = NULL; |
| 6856 | } else { |
| 6857 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); |
| 6858 | return 1; |
| 6859 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6860 | if (_PyObject_HasAttrId(obj, &PyId_optional_vars)) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6861 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6862 | tmp = _PyObject_GetAttrId(obj, &PyId_optional_vars); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6863 | if (tmp == NULL) goto failed; |
| 6864 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 6865 | if (res != 0) goto failed; |
| 6866 | Py_XDECREF(tmp); |
| 6867 | tmp = NULL; |
| 6868 | } else { |
| 6869 | optional_vars = NULL; |
| 6870 | } |
| 6871 | *out = withitem(context_expr, optional_vars, arena); |
| 6872 | return 0; |
| 6873 | failed: |
| 6874 | Py_XDECREF(tmp); |
| 6875 | return 1; |
| 6876 | } |
| 6877 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6878 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6879 | static struct PyModuleDef _astmodule = { |
| 6880 | PyModuleDef_HEAD_INIT, "_ast" |
| 6881 | }; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6882 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6883 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6884 | { |
| 6885 | PyObject *m, *d; |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6886 | if (!init_types()) return NULL; |
| 6887 | m = PyModule_Create(&_astmodule); |
| 6888 | if (!m) return NULL; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6889 | d = PyModule_GetDict(m); |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6890 | if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return |
| 6891 | NULL; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6892 | if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6893 | return NULL; |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6894 | if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return |
| 6895 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6896 | if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6897 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6898 | if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6899 | < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6900 | if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6901 | 0) return NULL; |
| 6902 | if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return |
| 6903 | NULL; |
| 6904 | if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return |
| 6905 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6906 | if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6907 | < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6908 | if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6909 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6910 | if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6911 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6912 | if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6913 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6914 | if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6915 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6916 | if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6917 | 0) return NULL; |
| 6918 | if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return |
| 6919 | NULL; |
| 6920 | if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return |
| 6921 | NULL; |
| 6922 | if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return NULL; |
| 6923 | if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return |
| 6924 | NULL; |
| 6925 | if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return |
| 6926 | NULL; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 6927 | if (PyDict_SetItemString(d, "Try", (PyObject*)Try_type) < 0) return |
| 6928 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6929 | if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6930 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6931 | if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6932 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6933 | if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6934 | 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6935 | if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6936 | return NULL; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 6937 | if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6938 | return NULL; |
| 6939 | if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return |
| 6940 | NULL; |
| 6941 | if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return |
| 6942 | NULL; |
| 6943 | if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return |
| 6944 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6945 | if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6946 | return NULL; |
| 6947 | if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return |
| 6948 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6949 | if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6950 | return NULL; |
| 6951 | if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return |
| 6952 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6953 | if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6954 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6955 | if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6956 | return NULL; |
| 6957 | if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return |
| 6958 | NULL; |
| 6959 | if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return |
| 6960 | NULL; |
| 6961 | if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return |
| 6962 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6963 | if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6964 | return NULL; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 6965 | if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6966 | return NULL; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 6967 | if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6968 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6969 | if (PyDict_SetItemString(d, "GeneratorExp", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6970 | (PyObject*)GeneratorExp_type) < 0) return NULL; |
| 6971 | if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return |
| 6972 | NULL; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 6973 | if (PyDict_SetItemString(d, "YieldFrom", (PyObject*)YieldFrom_type) < |
| 6974 | 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6975 | if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6976 | return NULL; |
| 6977 | if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return |
| 6978 | NULL; |
| 6979 | if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return |
| 6980 | NULL; |
| 6981 | if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return |
| 6982 | NULL; |
| 6983 | if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return |
| 6984 | NULL; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 6985 | if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6986 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6987 | if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6988 | 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6989 | if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6990 | 0) return NULL; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 6991 | if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6992 | return NULL; |
| 6993 | if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return |
| 6994 | NULL; |
| 6995 | if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return |
| 6996 | NULL; |
| 6997 | if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return |
| 6998 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6999 | if (PyDict_SetItemString(d, "expr_context", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7000 | (PyObject*)expr_context_type) < 0) return NULL; |
| 7001 | if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return |
| 7002 | NULL; |
| 7003 | if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return |
| 7004 | NULL; |
| 7005 | if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return |
| 7006 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7007 | if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7008 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7009 | if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7010 | return NULL; |
| 7011 | if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return |
| 7012 | NULL; |
| 7013 | if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return |
| 7014 | NULL; |
| 7015 | if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return |
| 7016 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7017 | if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7018 | return NULL; |
| 7019 | if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return |
| 7020 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7021 | if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7022 | return NULL; |
| 7023 | if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return |
| 7024 | NULL; |
| 7025 | if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7026 | if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7027 | return NULL; |
| 7028 | if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return |
| 7029 | NULL; |
| 7030 | if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return |
| 7031 | NULL; |
| 7032 | if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return |
| 7033 | NULL; |
| 7034 | if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return |
| 7035 | NULL; |
| 7036 | if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return |
| 7037 | NULL; |
| 7038 | if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return |
| 7039 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7040 | if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7041 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7042 | if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7043 | return NULL; |
| 7044 | if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return |
| 7045 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7046 | if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7047 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7048 | if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7049 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7050 | if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7051 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7052 | if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7053 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7054 | if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7055 | return NULL; |
| 7056 | if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return |
| 7057 | NULL; |
| 7058 | if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return |
| 7059 | NULL; |
| 7060 | if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return |
| 7061 | NULL; |
| 7062 | if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return |
| 7063 | NULL; |
| 7064 | if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return NULL; |
| 7065 | if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return |
| 7066 | NULL; |
| 7067 | if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return NULL; |
| 7068 | if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return |
| 7069 | NULL; |
| 7070 | if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return NULL; |
| 7071 | if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return |
| 7072 | NULL; |
| 7073 | if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return NULL; |
| 7074 | if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return |
| 7075 | NULL; |
| 7076 | if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return NULL; |
| 7077 | if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return |
| 7078 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7079 | if (PyDict_SetItemString(d, "comprehension", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7080 | (PyObject*)comprehension_type) < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7081 | if (PyDict_SetItemString(d, "excepthandler", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7082 | (PyObject*)excepthandler_type) < 0) return NULL; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 7083 | if (PyDict_SetItemString(d, "ExceptHandler", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7084 | (PyObject*)ExceptHandler_type) < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7085 | if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7086 | 0) return NULL; |
| 7087 | if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return |
| 7088 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7089 | if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7090 | return NULL; |
| 7091 | if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return |
| 7092 | NULL; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 7093 | if (PyDict_SetItemString(d, "withitem", (PyObject*)withitem_type) < 0) |
| 7094 | return NULL; |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7095 | return m; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 7096 | } |
| 7097 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 7098 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 7099 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 7100 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 7101 | init_types(); |
| 7102 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 7103 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 7104 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7105 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 7106 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7107 | { |
| 7108 | mod_ty res; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7109 | PyObject *req_type[] = {(PyObject*)Module_type, (PyObject*)Expression_type, |
| 7110 | (PyObject*)Interactive_type}; |
| 7111 | char *req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 7112 | int isinstance; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7113 | assert(0 <= mode && mode <= 2); |
| 7114 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7115 | init_types(); |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7116 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 7117 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 7118 | if (isinstance == -1) |
| 7119 | return NULL; |
| 7120 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7121 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
| 7122 | req_name[mode], Py_TYPE(ast)->tp_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7123 | return NULL; |
| 7124 | } |
| 7125 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 7126 | return NULL; |
| 7127 | else |
| 7128 | return res; |
| 7129 | } |
| 7130 | |
| 7131 | int PyAST_Check(PyObject* obj) |
| 7132 | { |
| 7133 | init_types(); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 7134 | return PyObject_IsInstance(obj, (PyObject*)&AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7135 | } |
| 7136 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 7137 | |