Thomas Wouters | cf297e4 | 2007-02-23 15:07:44 +0000 | [diff] [blame] | 1 | /* File automatically generated by Parser/asdl_c.py. */ |
| 2 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3 | #include "Python.h" |
| 4 | #include "Python-ast.h" |
| 5 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 6 | static PyTypeObject AST_type; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 7 | static PyTypeObject *mod_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 8 | static PyObject* ast2obj_mod(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 9 | static PyTypeObject *Module_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 10 | _Py_IDENTIFIER(body); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 11 | static char *Module_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 12 | "body", |
| 13 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 14 | static PyTypeObject *Interactive_type; |
| 15 | static char *Interactive_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 16 | "body", |
| 17 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 18 | static PyTypeObject *Expression_type; |
| 19 | static char *Expression_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 20 | "body", |
| 21 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 22 | static PyTypeObject *Suite_type; |
| 23 | static char *Suite_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 24 | "body", |
| 25 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 26 | static PyTypeObject *stmt_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 27 | _Py_IDENTIFIER(lineno); |
| 28 | _Py_IDENTIFIER(col_offset); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 29 | static char *stmt_attributes[] = { |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 30 | "lineno", |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 31 | "col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 32 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 33 | static PyObject* ast2obj_stmt(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 34 | static PyTypeObject *FunctionDef_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 35 | _Py_IDENTIFIER(name); |
| 36 | _Py_IDENTIFIER(args); |
| 37 | _Py_IDENTIFIER(decorator_list); |
| 38 | _Py_IDENTIFIER(returns); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 39 | static char *FunctionDef_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 40 | "name", |
| 41 | "args", |
| 42 | "body", |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 43 | "decorator_list", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 44 | "returns", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 45 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 46 | static PyTypeObject *ClassDef_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 47 | _Py_IDENTIFIER(bases); |
| 48 | _Py_IDENTIFIER(keywords); |
| 49 | _Py_IDENTIFIER(starargs); |
| 50 | _Py_IDENTIFIER(kwargs); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 51 | static char *ClassDef_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 52 | "name", |
| 53 | "bases", |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 54 | "keywords", |
| 55 | "starargs", |
| 56 | "kwargs", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 57 | "body", |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 58 | "decorator_list", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 59 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 60 | static PyTypeObject *Return_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 61 | _Py_IDENTIFIER(value); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 62 | static char *Return_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 63 | "value", |
| 64 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 65 | static PyTypeObject *Delete_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 66 | _Py_IDENTIFIER(targets); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 67 | static char *Delete_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 68 | "targets", |
| 69 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 70 | static PyTypeObject *Assign_type; |
| 71 | static char *Assign_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 72 | "targets", |
| 73 | "value", |
| 74 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 75 | static PyTypeObject *AugAssign_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 76 | _Py_IDENTIFIER(target); |
| 77 | _Py_IDENTIFIER(op); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 78 | static char *AugAssign_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 79 | "target", |
| 80 | "op", |
| 81 | "value", |
| 82 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 83 | static PyTypeObject *For_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 84 | _Py_IDENTIFIER(iter); |
| 85 | _Py_IDENTIFIER(orelse); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 86 | static char *For_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 87 | "target", |
| 88 | "iter", |
| 89 | "body", |
| 90 | "orelse", |
| 91 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 92 | static PyTypeObject *While_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 93 | _Py_IDENTIFIER(test); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 94 | static char *While_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 95 | "test", |
| 96 | "body", |
| 97 | "orelse", |
| 98 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 99 | static PyTypeObject *If_type; |
| 100 | static char *If_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 101 | "test", |
| 102 | "body", |
| 103 | "orelse", |
| 104 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 105 | static PyTypeObject *With_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 106 | _Py_IDENTIFIER(items); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 107 | static char *With_fields[]={ |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 108 | "items", |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 109 | "body", |
| 110 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 111 | static PyTypeObject *Raise_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 112 | _Py_IDENTIFIER(exc); |
| 113 | _Py_IDENTIFIER(cause); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 114 | static char *Raise_fields[]={ |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 115 | "exc", |
| 116 | "cause", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 117 | }; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 118 | static PyTypeObject *Try_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 119 | _Py_IDENTIFIER(handlers); |
| 120 | _Py_IDENTIFIER(finalbody); |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 121 | static char *Try_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 122 | "body", |
| 123 | "handlers", |
| 124 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 125 | "finalbody", |
| 126 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 127 | static PyTypeObject *Assert_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 128 | _Py_IDENTIFIER(msg); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 129 | static char *Assert_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 130 | "test", |
| 131 | "msg", |
| 132 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 133 | static PyTypeObject *Import_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 134 | _Py_IDENTIFIER(names); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 135 | static char *Import_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 136 | "names", |
| 137 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 138 | static PyTypeObject *ImportFrom_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 139 | _Py_IDENTIFIER(module); |
| 140 | _Py_IDENTIFIER(level); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 141 | static char *ImportFrom_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 142 | "module", |
| 143 | "names", |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 144 | "level", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 145 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 146 | static PyTypeObject *Global_type; |
| 147 | static char *Global_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 148 | "names", |
| 149 | }; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 150 | static PyTypeObject *Nonlocal_type; |
| 151 | static char *Nonlocal_fields[]={ |
| 152 | "names", |
| 153 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 154 | static PyTypeObject *Expr_type; |
| 155 | static char *Expr_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 156 | "value", |
| 157 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 158 | static PyTypeObject *Pass_type; |
| 159 | static PyTypeObject *Break_type; |
| 160 | static PyTypeObject *Continue_type; |
| 161 | static PyTypeObject *expr_type; |
| 162 | static char *expr_attributes[] = { |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 163 | "lineno", |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 164 | "col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 165 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 166 | static PyObject* ast2obj_expr(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 167 | static PyTypeObject *BoolOp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 168 | _Py_IDENTIFIER(values); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 169 | static char *BoolOp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 170 | "op", |
| 171 | "values", |
| 172 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 173 | static PyTypeObject *BinOp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 174 | _Py_IDENTIFIER(left); |
| 175 | _Py_IDENTIFIER(right); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 176 | static char *BinOp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 177 | "left", |
| 178 | "op", |
| 179 | "right", |
| 180 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 181 | static PyTypeObject *UnaryOp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 182 | _Py_IDENTIFIER(operand); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 183 | static char *UnaryOp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 184 | "op", |
| 185 | "operand", |
| 186 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 187 | static PyTypeObject *Lambda_type; |
| 188 | static char *Lambda_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 189 | "args", |
| 190 | "body", |
| 191 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 192 | static PyTypeObject *IfExp_type; |
| 193 | static char *IfExp_fields[]={ |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 194 | "test", |
| 195 | "body", |
| 196 | "orelse", |
| 197 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 198 | static PyTypeObject *Dict_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 199 | _Py_IDENTIFIER(keys); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 200 | static char *Dict_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 201 | "keys", |
| 202 | "values", |
| 203 | }; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 204 | static PyTypeObject *Set_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 205 | _Py_IDENTIFIER(elts); |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 206 | static char *Set_fields[]={ |
| 207 | "elts", |
| 208 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 209 | static PyTypeObject *ListComp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 210 | _Py_IDENTIFIER(elt); |
| 211 | _Py_IDENTIFIER(generators); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 212 | static char *ListComp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 213 | "elt", |
| 214 | "generators", |
| 215 | }; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 216 | static PyTypeObject *SetComp_type; |
| 217 | static char *SetComp_fields[]={ |
| 218 | "elt", |
| 219 | "generators", |
| 220 | }; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 221 | static PyTypeObject *DictComp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 222 | _Py_IDENTIFIER(key); |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 223 | static char *DictComp_fields[]={ |
| 224 | "key", |
| 225 | "value", |
| 226 | "generators", |
| 227 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 228 | static PyTypeObject *GeneratorExp_type; |
| 229 | static char *GeneratorExp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 230 | "elt", |
| 231 | "generators", |
| 232 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 233 | static PyTypeObject *Yield_type; |
| 234 | static char *Yield_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 235 | "value", |
| 236 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 237 | static PyTypeObject *Compare_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 238 | _Py_IDENTIFIER(ops); |
| 239 | _Py_IDENTIFIER(comparators); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 240 | static char *Compare_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 241 | "left", |
| 242 | "ops", |
| 243 | "comparators", |
| 244 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 245 | static PyTypeObject *Call_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 246 | _Py_IDENTIFIER(func); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 247 | static char *Call_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 248 | "func", |
| 249 | "args", |
| 250 | "keywords", |
| 251 | "starargs", |
| 252 | "kwargs", |
| 253 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 254 | static PyTypeObject *Num_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 255 | _Py_IDENTIFIER(n); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 256 | static char *Num_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 257 | "n", |
| 258 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 259 | static PyTypeObject *Str_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 260 | _Py_IDENTIFIER(s); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 261 | static char *Str_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 262 | "s", |
| 263 | }; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 264 | static PyTypeObject *Bytes_type; |
| 265 | static char *Bytes_fields[]={ |
| 266 | "s", |
| 267 | }; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 268 | static PyTypeObject *Ellipsis_type; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 269 | static PyTypeObject *Attribute_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 270 | _Py_IDENTIFIER(attr); |
| 271 | _Py_IDENTIFIER(ctx); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 272 | static char *Attribute_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 273 | "value", |
| 274 | "attr", |
| 275 | "ctx", |
| 276 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 277 | static PyTypeObject *Subscript_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 278 | _Py_IDENTIFIER(slice); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 279 | static char *Subscript_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 280 | "value", |
| 281 | "slice", |
| 282 | "ctx", |
| 283 | }; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 284 | static PyTypeObject *Starred_type; |
| 285 | static char *Starred_fields[]={ |
| 286 | "value", |
| 287 | "ctx", |
| 288 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 289 | static PyTypeObject *Name_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 290 | _Py_IDENTIFIER(id); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 291 | static char *Name_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 292 | "id", |
| 293 | "ctx", |
| 294 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 295 | static PyTypeObject *List_type; |
| 296 | static char *List_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 297 | "elts", |
| 298 | "ctx", |
| 299 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 300 | static PyTypeObject *Tuple_type; |
| 301 | static char *Tuple_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 302 | "elts", |
| 303 | "ctx", |
| 304 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 305 | static PyTypeObject *expr_context_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 306 | static PyObject *Load_singleton, *Store_singleton, *Del_singleton, |
| 307 | *AugLoad_singleton, *AugStore_singleton, *Param_singleton; |
| 308 | static PyObject* ast2obj_expr_context(expr_context_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 309 | static PyTypeObject *Load_type; |
| 310 | static PyTypeObject *Store_type; |
| 311 | static PyTypeObject *Del_type; |
| 312 | static PyTypeObject *AugLoad_type; |
| 313 | static PyTypeObject *AugStore_type; |
| 314 | static PyTypeObject *Param_type; |
| 315 | static PyTypeObject *slice_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 316 | static PyObject* ast2obj_slice(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 317 | static PyTypeObject *Slice_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 318 | _Py_IDENTIFIER(lower); |
| 319 | _Py_IDENTIFIER(upper); |
| 320 | _Py_IDENTIFIER(step); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 321 | static char *Slice_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 322 | "lower", |
| 323 | "upper", |
| 324 | "step", |
| 325 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 326 | static PyTypeObject *ExtSlice_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 327 | _Py_IDENTIFIER(dims); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 328 | static char *ExtSlice_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 329 | "dims", |
| 330 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 331 | static PyTypeObject *Index_type; |
| 332 | static char *Index_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 333 | "value", |
| 334 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 335 | static PyTypeObject *boolop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 336 | static PyObject *And_singleton, *Or_singleton; |
| 337 | static PyObject* ast2obj_boolop(boolop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 338 | static PyTypeObject *And_type; |
| 339 | static PyTypeObject *Or_type; |
| 340 | static PyTypeObject *operator_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 341 | static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton, |
| 342 | *Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton, |
| 343 | *RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton, |
| 344 | *FloorDiv_singleton; |
| 345 | static PyObject* ast2obj_operator(operator_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 346 | static PyTypeObject *Add_type; |
| 347 | static PyTypeObject *Sub_type; |
| 348 | static PyTypeObject *Mult_type; |
| 349 | static PyTypeObject *Div_type; |
| 350 | static PyTypeObject *Mod_type; |
| 351 | static PyTypeObject *Pow_type; |
| 352 | static PyTypeObject *LShift_type; |
| 353 | static PyTypeObject *RShift_type; |
| 354 | static PyTypeObject *BitOr_type; |
| 355 | static PyTypeObject *BitXor_type; |
| 356 | static PyTypeObject *BitAnd_type; |
| 357 | static PyTypeObject *FloorDiv_type; |
| 358 | static PyTypeObject *unaryop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 359 | static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton, |
| 360 | *USub_singleton; |
| 361 | static PyObject* ast2obj_unaryop(unaryop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 362 | static PyTypeObject *Invert_type; |
| 363 | static PyTypeObject *Not_type; |
| 364 | static PyTypeObject *UAdd_type; |
| 365 | static PyTypeObject *USub_type; |
| 366 | static PyTypeObject *cmpop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 367 | static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton, |
| 368 | *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton, |
| 369 | *NotIn_singleton; |
| 370 | static PyObject* ast2obj_cmpop(cmpop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 371 | static PyTypeObject *Eq_type; |
| 372 | static PyTypeObject *NotEq_type; |
| 373 | static PyTypeObject *Lt_type; |
| 374 | static PyTypeObject *LtE_type; |
| 375 | static PyTypeObject *Gt_type; |
| 376 | static PyTypeObject *GtE_type; |
| 377 | static PyTypeObject *Is_type; |
| 378 | static PyTypeObject *IsNot_type; |
| 379 | static PyTypeObject *In_type; |
| 380 | static PyTypeObject *NotIn_type; |
| 381 | static PyTypeObject *comprehension_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 382 | static PyObject* ast2obj_comprehension(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 383 | _Py_IDENTIFIER(ifs); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 384 | static char *comprehension_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 385 | "target", |
| 386 | "iter", |
| 387 | "ifs", |
| 388 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 389 | static PyTypeObject *excepthandler_type; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 390 | static char *excepthandler_attributes[] = { |
| 391 | "lineno", |
| 392 | "col_offset", |
| 393 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 394 | static PyObject* ast2obj_excepthandler(void*); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 395 | static PyTypeObject *ExceptHandler_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 396 | _Py_IDENTIFIER(type); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 397 | static char *ExceptHandler_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 398 | "type", |
| 399 | "name", |
| 400 | "body", |
| 401 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 402 | static PyTypeObject *arguments_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 403 | static PyObject* ast2obj_arguments(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 404 | _Py_IDENTIFIER(vararg); |
| 405 | _Py_IDENTIFIER(varargannotation); |
| 406 | _Py_IDENTIFIER(kwonlyargs); |
| 407 | _Py_IDENTIFIER(kwarg); |
| 408 | _Py_IDENTIFIER(kwargannotation); |
| 409 | _Py_IDENTIFIER(defaults); |
| 410 | _Py_IDENTIFIER(kw_defaults); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 411 | static char *arguments_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 412 | "args", |
| 413 | "vararg", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 414 | "varargannotation", |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 415 | "kwonlyargs", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 416 | "kwarg", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 417 | "kwargannotation", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 418 | "defaults", |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 419 | "kw_defaults", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 420 | }; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 421 | static PyTypeObject *arg_type; |
| 422 | static PyObject* ast2obj_arg(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 423 | _Py_IDENTIFIER(arg); |
| 424 | _Py_IDENTIFIER(annotation); |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 425 | static char *arg_fields[]={ |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 426 | "arg", |
| 427 | "annotation", |
| 428 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 429 | static PyTypeObject *keyword_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 430 | static PyObject* ast2obj_keyword(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 431 | static char *keyword_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 432 | "arg", |
| 433 | "value", |
| 434 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 435 | static PyTypeObject *alias_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 436 | static PyObject* ast2obj_alias(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 437 | _Py_IDENTIFIER(asname); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 438 | static char *alias_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 439 | "name", |
| 440 | "asname", |
| 441 | }; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 442 | static PyTypeObject *withitem_type; |
| 443 | static PyObject* ast2obj_withitem(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 444 | _Py_IDENTIFIER(context_expr); |
| 445 | _Py_IDENTIFIER(optional_vars); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 446 | static char *withitem_fields[]={ |
| 447 | "context_expr", |
| 448 | "optional_vars", |
| 449 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 450 | |
| 451 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 452 | static int |
| 453 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 454 | { |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 455 | _Py_IDENTIFIER(_fields); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 456 | Py_ssize_t i, numfields = 0; |
| 457 | int res = -1; |
| 458 | PyObject *key, *value, *fields; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 459 | fields = _PyObject_GetAttrId((PyObject*)Py_TYPE(self), &PyId__fields); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 460 | if (!fields) |
| 461 | PyErr_Clear(); |
| 462 | if (fields) { |
| 463 | numfields = PySequence_Size(fields); |
| 464 | if (numfields == -1) |
| 465 | goto cleanup; |
| 466 | } |
| 467 | res = 0; /* if no error occurs, this stays 0 to the end */ |
| 468 | if (PyTuple_GET_SIZE(args) > 0) { |
| 469 | if (numfields != PyTuple_GET_SIZE(args)) { |
| 470 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes %s" |
Amaury Forgeot d'Arc | 245c70b | 2008-09-10 22:24:24 +0000 | [diff] [blame] | 471 | "%zd positional argument%s", |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 472 | Py_TYPE(self)->tp_name, |
| 473 | numfields == 0 ? "" : "either 0 or ", |
| 474 | numfields, numfields == 1 ? "" : "s"); |
| 475 | res = -1; |
| 476 | goto cleanup; |
| 477 | } |
| 478 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
| 479 | /* cannot be reached when fields is NULL */ |
| 480 | PyObject *name = PySequence_GetItem(fields, i); |
| 481 | if (!name) { |
| 482 | res = -1; |
| 483 | goto cleanup; |
| 484 | } |
| 485 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
| 486 | Py_DECREF(name); |
| 487 | if (res < 0) |
| 488 | goto cleanup; |
| 489 | } |
| 490 | } |
| 491 | if (kw) { |
| 492 | i = 0; /* needed by PyDict_Next */ |
| 493 | while (PyDict_Next(kw, &i, &key, &value)) { |
| 494 | res = PyObject_SetAttr(self, key, value); |
| 495 | if (res < 0) |
| 496 | goto cleanup; |
| 497 | } |
| 498 | } |
| 499 | cleanup: |
| 500 | Py_XDECREF(fields); |
| 501 | return res; |
| 502 | } |
| 503 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 504 | /* Pickling support */ |
| 505 | static PyObject * |
| 506 | ast_type_reduce(PyObject *self, PyObject *unused) |
| 507 | { |
| 508 | PyObject *res; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 509 | _Py_IDENTIFIER(__dict__); |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 510 | PyObject *dict = _PyObject_GetAttrId(self, &PyId___dict__); |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 511 | if (dict == NULL) { |
| 512 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) |
| 513 | PyErr_Clear(); |
| 514 | else |
| 515 | return NULL; |
| 516 | } |
| 517 | if (dict) { |
| 518 | res = Py_BuildValue("O()O", Py_TYPE(self), dict); |
| 519 | Py_DECREF(dict); |
| 520 | return res; |
| 521 | } |
| 522 | return Py_BuildValue("O()", Py_TYPE(self)); |
| 523 | } |
| 524 | |
| 525 | static PyMethodDef ast_type_methods[] = { |
| 526 | {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, |
| 527 | {NULL} |
| 528 | }; |
| 529 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 530 | static PyTypeObject AST_type = { |
| 531 | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 532 | "_ast.AST", |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 533 | sizeof(PyObject), |
| 534 | 0, |
| 535 | 0, /* tp_dealloc */ |
| 536 | 0, /* tp_print */ |
| 537 | 0, /* tp_getattr */ |
| 538 | 0, /* tp_setattr */ |
Mark Dickinson | e94c679 | 2009-02-02 20:36:42 +0000 | [diff] [blame] | 539 | 0, /* tp_reserved */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 540 | 0, /* tp_repr */ |
| 541 | 0, /* tp_as_number */ |
| 542 | 0, /* tp_as_sequence */ |
| 543 | 0, /* tp_as_mapping */ |
| 544 | 0, /* tp_hash */ |
| 545 | 0, /* tp_call */ |
| 546 | 0, /* tp_str */ |
| 547 | PyObject_GenericGetAttr, /* tp_getattro */ |
| 548 | PyObject_GenericSetAttr, /* tp_setattro */ |
| 549 | 0, /* tp_as_buffer */ |
| 550 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
| 551 | 0, /* tp_doc */ |
| 552 | 0, /* tp_traverse */ |
| 553 | 0, /* tp_clear */ |
| 554 | 0, /* tp_richcompare */ |
| 555 | 0, /* tp_weaklistoffset */ |
| 556 | 0, /* tp_iter */ |
| 557 | 0, /* tp_iternext */ |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 558 | ast_type_methods, /* tp_methods */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 559 | 0, /* tp_members */ |
| 560 | 0, /* tp_getset */ |
| 561 | 0, /* tp_base */ |
| 562 | 0, /* tp_dict */ |
| 563 | 0, /* tp_descr_get */ |
| 564 | 0, /* tp_descr_set */ |
| 565 | 0, /* tp_dictoffset */ |
| 566 | (initproc)ast_type_init, /* tp_init */ |
| 567 | PyType_GenericAlloc, /* tp_alloc */ |
| 568 | PyType_GenericNew, /* tp_new */ |
| 569 | PyObject_Del, /* tp_free */ |
| 570 | }; |
| 571 | |
| 572 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 573 | static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields) |
| 574 | { |
| 575 | PyObject *fnames, *result; |
| 576 | int i; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 577 | fnames = PyTuple_New(num_fields); |
| 578 | if (!fnames) return NULL; |
| 579 | for (i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 580 | PyObject *field = PyUnicode_FromString(fields[i]); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 581 | if (!field) { |
| 582 | Py_DECREF(fnames); |
| 583 | return NULL; |
| 584 | } |
| 585 | PyTuple_SET_ITEM(fnames, i, field); |
| 586 | } |
Victor Stinner | 7eeb5b5 | 2010-06-07 19:57:46 +0000 | [diff] [blame] | 587 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 588 | type, base, "_fields", fnames, "__module__", "_ast"); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 589 | Py_DECREF(fnames); |
| 590 | return (PyTypeObject*)result; |
| 591 | } |
| 592 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 593 | static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) |
| 594 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 595 | int i, result; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 596 | _Py_IDENTIFIER(_attributes); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 597 | PyObject *s, *l = PyTuple_New(num_fields); |
Benjamin Peterson | 3e5cd1d | 2010-06-27 21:45:24 +0000 | [diff] [blame] | 598 | if (!l) |
| 599 | return 0; |
| 600 | for (i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 601 | s = PyUnicode_FromString(attrs[i]); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 602 | if (!s) { |
| 603 | Py_DECREF(l); |
| 604 | return 0; |
| 605 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 606 | PyTuple_SET_ITEM(l, i, s); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 607 | } |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 608 | result = _PyObject_SetAttrId((PyObject*)type, &PyId__attributes, l) >= 0; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 609 | Py_DECREF(l); |
| 610 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 611 | } |
| 612 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 613 | /* Conversion AST -> Python */ |
| 614 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 615 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 616 | { |
| 617 | int i, n = asdl_seq_LEN(seq); |
| 618 | PyObject *result = PyList_New(n); |
| 619 | PyObject *value; |
| 620 | if (!result) |
| 621 | return NULL; |
| 622 | for (i = 0; i < n; i++) { |
| 623 | value = func(asdl_seq_GET(seq, i)); |
| 624 | if (!value) { |
| 625 | Py_DECREF(result); |
| 626 | return NULL; |
| 627 | } |
| 628 | PyList_SET_ITEM(result, i, value); |
| 629 | } |
| 630 | return result; |
| 631 | } |
| 632 | |
| 633 | static PyObject* ast2obj_object(void *o) |
| 634 | { |
| 635 | if (!o) |
| 636 | o = Py_None; |
| 637 | Py_INCREF((PyObject*)o); |
| 638 | return (PyObject*)o; |
| 639 | } |
| 640 | #define ast2obj_identifier ast2obj_object |
| 641 | #define ast2obj_string ast2obj_object |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 642 | #define ast2obj_bytes ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 643 | |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 644 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 645 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 646 | return PyLong_FromLong(b); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 647 | } |
| 648 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 649 | /* Conversion Python -> AST */ |
| 650 | |
| 651 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 652 | { |
| 653 | if (obj == Py_None) |
| 654 | obj = NULL; |
| 655 | if (obj) |
| 656 | PyArena_AddPyObject(arena, obj); |
| 657 | Py_XINCREF(obj); |
| 658 | *out = obj; |
| 659 | return 0; |
| 660 | } |
| 661 | |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 662 | static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 663 | { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 664 | if (!PyUnicode_CheckExact(obj) && obj != Py_None) { |
| 665 | PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 666 | return 1; |
| 667 | } |
| 668 | return obj2ast_object(obj, out, arena); |
| 669 | } |
| 670 | |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 671 | static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) |
| 672 | { |
Benjamin Peterson | 0224d4e | 2011-08-31 22:13:03 -0400 | [diff] [blame] | 673 | if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 674 | PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); |
| 675 | return 1; |
| 676 | } |
| 677 | return obj2ast_object(obj, out, arena); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 678 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 679 | |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 680 | static int obj2ast_bytes(PyObject* obj, PyObject** out, PyArena* arena) |
| 681 | { |
| 682 | if (!PyBytes_CheckExact(obj)) { |
| 683 | PyErr_SetString(PyExc_TypeError, "AST bytes must be of type bytes"); |
| 684 | return 1; |
| 685 | } |
| 686 | return obj2ast_object(obj, out, arena); |
| 687 | } |
| 688 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 689 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 690 | { |
| 691 | int i; |
| 692 | if (!PyLong_Check(obj)) { |
Amaury Forgeot d'Arc | 5e8f810 | 2011-11-22 21:52:30 +0100 | [diff] [blame] | 693 | PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 694 | return 1; |
| 695 | } |
| 696 | |
| 697 | i = (int)PyLong_AsLong(obj); |
| 698 | if (i == -1 && PyErr_Occurred()) |
| 699 | return 1; |
| 700 | *out = i; |
| 701 | return 0; |
| 702 | } |
| 703 | |
Benjamin Peterson | 1a6e0d0 | 2008-10-25 15:49:17 +0000 | [diff] [blame] | 704 | static int add_ast_fields(void) |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 705 | { |
| 706 | PyObject *empty_tuple, *d; |
| 707 | if (PyType_Ready(&AST_type) < 0) |
| 708 | return -1; |
| 709 | d = AST_type.tp_dict; |
| 710 | empty_tuple = PyTuple_New(0); |
| 711 | if (!empty_tuple || |
| 712 | PyDict_SetItemString(d, "_fields", empty_tuple) < 0 || |
| 713 | PyDict_SetItemString(d, "_attributes", empty_tuple) < 0) { |
| 714 | Py_XDECREF(empty_tuple); |
| 715 | return -1; |
| 716 | } |
| 717 | Py_DECREF(empty_tuple); |
| 718 | return 0; |
| 719 | } |
| 720 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 721 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 722 | static int init_types(void) |
| 723 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 724 | static int initialized; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 725 | if (initialized) return 1; |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 726 | if (add_ast_fields() < 0) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 727 | mod_type = make_type("mod", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 728 | if (!mod_type) return 0; |
| 729 | if (!add_attributes(mod_type, NULL, 0)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 730 | Module_type = make_type("Module", mod_type, Module_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 731 | if (!Module_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 732 | Interactive_type = make_type("Interactive", mod_type, |
| 733 | Interactive_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 734 | if (!Interactive_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 735 | Expression_type = make_type("Expression", mod_type, Expression_fields, |
| 736 | 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 737 | if (!Expression_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 738 | Suite_type = make_type("Suite", mod_type, Suite_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 739 | if (!Suite_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 740 | stmt_type = make_type("stmt", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 741 | if (!stmt_type) return 0; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 742 | if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 743 | FunctionDef_type = make_type("FunctionDef", stmt_type, |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 744 | FunctionDef_fields, 5); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 745 | if (!FunctionDef_type) return 0; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 746 | ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 7); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 747 | if (!ClassDef_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 748 | Return_type = make_type("Return", stmt_type, Return_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 749 | if (!Return_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 750 | Delete_type = make_type("Delete", stmt_type, Delete_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 751 | if (!Delete_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 752 | Assign_type = make_type("Assign", stmt_type, Assign_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 753 | if (!Assign_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 754 | AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 755 | if (!AugAssign_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 756 | For_type = make_type("For", stmt_type, For_fields, 4); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 757 | if (!For_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 758 | While_type = make_type("While", stmt_type, While_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 759 | if (!While_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 760 | If_type = make_type("If", stmt_type, If_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 761 | if (!If_type) return 0; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 762 | With_type = make_type("With", stmt_type, With_fields, 2); |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 763 | if (!With_type) return 0; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 764 | Raise_type = make_type("Raise", stmt_type, Raise_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 765 | if (!Raise_type) return 0; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 766 | Try_type = make_type("Try", stmt_type, Try_fields, 4); |
| 767 | if (!Try_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 768 | Assert_type = make_type("Assert", stmt_type, Assert_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 769 | if (!Assert_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 770 | Import_type = make_type("Import", stmt_type, Import_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 771 | if (!Import_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 772 | ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 773 | 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 774 | if (!ImportFrom_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 775 | Global_type = make_type("Global", stmt_type, Global_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 776 | if (!Global_type) return 0; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 777 | Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1); |
| 778 | if (!Nonlocal_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 779 | Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 780 | if (!Expr_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 781 | Pass_type = make_type("Pass", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 782 | if (!Pass_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 783 | Break_type = make_type("Break", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 784 | if (!Break_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 785 | Continue_type = make_type("Continue", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 786 | if (!Continue_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 787 | expr_type = make_type("expr", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 788 | if (!expr_type) return 0; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 789 | if (!add_attributes(expr_type, expr_attributes, 2)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 790 | BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 791 | if (!BoolOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 792 | BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 793 | if (!BinOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 794 | UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 795 | if (!UnaryOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 796 | Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 797 | if (!Lambda_type) return 0; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 798 | IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 799 | if (!IfExp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 800 | Dict_type = make_type("Dict", expr_type, Dict_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 801 | if (!Dict_type) return 0; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 802 | Set_type = make_type("Set", expr_type, Set_fields, 1); |
| 803 | if (!Set_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 804 | ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 805 | if (!ListComp_type) return 0; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 806 | SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2); |
| 807 | if (!SetComp_type) return 0; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 808 | DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3); |
| 809 | if (!DictComp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 810 | GeneratorExp_type = make_type("GeneratorExp", expr_type, |
| 811 | GeneratorExp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 812 | if (!GeneratorExp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 813 | Yield_type = make_type("Yield", expr_type, Yield_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 814 | if (!Yield_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 815 | Compare_type = make_type("Compare", expr_type, Compare_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 816 | if (!Compare_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 817 | Call_type = make_type("Call", expr_type, Call_fields, 5); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 818 | if (!Call_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 819 | Num_type = make_type("Num", expr_type, Num_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 820 | if (!Num_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 821 | Str_type = make_type("Str", expr_type, Str_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 822 | if (!Str_type) return 0; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 823 | Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1); |
| 824 | if (!Bytes_type) return 0; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 825 | Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0); |
| 826 | if (!Ellipsis_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 827 | Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 828 | if (!Attribute_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 829 | Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 830 | if (!Subscript_type) return 0; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 831 | Starred_type = make_type("Starred", expr_type, Starred_fields, 2); |
| 832 | if (!Starred_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 833 | Name_type = make_type("Name", expr_type, Name_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 834 | if (!Name_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 835 | List_type = make_type("List", expr_type, List_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 836 | if (!List_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 837 | Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 838 | if (!Tuple_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 839 | 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] | 840 | if (!expr_context_type) return 0; |
| 841 | if (!add_attributes(expr_context_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 842 | Load_type = make_type("Load", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 843 | if (!Load_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 844 | Load_singleton = PyType_GenericNew(Load_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 845 | if (!Load_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 846 | Store_type = make_type("Store", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 847 | if (!Store_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 848 | Store_singleton = PyType_GenericNew(Store_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 849 | if (!Store_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 850 | Del_type = make_type("Del", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 851 | if (!Del_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 852 | Del_singleton = PyType_GenericNew(Del_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 853 | if (!Del_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 854 | AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 855 | if (!AugLoad_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 856 | AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 857 | if (!AugLoad_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 858 | AugStore_type = make_type("AugStore", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 859 | if (!AugStore_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 860 | AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 861 | if (!AugStore_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 862 | Param_type = make_type("Param", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 863 | if (!Param_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 864 | Param_singleton = PyType_GenericNew(Param_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 865 | if (!Param_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 866 | slice_type = make_type("slice", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 867 | if (!slice_type) return 0; |
| 868 | if (!add_attributes(slice_type, NULL, 0)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 869 | Slice_type = make_type("Slice", slice_type, Slice_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 870 | if (!Slice_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 871 | ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 872 | if (!ExtSlice_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 873 | Index_type = make_type("Index", slice_type, Index_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 874 | if (!Index_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 875 | boolop_type = make_type("boolop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 876 | if (!boolop_type) return 0; |
| 877 | if (!add_attributes(boolop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 878 | And_type = make_type("And", boolop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 879 | if (!And_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 880 | And_singleton = PyType_GenericNew(And_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 881 | if (!And_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 882 | Or_type = make_type("Or", boolop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 883 | if (!Or_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 884 | Or_singleton = PyType_GenericNew(Or_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 885 | if (!Or_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 886 | operator_type = make_type("operator", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 887 | if (!operator_type) return 0; |
| 888 | if (!add_attributes(operator_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 889 | Add_type = make_type("Add", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 890 | if (!Add_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 891 | Add_singleton = PyType_GenericNew(Add_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 892 | if (!Add_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 893 | Sub_type = make_type("Sub", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 894 | if (!Sub_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 895 | Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 896 | if (!Sub_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 897 | Mult_type = make_type("Mult", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 898 | if (!Mult_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 899 | Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 900 | if (!Mult_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 901 | Div_type = make_type("Div", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 902 | if (!Div_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 903 | Div_singleton = PyType_GenericNew(Div_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 904 | if (!Div_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 905 | Mod_type = make_type("Mod", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 906 | if (!Mod_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 907 | Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 908 | if (!Mod_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 909 | Pow_type = make_type("Pow", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 910 | if (!Pow_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 911 | Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 912 | if (!Pow_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 913 | LShift_type = make_type("LShift", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 914 | if (!LShift_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 915 | LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 916 | if (!LShift_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 917 | RShift_type = make_type("RShift", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 918 | if (!RShift_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 919 | RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 920 | if (!RShift_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 921 | BitOr_type = make_type("BitOr", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 922 | if (!BitOr_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 923 | BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 924 | if (!BitOr_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 925 | BitXor_type = make_type("BitXor", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 926 | if (!BitXor_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 927 | BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 928 | if (!BitXor_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 929 | BitAnd_type = make_type("BitAnd", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 930 | if (!BitAnd_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 931 | BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 932 | if (!BitAnd_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 933 | FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 934 | if (!FloorDiv_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 935 | FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 936 | if (!FloorDiv_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 937 | unaryop_type = make_type("unaryop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 938 | if (!unaryop_type) return 0; |
| 939 | if (!add_attributes(unaryop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 940 | Invert_type = make_type("Invert", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 941 | if (!Invert_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 942 | Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 943 | if (!Invert_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 944 | Not_type = make_type("Not", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 945 | if (!Not_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 946 | Not_singleton = PyType_GenericNew(Not_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 947 | if (!Not_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 948 | UAdd_type = make_type("UAdd", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 949 | if (!UAdd_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 950 | UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 951 | if (!UAdd_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 952 | USub_type = make_type("USub", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 953 | if (!USub_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 954 | USub_singleton = PyType_GenericNew(USub_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 955 | if (!USub_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 956 | cmpop_type = make_type("cmpop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 957 | if (!cmpop_type) return 0; |
| 958 | if (!add_attributes(cmpop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 959 | Eq_type = make_type("Eq", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 960 | if (!Eq_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 961 | Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 962 | if (!Eq_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 963 | NotEq_type = make_type("NotEq", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 964 | if (!NotEq_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 965 | NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 966 | if (!NotEq_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 967 | Lt_type = make_type("Lt", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 968 | if (!Lt_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 969 | Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 970 | if (!Lt_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 971 | LtE_type = make_type("LtE", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 972 | if (!LtE_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 973 | LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 974 | if (!LtE_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 975 | Gt_type = make_type("Gt", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 976 | if (!Gt_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 977 | Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 978 | if (!Gt_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 979 | GtE_type = make_type("GtE", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 980 | if (!GtE_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 981 | GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 982 | if (!GtE_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 983 | Is_type = make_type("Is", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 984 | if (!Is_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 985 | Is_singleton = PyType_GenericNew(Is_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 986 | if (!Is_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 987 | IsNot_type = make_type("IsNot", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 988 | if (!IsNot_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 989 | IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 990 | if (!IsNot_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 991 | In_type = make_type("In", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 992 | if (!In_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 993 | In_singleton = PyType_GenericNew(In_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 994 | if (!In_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 995 | NotIn_type = make_type("NotIn", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 996 | if (!NotIn_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 997 | NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 998 | if (!NotIn_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 999 | comprehension_type = make_type("comprehension", &AST_type, |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1000 | comprehension_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1001 | if (!comprehension_type) return 0; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 1002 | excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1003 | if (!excepthandler_type) return 0; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 1004 | if (!add_attributes(excepthandler_type, excepthandler_attributes, 2)) |
| 1005 | return 0; |
| 1006 | ExceptHandler_type = make_type("ExceptHandler", excepthandler_type, |
| 1007 | ExceptHandler_fields, 3); |
| 1008 | if (!ExceptHandler_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1009 | arguments_type = make_type("arguments", &AST_type, arguments_fields, 8); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1010 | if (!arguments_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1011 | arg_type = make_type("arg", &AST_type, arg_fields, 2); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1012 | if (!arg_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1013 | keyword_type = make_type("keyword", &AST_type, keyword_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1014 | if (!keyword_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1015 | alias_type = make_type("alias", &AST_type, alias_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1016 | if (!alias_type) return 0; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1017 | withitem_type = make_type("withitem", &AST_type, withitem_fields, 2); |
| 1018 | if (!withitem_type) return 0; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1019 | initialized = 1; |
| 1020 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1021 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 1022 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1023 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 1024 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 1025 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 1026 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 1027 | arena); |
| 1028 | static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena); |
| 1029 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 1030 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 1031 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 1032 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 1033 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 1034 | arena); |
| 1035 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 1036 | arena); |
| 1037 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 1038 | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
| 1039 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 1040 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1041 | 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] | 1042 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1043 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1044 | Module(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1045 | { |
| 1046 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1047 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1048 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1049 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1050 | p->kind = Module_kind; |
| 1051 | p->v.Module.body = body; |
| 1052 | return p; |
| 1053 | } |
| 1054 | |
| 1055 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1056 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1057 | { |
| 1058 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1059 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1060 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1061 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1062 | p->kind = Interactive_kind; |
| 1063 | p->v.Interactive.body = body; |
| 1064 | return p; |
| 1065 | } |
| 1066 | |
| 1067 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1068 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1069 | { |
| 1070 | mod_ty p; |
| 1071 | if (!body) { |
| 1072 | PyErr_SetString(PyExc_ValueError, |
| 1073 | "field body is required for Expression"); |
| 1074 | return NULL; |
| 1075 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1076 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1077 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1078 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1079 | p->kind = Expression_kind; |
| 1080 | p->v.Expression.body = body; |
| 1081 | return p; |
| 1082 | } |
| 1083 | |
| 1084 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1085 | Suite(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1086 | { |
| 1087 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1088 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1089 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1090 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1091 | p->kind = Suite_kind; |
| 1092 | p->v.Suite.body = body; |
| 1093 | return p; |
| 1094 | } |
| 1095 | |
| 1096 | stmt_ty |
| 1097 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1098 | decorator_list, expr_ty returns, int lineno, int col_offset, |
| 1099 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1100 | { |
| 1101 | stmt_ty p; |
| 1102 | if (!name) { |
| 1103 | PyErr_SetString(PyExc_ValueError, |
| 1104 | "field name is required for FunctionDef"); |
| 1105 | return NULL; |
| 1106 | } |
| 1107 | if (!args) { |
| 1108 | PyErr_SetString(PyExc_ValueError, |
| 1109 | "field args is required for FunctionDef"); |
| 1110 | return NULL; |
| 1111 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1112 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1113 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1114 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1115 | p->kind = FunctionDef_kind; |
| 1116 | p->v.FunctionDef.name = name; |
| 1117 | p->v.FunctionDef.args = args; |
| 1118 | p->v.FunctionDef.body = body; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1119 | p->v.FunctionDef.decorator_list = decorator_list; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1120 | p->v.FunctionDef.returns = returns; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1121 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1122 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1123 | return p; |
| 1124 | } |
| 1125 | |
| 1126 | stmt_ty |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 1127 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, expr_ty |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1128 | starargs, expr_ty kwargs, asdl_seq * body, asdl_seq * decorator_list, |
| 1129 | int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1130 | { |
| 1131 | stmt_ty p; |
| 1132 | if (!name) { |
| 1133 | PyErr_SetString(PyExc_ValueError, |
| 1134 | "field name is required for ClassDef"); |
| 1135 | return NULL; |
| 1136 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1137 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1138 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1139 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1140 | p->kind = ClassDef_kind; |
| 1141 | p->v.ClassDef.name = name; |
| 1142 | p->v.ClassDef.bases = bases; |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 1143 | p->v.ClassDef.keywords = keywords; |
| 1144 | p->v.ClassDef.starargs = starargs; |
| 1145 | p->v.ClassDef.kwargs = kwargs; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1146 | p->v.ClassDef.body = body; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1147 | p->v.ClassDef.decorator_list = decorator_list; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1148 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1149 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1150 | return p; |
| 1151 | } |
| 1152 | |
| 1153 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1154 | Return(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1155 | { |
| 1156 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1157 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1158 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1159 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1160 | p->kind = Return_kind; |
| 1161 | p->v.Return.value = value; |
| 1162 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1163 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1164 | return p; |
| 1165 | } |
| 1166 | |
| 1167 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1168 | Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1169 | { |
| 1170 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1171 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1172 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1173 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1174 | p->kind = Delete_kind; |
| 1175 | p->v.Delete.targets = targets; |
| 1176 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1177 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1178 | return p; |
| 1179 | } |
| 1180 | |
| 1181 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1182 | Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena |
| 1183 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1184 | { |
| 1185 | stmt_ty p; |
| 1186 | if (!value) { |
| 1187 | PyErr_SetString(PyExc_ValueError, |
| 1188 | "field value is required for Assign"); |
| 1189 | return NULL; |
| 1190 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1191 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1192 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1193 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1194 | p->kind = Assign_kind; |
| 1195 | p->v.Assign.targets = targets; |
| 1196 | p->v.Assign.value = value; |
| 1197 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1198 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1199 | return p; |
| 1200 | } |
| 1201 | |
| 1202 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1203 | AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int |
| 1204 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1205 | { |
| 1206 | stmt_ty p; |
| 1207 | if (!target) { |
| 1208 | PyErr_SetString(PyExc_ValueError, |
| 1209 | "field target is required for AugAssign"); |
| 1210 | return NULL; |
| 1211 | } |
| 1212 | if (!op) { |
| 1213 | PyErr_SetString(PyExc_ValueError, |
| 1214 | "field op is required for AugAssign"); |
| 1215 | return NULL; |
| 1216 | } |
| 1217 | if (!value) { |
| 1218 | PyErr_SetString(PyExc_ValueError, |
| 1219 | "field value is required for AugAssign"); |
| 1220 | return NULL; |
| 1221 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1222 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1223 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1224 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1225 | p->kind = AugAssign_kind; |
| 1226 | p->v.AugAssign.target = target; |
| 1227 | p->v.AugAssign.op = op; |
| 1228 | p->v.AugAssign.value = value; |
| 1229 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1230 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1231 | return p; |
| 1232 | } |
| 1233 | |
| 1234 | stmt_ty |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1235 | 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] | 1236 | lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1237 | { |
| 1238 | stmt_ty p; |
| 1239 | if (!target) { |
| 1240 | PyErr_SetString(PyExc_ValueError, |
| 1241 | "field target is required for For"); |
| 1242 | return NULL; |
| 1243 | } |
| 1244 | if (!iter) { |
| 1245 | PyErr_SetString(PyExc_ValueError, |
| 1246 | "field iter is required for For"); |
| 1247 | return NULL; |
| 1248 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1249 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1250 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1251 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1252 | p->kind = For_kind; |
| 1253 | p->v.For.target = target; |
| 1254 | p->v.For.iter = iter; |
| 1255 | p->v.For.body = body; |
| 1256 | p->v.For.orelse = orelse; |
| 1257 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1258 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1259 | return p; |
| 1260 | } |
| 1261 | |
| 1262 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1263 | While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1264 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1265 | { |
| 1266 | stmt_ty p; |
| 1267 | if (!test) { |
| 1268 | PyErr_SetString(PyExc_ValueError, |
| 1269 | "field test is required for While"); |
| 1270 | return NULL; |
| 1271 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1272 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1273 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1274 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1275 | p->kind = While_kind; |
| 1276 | p->v.While.test = test; |
| 1277 | p->v.While.body = body; |
| 1278 | p->v.While.orelse = orelse; |
| 1279 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1280 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1281 | return p; |
| 1282 | } |
| 1283 | |
| 1284 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1285 | If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1286 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1287 | { |
| 1288 | stmt_ty p; |
| 1289 | if (!test) { |
| 1290 | PyErr_SetString(PyExc_ValueError, |
| 1291 | "field test is required for If"); |
| 1292 | return NULL; |
| 1293 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1294 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1295 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1296 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1297 | p->kind = If_kind; |
| 1298 | p->v.If.test = test; |
| 1299 | p->v.If.body = body; |
| 1300 | p->v.If.orelse = orelse; |
| 1301 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1302 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1303 | return p; |
| 1304 | } |
| 1305 | |
| 1306 | stmt_ty |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1307 | With(asdl_seq * items, asdl_seq * body, int lineno, int col_offset, PyArena |
| 1308 | *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1309 | { |
| 1310 | stmt_ty p; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1311 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1312 | if (!p) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1313 | return NULL; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1314 | p->kind = With_kind; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1315 | p->v.With.items = items; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1316 | p->v.With.body = body; |
| 1317 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1318 | p->col_offset = col_offset; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1319 | return p; |
| 1320 | } |
| 1321 | |
| 1322 | stmt_ty |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 1323 | 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] | 1324 | { |
| 1325 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1326 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1327 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1328 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1329 | p->kind = Raise_kind; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 1330 | p->v.Raise.exc = exc; |
| 1331 | p->v.Raise.cause = cause; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1332 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1333 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1334 | return p; |
| 1335 | } |
| 1336 | |
| 1337 | stmt_ty |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 1338 | Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * |
| 1339 | finalbody, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1340 | { |
| 1341 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1342 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1343 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1344 | return NULL; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 1345 | p->kind = Try_kind; |
| 1346 | p->v.Try.body = body; |
| 1347 | p->v.Try.handlers = handlers; |
| 1348 | p->v.Try.orelse = orelse; |
| 1349 | p->v.Try.finalbody = finalbody; |
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 |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1356 | 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] | 1357 | { |
| 1358 | stmt_ty p; |
| 1359 | if (!test) { |
| 1360 | PyErr_SetString(PyExc_ValueError, |
| 1361 | "field test is required for Assert"); |
| 1362 | return NULL; |
| 1363 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1364 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1365 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1366 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1367 | p->kind = Assert_kind; |
| 1368 | p->v.Assert.test = test; |
| 1369 | p->v.Assert.msg = msg; |
| 1370 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1371 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1372 | return p; |
| 1373 | } |
| 1374 | |
| 1375 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1376 | Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1377 | { |
| 1378 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1379 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1380 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1381 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1382 | p->kind = Import_kind; |
| 1383 | p->v.Import.names = names; |
| 1384 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1385 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1386 | return p; |
| 1387 | } |
| 1388 | |
| 1389 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1390 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
| 1391 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1392 | { |
| 1393 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1394 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1395 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1396 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1397 | p->kind = ImportFrom_kind; |
| 1398 | p->v.ImportFrom.module = module; |
| 1399 | p->v.ImportFrom.names = names; |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 1400 | p->v.ImportFrom.level = level; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1401 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1402 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1403 | return p; |
| 1404 | } |
| 1405 | |
| 1406 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1407 | Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1408 | { |
| 1409 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1410 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1411 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1412 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1413 | p->kind = Global_kind; |
| 1414 | p->v.Global.names = names; |
| 1415 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1416 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1417 | return p; |
| 1418 | } |
| 1419 | |
| 1420 | stmt_ty |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 1421 | Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
| 1422 | { |
| 1423 | stmt_ty p; |
| 1424 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1425 | if (!p) |
| 1426 | return NULL; |
| 1427 | p->kind = Nonlocal_kind; |
| 1428 | p->v.Nonlocal.names = names; |
| 1429 | p->lineno = lineno; |
| 1430 | p->col_offset = col_offset; |
| 1431 | return p; |
| 1432 | } |
| 1433 | |
| 1434 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1435 | Expr(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1436 | { |
| 1437 | stmt_ty p; |
| 1438 | if (!value) { |
| 1439 | PyErr_SetString(PyExc_ValueError, |
| 1440 | "field value is required for Expr"); |
| 1441 | return NULL; |
| 1442 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1443 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1444 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1445 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1446 | p->kind = Expr_kind; |
| 1447 | p->v.Expr.value = value; |
| 1448 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1449 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1450 | return p; |
| 1451 | } |
| 1452 | |
| 1453 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1454 | Pass(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1455 | { |
| 1456 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1457 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1458 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1459 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1460 | p->kind = Pass_kind; |
| 1461 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1462 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1463 | return p; |
| 1464 | } |
| 1465 | |
| 1466 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1467 | Break(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1468 | { |
| 1469 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1470 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1471 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1472 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1473 | p->kind = Break_kind; |
| 1474 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1475 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1476 | return p; |
| 1477 | } |
| 1478 | |
| 1479 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1480 | Continue(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1481 | { |
| 1482 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1483 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1484 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1485 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1486 | p->kind = Continue_kind; |
| 1487 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1488 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1489 | return p; |
| 1490 | } |
| 1491 | |
| 1492 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1493 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1494 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1495 | { |
| 1496 | expr_ty p; |
| 1497 | if (!op) { |
| 1498 | PyErr_SetString(PyExc_ValueError, |
| 1499 | "field op is required for BoolOp"); |
| 1500 | return NULL; |
| 1501 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1502 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1503 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1504 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1505 | p->kind = BoolOp_kind; |
| 1506 | p->v.BoolOp.op = op; |
| 1507 | p->v.BoolOp.values = values; |
| 1508 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1509 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1510 | return p; |
| 1511 | } |
| 1512 | |
| 1513 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1514 | BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset, |
| 1515 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1516 | { |
| 1517 | expr_ty p; |
| 1518 | if (!left) { |
| 1519 | PyErr_SetString(PyExc_ValueError, |
| 1520 | "field left is required for BinOp"); |
| 1521 | return NULL; |
| 1522 | } |
| 1523 | if (!op) { |
| 1524 | PyErr_SetString(PyExc_ValueError, |
| 1525 | "field op is required for BinOp"); |
| 1526 | return NULL; |
| 1527 | } |
| 1528 | if (!right) { |
| 1529 | PyErr_SetString(PyExc_ValueError, |
| 1530 | "field right is required for BinOp"); |
| 1531 | return NULL; |
| 1532 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1533 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1534 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1535 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1536 | p->kind = BinOp_kind; |
| 1537 | p->v.BinOp.left = left; |
| 1538 | p->v.BinOp.op = op; |
| 1539 | p->v.BinOp.right = right; |
| 1540 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1541 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1542 | return p; |
| 1543 | } |
| 1544 | |
| 1545 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1546 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena |
| 1547 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1548 | { |
| 1549 | expr_ty p; |
| 1550 | if (!op) { |
| 1551 | PyErr_SetString(PyExc_ValueError, |
| 1552 | "field op is required for UnaryOp"); |
| 1553 | return NULL; |
| 1554 | } |
| 1555 | if (!operand) { |
| 1556 | PyErr_SetString(PyExc_ValueError, |
| 1557 | "field operand is required for UnaryOp"); |
| 1558 | return NULL; |
| 1559 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1560 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1561 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1562 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1563 | p->kind = UnaryOp_kind; |
| 1564 | p->v.UnaryOp.op = op; |
| 1565 | p->v.UnaryOp.operand = operand; |
| 1566 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1567 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1568 | return p; |
| 1569 | } |
| 1570 | |
| 1571 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1572 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena |
| 1573 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1574 | { |
| 1575 | expr_ty p; |
| 1576 | if (!args) { |
| 1577 | PyErr_SetString(PyExc_ValueError, |
| 1578 | "field args is required for Lambda"); |
| 1579 | return NULL; |
| 1580 | } |
| 1581 | if (!body) { |
| 1582 | PyErr_SetString(PyExc_ValueError, |
| 1583 | "field body is required for Lambda"); |
| 1584 | return NULL; |
| 1585 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1586 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1587 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1588 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1589 | p->kind = Lambda_kind; |
| 1590 | p->v.Lambda.args = args; |
| 1591 | p->v.Lambda.body = body; |
| 1592 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1593 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1594 | return p; |
| 1595 | } |
| 1596 | |
| 1597 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1598 | IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset, |
| 1599 | PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1600 | { |
| 1601 | expr_ty p; |
| 1602 | if (!test) { |
| 1603 | PyErr_SetString(PyExc_ValueError, |
| 1604 | "field test is required for IfExp"); |
| 1605 | return NULL; |
| 1606 | } |
| 1607 | if (!body) { |
| 1608 | PyErr_SetString(PyExc_ValueError, |
| 1609 | "field body is required for IfExp"); |
| 1610 | return NULL; |
| 1611 | } |
| 1612 | if (!orelse) { |
| 1613 | PyErr_SetString(PyExc_ValueError, |
| 1614 | "field orelse is required for IfExp"); |
| 1615 | return NULL; |
| 1616 | } |
| 1617 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1618 | if (!p) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1619 | return NULL; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1620 | p->kind = IfExp_kind; |
| 1621 | p->v.IfExp.test = test; |
| 1622 | p->v.IfExp.body = body; |
| 1623 | p->v.IfExp.orelse = orelse; |
| 1624 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1625 | p->col_offset = col_offset; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1626 | return p; |
| 1627 | } |
| 1628 | |
| 1629 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1630 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1631 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1632 | { |
| 1633 | expr_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1634 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1635 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1636 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1637 | p->kind = Dict_kind; |
| 1638 | p->v.Dict.keys = keys; |
| 1639 | p->v.Dict.values = values; |
| 1640 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1641 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1642 | return p; |
| 1643 | } |
| 1644 | |
| 1645 | expr_ty |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1646 | Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena) |
| 1647 | { |
| 1648 | expr_ty p; |
| 1649 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1650 | if (!p) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1651 | return NULL; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1652 | p->kind = Set_kind; |
| 1653 | p->v.Set.elts = elts; |
| 1654 | p->lineno = lineno; |
| 1655 | p->col_offset = col_offset; |
| 1656 | return p; |
| 1657 | } |
| 1658 | |
| 1659 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1660 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1661 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1662 | { |
| 1663 | expr_ty p; |
| 1664 | if (!elt) { |
| 1665 | PyErr_SetString(PyExc_ValueError, |
| 1666 | "field elt is required for ListComp"); |
| 1667 | return NULL; |
| 1668 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1669 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1670 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1671 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1672 | p->kind = ListComp_kind; |
| 1673 | p->v.ListComp.elt = elt; |
| 1674 | p->v.ListComp.generators = generators; |
| 1675 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1676 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1677 | return p; |
| 1678 | } |
| 1679 | |
| 1680 | expr_ty |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 1681 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena |
| 1682 | *arena) |
| 1683 | { |
| 1684 | expr_ty p; |
| 1685 | if (!elt) { |
| 1686 | PyErr_SetString(PyExc_ValueError, |
| 1687 | "field elt is required for SetComp"); |
| 1688 | return NULL; |
| 1689 | } |
| 1690 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1691 | if (!p) |
| 1692 | return NULL; |
| 1693 | p->kind = SetComp_kind; |
| 1694 | p->v.SetComp.elt = elt; |
| 1695 | p->v.SetComp.generators = generators; |
| 1696 | p->lineno = lineno; |
| 1697 | p->col_offset = col_offset; |
| 1698 | return p; |
| 1699 | } |
| 1700 | |
| 1701 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 1702 | DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int |
| 1703 | col_offset, PyArena *arena) |
| 1704 | { |
| 1705 | expr_ty p; |
| 1706 | if (!key) { |
| 1707 | PyErr_SetString(PyExc_ValueError, |
| 1708 | "field key is required for DictComp"); |
| 1709 | return NULL; |
| 1710 | } |
| 1711 | if (!value) { |
| 1712 | PyErr_SetString(PyExc_ValueError, |
| 1713 | "field value is required for DictComp"); |
| 1714 | return NULL; |
| 1715 | } |
| 1716 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1717 | if (!p) |
| 1718 | return NULL; |
| 1719 | p->kind = DictComp_kind; |
| 1720 | p->v.DictComp.key = key; |
| 1721 | p->v.DictComp.value = value; |
| 1722 | p->v.DictComp.generators = generators; |
| 1723 | p->lineno = lineno; |
| 1724 | p->col_offset = col_offset; |
| 1725 | return p; |
| 1726 | } |
| 1727 | |
| 1728 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1729 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1730 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1731 | { |
| 1732 | expr_ty p; |
| 1733 | if (!elt) { |
| 1734 | PyErr_SetString(PyExc_ValueError, |
| 1735 | "field elt is required for GeneratorExp"); |
| 1736 | return NULL; |
| 1737 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1738 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1739 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1740 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1741 | p->kind = GeneratorExp_kind; |
| 1742 | p->v.GeneratorExp.elt = elt; |
| 1743 | p->v.GeneratorExp.generators = generators; |
| 1744 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1745 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1746 | return p; |
| 1747 | } |
| 1748 | |
| 1749 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1750 | Yield(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1751 | { |
| 1752 | expr_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1753 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1754 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1755 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1756 | p->kind = Yield_kind; |
| 1757 | p->v.Yield.value = value; |
| 1758 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1759 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1760 | return p; |
| 1761 | } |
| 1762 | |
| 1763 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1764 | Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno, |
| 1765 | int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1766 | { |
| 1767 | expr_ty p; |
| 1768 | if (!left) { |
| 1769 | PyErr_SetString(PyExc_ValueError, |
| 1770 | "field left is required for Compare"); |
| 1771 | return NULL; |
| 1772 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1773 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1774 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1775 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1776 | p->kind = Compare_kind; |
| 1777 | p->v.Compare.left = left; |
| 1778 | p->v.Compare.ops = ops; |
| 1779 | p->v.Compare.comparators = comparators; |
| 1780 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1781 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1782 | return p; |
| 1783 | } |
| 1784 | |
| 1785 | expr_ty |
| 1786 | 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] | 1787 | expr_ty kwargs, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1788 | { |
| 1789 | expr_ty p; |
| 1790 | if (!func) { |
| 1791 | PyErr_SetString(PyExc_ValueError, |
| 1792 | "field func is required for Call"); |
| 1793 | return NULL; |
| 1794 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1795 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1796 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1797 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1798 | p->kind = Call_kind; |
| 1799 | p->v.Call.func = func; |
| 1800 | p->v.Call.args = args; |
| 1801 | p->v.Call.keywords = keywords; |
| 1802 | p->v.Call.starargs = starargs; |
| 1803 | p->v.Call.kwargs = kwargs; |
| 1804 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1805 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1806 | return p; |
| 1807 | } |
| 1808 | |
| 1809 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1810 | Num(object n, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1811 | { |
| 1812 | expr_ty p; |
| 1813 | if (!n) { |
| 1814 | PyErr_SetString(PyExc_ValueError, |
| 1815 | "field n is required for Num"); |
| 1816 | return NULL; |
| 1817 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1818 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1819 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1820 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1821 | p->kind = Num_kind; |
| 1822 | p->v.Num.n = n; |
| 1823 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1824 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1825 | return p; |
| 1826 | } |
| 1827 | |
| 1828 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1829 | Str(string s, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1830 | { |
| 1831 | expr_ty p; |
| 1832 | if (!s) { |
| 1833 | PyErr_SetString(PyExc_ValueError, |
| 1834 | "field s is required for Str"); |
| 1835 | return NULL; |
| 1836 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1837 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1838 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1839 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1840 | p->kind = Str_kind; |
| 1841 | p->v.Str.s = s; |
| 1842 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1843 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1844 | return p; |
| 1845 | } |
| 1846 | |
| 1847 | expr_ty |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 1848 | Bytes(bytes s, int lineno, int col_offset, PyArena *arena) |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1849 | { |
| 1850 | expr_ty p; |
| 1851 | if (!s) { |
| 1852 | PyErr_SetString(PyExc_ValueError, |
| 1853 | "field s is required for Bytes"); |
| 1854 | return NULL; |
| 1855 | } |
| 1856 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1857 | if (!p) |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1858 | return NULL; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1859 | p->kind = Bytes_kind; |
| 1860 | p->v.Bytes.s = s; |
| 1861 | p->lineno = lineno; |
| 1862 | p->col_offset = col_offset; |
| 1863 | return p; |
| 1864 | } |
| 1865 | |
| 1866 | expr_ty |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1867 | Ellipsis(int lineno, int col_offset, PyArena *arena) |
| 1868 | { |
| 1869 | expr_ty p; |
| 1870 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1871 | if (!p) |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1872 | return NULL; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1873 | p->kind = Ellipsis_kind; |
| 1874 | p->lineno = lineno; |
| 1875 | p->col_offset = col_offset; |
| 1876 | return p; |
| 1877 | } |
| 1878 | |
| 1879 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1880 | Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int |
| 1881 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1882 | { |
| 1883 | expr_ty p; |
| 1884 | if (!value) { |
| 1885 | PyErr_SetString(PyExc_ValueError, |
| 1886 | "field value is required for Attribute"); |
| 1887 | return NULL; |
| 1888 | } |
| 1889 | if (!attr) { |
| 1890 | PyErr_SetString(PyExc_ValueError, |
| 1891 | "field attr is required for Attribute"); |
| 1892 | return NULL; |
| 1893 | } |
| 1894 | if (!ctx) { |
| 1895 | PyErr_SetString(PyExc_ValueError, |
| 1896 | "field ctx is required for Attribute"); |
| 1897 | return NULL; |
| 1898 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1899 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1900 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1901 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1902 | p->kind = Attribute_kind; |
| 1903 | p->v.Attribute.value = value; |
| 1904 | p->v.Attribute.attr = attr; |
| 1905 | p->v.Attribute.ctx = ctx; |
| 1906 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1907 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1908 | return p; |
| 1909 | } |
| 1910 | |
| 1911 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1912 | Subscript(expr_ty value, slice_ty slice, 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 Subscript"); |
| 1919 | return NULL; |
| 1920 | } |
| 1921 | if (!slice) { |
| 1922 | PyErr_SetString(PyExc_ValueError, |
| 1923 | "field slice is required for Subscript"); |
| 1924 | return NULL; |
| 1925 | } |
| 1926 | if (!ctx) { |
| 1927 | PyErr_SetString(PyExc_ValueError, |
| 1928 | "field ctx is required for Subscript"); |
| 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 = Subscript_kind; |
| 1935 | p->v.Subscript.value = value; |
| 1936 | p->v.Subscript.slice = slice; |
| 1937 | p->v.Subscript.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 |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 1944 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1945 | *arena) |
| 1946 | { |
| 1947 | expr_ty p; |
| 1948 | if (!value) { |
| 1949 | PyErr_SetString(PyExc_ValueError, |
| 1950 | "field value is required for Starred"); |
| 1951 | return NULL; |
| 1952 | } |
| 1953 | if (!ctx) { |
| 1954 | PyErr_SetString(PyExc_ValueError, |
| 1955 | "field ctx is required for Starred"); |
| 1956 | return NULL; |
| 1957 | } |
| 1958 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1959 | if (!p) |
| 1960 | return NULL; |
| 1961 | p->kind = Starred_kind; |
| 1962 | p->v.Starred.value = value; |
| 1963 | p->v.Starred.ctx = ctx; |
| 1964 | p->lineno = lineno; |
| 1965 | p->col_offset = col_offset; |
| 1966 | return p; |
| 1967 | } |
| 1968 | |
| 1969 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1970 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1971 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1972 | { |
| 1973 | expr_ty p; |
| 1974 | if (!id) { |
| 1975 | PyErr_SetString(PyExc_ValueError, |
| 1976 | "field id is required for Name"); |
| 1977 | return NULL; |
| 1978 | } |
| 1979 | if (!ctx) { |
| 1980 | PyErr_SetString(PyExc_ValueError, |
| 1981 | "field ctx is required for Name"); |
| 1982 | return NULL; |
| 1983 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1984 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1985 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1986 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1987 | p->kind = Name_kind; |
| 1988 | p->v.Name.id = id; |
| 1989 | p->v.Name.ctx = ctx; |
| 1990 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1991 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1992 | return p; |
| 1993 | } |
| 1994 | |
| 1995 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1996 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1997 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1998 | { |
| 1999 | expr_ty p; |
| 2000 | if (!ctx) { |
| 2001 | PyErr_SetString(PyExc_ValueError, |
| 2002 | "field ctx is required for List"); |
| 2003 | return NULL; |
| 2004 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2005 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2006 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2007 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2008 | p->kind = List_kind; |
| 2009 | p->v.List.elts = elts; |
| 2010 | p->v.List.ctx = ctx; |
| 2011 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2012 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2013 | return p; |
| 2014 | } |
| 2015 | |
| 2016 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2017 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 2018 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2019 | { |
| 2020 | expr_ty p; |
| 2021 | if (!ctx) { |
| 2022 | PyErr_SetString(PyExc_ValueError, |
| 2023 | "field ctx is required for Tuple"); |
| 2024 | return NULL; |
| 2025 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2026 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2027 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2028 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2029 | p->kind = Tuple_kind; |
| 2030 | p->v.Tuple.elts = elts; |
| 2031 | p->v.Tuple.ctx = ctx; |
| 2032 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2033 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2034 | return p; |
| 2035 | } |
| 2036 | |
| 2037 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2038 | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2039 | { |
| 2040 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2041 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2042 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2043 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2044 | p->kind = Slice_kind; |
| 2045 | p->v.Slice.lower = lower; |
| 2046 | p->v.Slice.upper = upper; |
| 2047 | p->v.Slice.step = step; |
| 2048 | return p; |
| 2049 | } |
| 2050 | |
| 2051 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2052 | ExtSlice(asdl_seq * dims, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2053 | { |
| 2054 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2055 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2056 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2057 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2058 | p->kind = ExtSlice_kind; |
| 2059 | p->v.ExtSlice.dims = dims; |
| 2060 | return p; |
| 2061 | } |
| 2062 | |
| 2063 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2064 | Index(expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2065 | { |
| 2066 | slice_ty p; |
| 2067 | if (!value) { |
| 2068 | PyErr_SetString(PyExc_ValueError, |
| 2069 | "field value is required for Index"); |
| 2070 | return NULL; |
| 2071 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2072 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2073 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2074 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2075 | p->kind = Index_kind; |
| 2076 | p->v.Index.value = value; |
| 2077 | return p; |
| 2078 | } |
| 2079 | |
| 2080 | comprehension_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2081 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2082 | { |
| 2083 | comprehension_ty p; |
| 2084 | if (!target) { |
| 2085 | PyErr_SetString(PyExc_ValueError, |
| 2086 | "field target is required for comprehension"); |
| 2087 | return NULL; |
| 2088 | } |
| 2089 | if (!iter) { |
| 2090 | PyErr_SetString(PyExc_ValueError, |
| 2091 | "field iter is required for comprehension"); |
| 2092 | return NULL; |
| 2093 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2094 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2095 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2096 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2097 | p->target = target; |
| 2098 | p->iter = iter; |
| 2099 | p->ifs = ifs; |
| 2100 | return p; |
| 2101 | } |
| 2102 | |
| 2103 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 2104 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2105 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2106 | { |
| 2107 | excepthandler_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2108 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2109 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2110 | return NULL; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 2111 | p->kind = ExceptHandler_kind; |
| 2112 | p->v.ExceptHandler.type = type; |
| 2113 | p->v.ExceptHandler.name = name; |
| 2114 | p->v.ExceptHandler.body = body; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2115 | p->lineno = lineno; |
| 2116 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2117 | return p; |
| 2118 | } |
| 2119 | |
| 2120 | arguments_ty |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2121 | arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation, |
| 2122 | asdl_seq * kwonlyargs, identifier kwarg, expr_ty kwargannotation, |
| 2123 | asdl_seq * defaults, asdl_seq * kw_defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2124 | { |
| 2125 | arguments_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2126 | p = (arguments_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->args = args; |
| 2130 | p->vararg = vararg; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2131 | p->varargannotation = varargannotation; |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 2132 | p->kwonlyargs = kwonlyargs; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2133 | p->kwarg = kwarg; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2134 | p->kwargannotation = kwargannotation; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2135 | p->defaults = defaults; |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 2136 | p->kw_defaults = kw_defaults; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2137 | return p; |
| 2138 | } |
| 2139 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2140 | arg_ty |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2141 | arg(identifier arg, expr_ty annotation, PyArena *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2142 | { |
| 2143 | arg_ty p; |
| 2144 | if (!arg) { |
| 2145 | PyErr_SetString(PyExc_ValueError, |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2146 | "field arg is required for arg"); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2147 | return NULL; |
| 2148 | } |
| 2149 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2150 | if (!p) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2151 | return NULL; |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2152 | p->arg = arg; |
| 2153 | p->annotation = annotation; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2154 | return p; |
| 2155 | } |
| 2156 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2157 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2158 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2159 | { |
| 2160 | keyword_ty p; |
| 2161 | if (!arg) { |
| 2162 | PyErr_SetString(PyExc_ValueError, |
| 2163 | "field arg is required for keyword"); |
| 2164 | return NULL; |
| 2165 | } |
| 2166 | if (!value) { |
| 2167 | PyErr_SetString(PyExc_ValueError, |
| 2168 | "field value is required for keyword"); |
| 2169 | return NULL; |
| 2170 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2171 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2172 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2173 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2174 | p->arg = arg; |
| 2175 | p->value = value; |
| 2176 | return p; |
| 2177 | } |
| 2178 | |
| 2179 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2180 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2181 | { |
| 2182 | alias_ty p; |
| 2183 | if (!name) { |
| 2184 | PyErr_SetString(PyExc_ValueError, |
| 2185 | "field name is required for alias"); |
| 2186 | return NULL; |
| 2187 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2188 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2189 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2190 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2191 | p->name = name; |
| 2192 | p->asname = asname; |
| 2193 | return p; |
| 2194 | } |
| 2195 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2196 | withitem_ty |
| 2197 | withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) |
| 2198 | { |
| 2199 | withitem_ty p; |
| 2200 | if (!context_expr) { |
| 2201 | PyErr_SetString(PyExc_ValueError, |
| 2202 | "field context_expr is required for withitem"); |
| 2203 | return NULL; |
| 2204 | } |
| 2205 | p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2206 | if (!p) |
| 2207 | return NULL; |
| 2208 | p->context_expr = context_expr; |
| 2209 | p->optional_vars = optional_vars; |
| 2210 | return p; |
| 2211 | } |
| 2212 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2213 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2214 | PyObject* |
| 2215 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2216 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2217 | mod_ty o = (mod_ty)_o; |
| 2218 | PyObject *result = NULL, *value = NULL; |
| 2219 | if (!o) { |
| 2220 | Py_INCREF(Py_None); |
| 2221 | return Py_None; |
| 2222 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2223 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2224 | switch (o->kind) { |
| 2225 | case Module_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2226 | result = PyType_GenericNew(Module_type, NULL, NULL); |
| 2227 | if (!result) goto failed; |
| 2228 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 2229 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2230 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2231 | goto failed; |
| 2232 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2233 | break; |
| 2234 | case Interactive_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2235 | result = PyType_GenericNew(Interactive_type, NULL, NULL); |
| 2236 | if (!result) goto failed; |
| 2237 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 2238 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2239 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2240 | goto failed; |
| 2241 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2242 | break; |
| 2243 | case Expression_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2244 | result = PyType_GenericNew(Expression_type, NULL, NULL); |
| 2245 | if (!result) goto failed; |
| 2246 | value = ast2obj_expr(o->v.Expression.body); |
| 2247 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2248 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2249 | goto failed; |
| 2250 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2251 | break; |
| 2252 | case Suite_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2253 | result = PyType_GenericNew(Suite_type, NULL, NULL); |
| 2254 | if (!result) goto failed; |
| 2255 | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
| 2256 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2257 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2258 | goto failed; |
| 2259 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2260 | break; |
| 2261 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2262 | return result; |
| 2263 | failed: |
| 2264 | Py_XDECREF(value); |
| 2265 | Py_XDECREF(result); |
| 2266 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2267 | } |
| 2268 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2269 | PyObject* |
| 2270 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2271 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2272 | stmt_ty o = (stmt_ty)_o; |
| 2273 | PyObject *result = NULL, *value = NULL; |
| 2274 | if (!o) { |
| 2275 | Py_INCREF(Py_None); |
| 2276 | return Py_None; |
| 2277 | } |
| 2278 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2279 | switch (o->kind) { |
| 2280 | case FunctionDef_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2281 | result = PyType_GenericNew(FunctionDef_type, NULL, NULL); |
| 2282 | if (!result) goto failed; |
| 2283 | value = ast2obj_identifier(o->v.FunctionDef.name); |
| 2284 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2285 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2286 | goto failed; |
| 2287 | Py_DECREF(value); |
| 2288 | value = ast2obj_arguments(o->v.FunctionDef.args); |
| 2289 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2290 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2291 | goto failed; |
| 2292 | Py_DECREF(value); |
| 2293 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 2294 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2295 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2296 | goto failed; |
| 2297 | Py_DECREF(value); |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2298 | value = ast2obj_list(o->v.FunctionDef.decorator_list, |
| 2299 | ast2obj_expr); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2300 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2301 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2302 | -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2303 | goto failed; |
| 2304 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2305 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 2306 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2307 | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2308 | goto failed; |
| 2309 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2310 | break; |
| 2311 | case ClassDef_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2312 | result = PyType_GenericNew(ClassDef_type, NULL, NULL); |
| 2313 | if (!result) goto failed; |
| 2314 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 2315 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2316 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2317 | goto failed; |
| 2318 | Py_DECREF(value); |
| 2319 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 2320 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2321 | if (_PyObject_SetAttrId(result, &PyId_bases, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2322 | goto failed; |
| 2323 | Py_DECREF(value); |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 2324 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 2325 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2326 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 2327 | goto failed; |
| 2328 | Py_DECREF(value); |
| 2329 | value = ast2obj_expr(o->v.ClassDef.starargs); |
| 2330 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2331 | if (_PyObject_SetAttrId(result, &PyId_starargs, value) == -1) |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 2332 | goto failed; |
| 2333 | Py_DECREF(value); |
| 2334 | value = ast2obj_expr(o->v.ClassDef.kwargs); |
| 2335 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2336 | if (_PyObject_SetAttrId(result, &PyId_kwargs, value) == -1) |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 2337 | goto failed; |
| 2338 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2339 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 2340 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2341 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2342 | goto failed; |
| 2343 | Py_DECREF(value); |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2344 | value = ast2obj_list(o->v.ClassDef.decorator_list, |
| 2345 | ast2obj_expr); |
| 2346 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2347 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2348 | -1) |
| 2349 | goto failed; |
| 2350 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2351 | break; |
| 2352 | case Return_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2353 | result = PyType_GenericNew(Return_type, NULL, NULL); |
| 2354 | if (!result) goto failed; |
| 2355 | value = ast2obj_expr(o->v.Return.value); |
| 2356 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2357 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2358 | goto failed; |
| 2359 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2360 | break; |
| 2361 | case Delete_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2362 | result = PyType_GenericNew(Delete_type, NULL, NULL); |
| 2363 | if (!result) goto failed; |
| 2364 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 2365 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2366 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2367 | goto failed; |
| 2368 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2369 | break; |
| 2370 | case Assign_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2371 | result = PyType_GenericNew(Assign_type, NULL, NULL); |
| 2372 | if (!result) goto failed; |
| 2373 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 2374 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2375 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2376 | goto failed; |
| 2377 | Py_DECREF(value); |
| 2378 | value = ast2obj_expr(o->v.Assign.value); |
| 2379 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2380 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2381 | goto failed; |
| 2382 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2383 | break; |
| 2384 | case AugAssign_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2385 | result = PyType_GenericNew(AugAssign_type, NULL, NULL); |
| 2386 | if (!result) goto failed; |
| 2387 | value = ast2obj_expr(o->v.AugAssign.target); |
| 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_target, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2390 | goto failed; |
| 2391 | Py_DECREF(value); |
| 2392 | value = ast2obj_operator(o->v.AugAssign.op); |
| 2393 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2394 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2395 | goto failed; |
| 2396 | Py_DECREF(value); |
| 2397 | value = ast2obj_expr(o->v.AugAssign.value); |
| 2398 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2399 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2400 | goto failed; |
| 2401 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2402 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2403 | case For_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2404 | result = PyType_GenericNew(For_type, NULL, NULL); |
| 2405 | if (!result) goto failed; |
| 2406 | value = ast2obj_expr(o->v.For.target); |
| 2407 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2408 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2409 | goto failed; |
| 2410 | Py_DECREF(value); |
| 2411 | value = ast2obj_expr(o->v.For.iter); |
| 2412 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2413 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2414 | goto failed; |
| 2415 | Py_DECREF(value); |
| 2416 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 2417 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2418 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2419 | goto failed; |
| 2420 | Py_DECREF(value); |
| 2421 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 2422 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2423 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2424 | goto failed; |
| 2425 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2426 | break; |
| 2427 | case While_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2428 | result = PyType_GenericNew(While_type, NULL, NULL); |
| 2429 | if (!result) goto failed; |
| 2430 | value = ast2obj_expr(o->v.While.test); |
| 2431 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2432 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2433 | goto failed; |
| 2434 | Py_DECREF(value); |
| 2435 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 2436 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2437 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2438 | goto failed; |
| 2439 | Py_DECREF(value); |
| 2440 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 2441 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2442 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2443 | goto failed; |
| 2444 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2445 | break; |
| 2446 | case If_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2447 | result = PyType_GenericNew(If_type, NULL, NULL); |
| 2448 | if (!result) goto failed; |
| 2449 | value = ast2obj_expr(o->v.If.test); |
| 2450 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2451 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2452 | goto failed; |
| 2453 | Py_DECREF(value); |
| 2454 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 2455 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2456 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2457 | goto failed; |
| 2458 | Py_DECREF(value); |
| 2459 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 2460 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2461 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2462 | goto failed; |
| 2463 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2464 | break; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2465 | case With_kind: |
| 2466 | result = PyType_GenericNew(With_type, NULL, NULL); |
| 2467 | if (!result) goto failed; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2468 | value = ast2obj_list(o->v.With.items, ast2obj_withitem); |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2469 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2470 | if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2471 | goto failed; |
| 2472 | Py_DECREF(value); |
| 2473 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 2474 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2475 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2476 | goto failed; |
| 2477 | Py_DECREF(value); |
| 2478 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2479 | case Raise_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2480 | result = PyType_GenericNew(Raise_type, NULL, NULL); |
| 2481 | if (!result) goto failed; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2482 | value = ast2obj_expr(o->v.Raise.exc); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2483 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2484 | if (_PyObject_SetAttrId(result, &PyId_exc, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2485 | goto failed; |
| 2486 | Py_DECREF(value); |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2487 | value = ast2obj_expr(o->v.Raise.cause); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2488 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2489 | if (_PyObject_SetAttrId(result, &PyId_cause, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2490 | goto failed; |
| 2491 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2492 | break; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2493 | case Try_kind: |
| 2494 | result = PyType_GenericNew(Try_type, NULL, NULL); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2495 | if (!result) goto failed; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2496 | value = ast2obj_list(o->v.Try.body, ast2obj_stmt); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2497 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2498 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2499 | goto failed; |
| 2500 | Py_DECREF(value); |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2501 | value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2502 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2503 | if (_PyObject_SetAttrId(result, &PyId_handlers, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2504 | goto failed; |
| 2505 | Py_DECREF(value); |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2506 | value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2507 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2508 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2509 | goto failed; |
| 2510 | Py_DECREF(value); |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2511 | value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2512 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2513 | if (_PyObject_SetAttrId(result, &PyId_finalbody, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2514 | goto failed; |
| 2515 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2516 | break; |
| 2517 | case Assert_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2518 | result = PyType_GenericNew(Assert_type, NULL, NULL); |
| 2519 | if (!result) goto failed; |
| 2520 | value = ast2obj_expr(o->v.Assert.test); |
| 2521 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2522 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2523 | goto failed; |
| 2524 | Py_DECREF(value); |
| 2525 | value = ast2obj_expr(o->v.Assert.msg); |
| 2526 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2527 | if (_PyObject_SetAttrId(result, &PyId_msg, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2528 | goto failed; |
| 2529 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2530 | break; |
| 2531 | case Import_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2532 | result = PyType_GenericNew(Import_type, NULL, NULL); |
| 2533 | if (!result) goto failed; |
| 2534 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 2535 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2536 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2537 | goto failed; |
| 2538 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2539 | break; |
| 2540 | case ImportFrom_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2541 | result = PyType_GenericNew(ImportFrom_type, NULL, NULL); |
| 2542 | if (!result) goto failed; |
| 2543 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 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_module, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2546 | goto failed; |
| 2547 | Py_DECREF(value); |
| 2548 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 2549 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2550 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2551 | goto failed; |
| 2552 | Py_DECREF(value); |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 2553 | value = ast2obj_int(o->v.ImportFrom.level); |
| 2554 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2555 | if (_PyObject_SetAttrId(result, &PyId_level, value) == -1) |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 2556 | goto failed; |
| 2557 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2558 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2559 | case Global_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2560 | result = PyType_GenericNew(Global_type, NULL, NULL); |
| 2561 | if (!result) goto failed; |
| 2562 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 2563 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2564 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2565 | goto failed; |
| 2566 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2567 | break; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2568 | case Nonlocal_kind: |
| 2569 | result = PyType_GenericNew(Nonlocal_type, NULL, NULL); |
| 2570 | if (!result) goto failed; |
| 2571 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 2572 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2573 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2574 | goto failed; |
| 2575 | Py_DECREF(value); |
| 2576 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2577 | case Expr_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2578 | result = PyType_GenericNew(Expr_type, NULL, NULL); |
| 2579 | if (!result) goto failed; |
| 2580 | value = ast2obj_expr(o->v.Expr.value); |
| 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_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2583 | goto failed; |
| 2584 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2585 | break; |
| 2586 | case Pass_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2587 | result = PyType_GenericNew(Pass_type, NULL, NULL); |
| 2588 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2589 | break; |
| 2590 | case Break_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2591 | result = PyType_GenericNew(Break_type, NULL, NULL); |
| 2592 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2593 | break; |
| 2594 | case Continue_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2595 | result = PyType_GenericNew(Continue_type, NULL, NULL); |
| 2596 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2597 | break; |
| 2598 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2599 | value = ast2obj_int(o->lineno); |
| 2600 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2601 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2602 | goto failed; |
| 2603 | Py_DECREF(value); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2604 | value = ast2obj_int(o->col_offset); |
| 2605 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2606 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2607 | goto failed; |
| 2608 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2609 | return result; |
| 2610 | failed: |
| 2611 | Py_XDECREF(value); |
| 2612 | Py_XDECREF(result); |
| 2613 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2614 | } |
| 2615 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2616 | PyObject* |
| 2617 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2618 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2619 | expr_ty o = (expr_ty)_o; |
| 2620 | PyObject *result = NULL, *value = NULL; |
| 2621 | if (!o) { |
| 2622 | Py_INCREF(Py_None); |
| 2623 | return Py_None; |
| 2624 | } |
| 2625 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2626 | switch (o->kind) { |
| 2627 | case BoolOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2628 | result = PyType_GenericNew(BoolOp_type, NULL, NULL); |
| 2629 | if (!result) goto failed; |
| 2630 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 2631 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2632 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2633 | goto failed; |
| 2634 | Py_DECREF(value); |
| 2635 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 2636 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2637 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2638 | goto failed; |
| 2639 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2640 | break; |
| 2641 | case BinOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2642 | result = PyType_GenericNew(BinOp_type, NULL, NULL); |
| 2643 | if (!result) goto failed; |
| 2644 | value = ast2obj_expr(o->v.BinOp.left); |
| 2645 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2646 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2647 | goto failed; |
| 2648 | Py_DECREF(value); |
| 2649 | value = ast2obj_operator(o->v.BinOp.op); |
| 2650 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2651 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2652 | goto failed; |
| 2653 | Py_DECREF(value); |
| 2654 | value = ast2obj_expr(o->v.BinOp.right); |
| 2655 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2656 | if (_PyObject_SetAttrId(result, &PyId_right, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2657 | goto failed; |
| 2658 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2659 | break; |
| 2660 | case UnaryOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2661 | result = PyType_GenericNew(UnaryOp_type, NULL, NULL); |
| 2662 | if (!result) goto failed; |
| 2663 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 2664 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2665 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2666 | goto failed; |
| 2667 | Py_DECREF(value); |
| 2668 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 2669 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2670 | if (_PyObject_SetAttrId(result, &PyId_operand, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2671 | goto failed; |
| 2672 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2673 | break; |
| 2674 | case Lambda_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2675 | result = PyType_GenericNew(Lambda_type, NULL, NULL); |
| 2676 | if (!result) goto failed; |
| 2677 | value = ast2obj_arguments(o->v.Lambda.args); |
| 2678 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2679 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2680 | goto failed; |
| 2681 | Py_DECREF(value); |
| 2682 | value = ast2obj_expr(o->v.Lambda.body); |
| 2683 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2684 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2685 | goto failed; |
| 2686 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2687 | break; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2688 | case IfExp_kind: |
| 2689 | result = PyType_GenericNew(IfExp_type, NULL, NULL); |
| 2690 | if (!result) goto failed; |
| 2691 | value = ast2obj_expr(o->v.IfExp.test); |
| 2692 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2693 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2694 | goto failed; |
| 2695 | Py_DECREF(value); |
| 2696 | value = ast2obj_expr(o->v.IfExp.body); |
| 2697 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2698 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2699 | goto failed; |
| 2700 | Py_DECREF(value); |
| 2701 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 2702 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2703 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2704 | goto failed; |
| 2705 | Py_DECREF(value); |
| 2706 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2707 | case Dict_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2708 | result = PyType_GenericNew(Dict_type, NULL, NULL); |
| 2709 | if (!result) goto failed; |
| 2710 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 2711 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2712 | if (_PyObject_SetAttrId(result, &PyId_keys, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2713 | goto failed; |
| 2714 | Py_DECREF(value); |
| 2715 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 2716 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2717 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2718 | goto failed; |
| 2719 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2720 | break; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2721 | case Set_kind: |
| 2722 | result = PyType_GenericNew(Set_type, NULL, NULL); |
| 2723 | if (!result) goto failed; |
| 2724 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 2725 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2726 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2727 | goto failed; |
| 2728 | Py_DECREF(value); |
| 2729 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2730 | case ListComp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2731 | result = PyType_GenericNew(ListComp_type, NULL, NULL); |
| 2732 | if (!result) goto failed; |
| 2733 | value = ast2obj_expr(o->v.ListComp.elt); |
| 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_elt, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2736 | goto failed; |
| 2737 | Py_DECREF(value); |
| 2738 | value = ast2obj_list(o->v.ListComp.generators, |
| 2739 | ast2obj_comprehension); |
| 2740 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2741 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2742 | goto failed; |
| 2743 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2744 | break; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2745 | case SetComp_kind: |
| 2746 | result = PyType_GenericNew(SetComp_type, NULL, NULL); |
| 2747 | if (!result) goto failed; |
| 2748 | value = ast2obj_expr(o->v.SetComp.elt); |
| 2749 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2750 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2751 | goto failed; |
| 2752 | Py_DECREF(value); |
| 2753 | value = ast2obj_list(o->v.SetComp.generators, |
| 2754 | ast2obj_comprehension); |
| 2755 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2756 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2757 | goto failed; |
| 2758 | Py_DECREF(value); |
| 2759 | break; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2760 | case DictComp_kind: |
| 2761 | result = PyType_GenericNew(DictComp_type, NULL, NULL); |
| 2762 | if (!result) goto failed; |
| 2763 | value = ast2obj_expr(o->v.DictComp.key); |
| 2764 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2765 | if (_PyObject_SetAttrId(result, &PyId_key, value) == -1) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2766 | goto failed; |
| 2767 | Py_DECREF(value); |
| 2768 | value = ast2obj_expr(o->v.DictComp.value); |
| 2769 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2770 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2771 | goto failed; |
| 2772 | Py_DECREF(value); |
| 2773 | value = ast2obj_list(o->v.DictComp.generators, |
| 2774 | ast2obj_comprehension); |
| 2775 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2776 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2777 | goto failed; |
| 2778 | Py_DECREF(value); |
| 2779 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2780 | case GeneratorExp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2781 | result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); |
| 2782 | if (!result) goto failed; |
| 2783 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 2784 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2785 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2786 | goto failed; |
| 2787 | Py_DECREF(value); |
| 2788 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 2789 | ast2obj_comprehension); |
| 2790 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2791 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2792 | goto failed; |
| 2793 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2794 | break; |
| 2795 | case Yield_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2796 | result = PyType_GenericNew(Yield_type, NULL, NULL); |
| 2797 | if (!result) goto failed; |
| 2798 | value = ast2obj_expr(o->v.Yield.value); |
| 2799 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2800 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2801 | goto failed; |
| 2802 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2803 | break; |
| 2804 | case Compare_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2805 | result = PyType_GenericNew(Compare_type, NULL, NULL); |
| 2806 | if (!result) goto failed; |
| 2807 | value = ast2obj_expr(o->v.Compare.left); |
| 2808 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2809 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2810 | goto failed; |
| 2811 | Py_DECREF(value); |
Martin v. Löwis | ce1d5d2 | 2006-02-26 20:51:25 +0000 | [diff] [blame] | 2812 | { |
| 2813 | int i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 2814 | value = PyList_New(n); |
| 2815 | if (!value) goto failed; |
| 2816 | for(i = 0; i < n; i++) |
| 2817 | PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i))); |
| 2818 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2819 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2820 | if (_PyObject_SetAttrId(result, &PyId_ops, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2821 | goto failed; |
| 2822 | Py_DECREF(value); |
| 2823 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
| 2824 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2825 | if (_PyObject_SetAttrId(result, &PyId_comparators, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2826 | goto failed; |
| 2827 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2828 | break; |
| 2829 | case Call_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2830 | result = PyType_GenericNew(Call_type, NULL, NULL); |
| 2831 | if (!result) goto failed; |
| 2832 | value = ast2obj_expr(o->v.Call.func); |
| 2833 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2834 | if (_PyObject_SetAttrId(result, &PyId_func, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2835 | goto failed; |
| 2836 | Py_DECREF(value); |
| 2837 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 2838 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2839 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2840 | goto failed; |
| 2841 | Py_DECREF(value); |
| 2842 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 2843 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2844 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2845 | goto failed; |
| 2846 | Py_DECREF(value); |
| 2847 | value = ast2obj_expr(o->v.Call.starargs); |
| 2848 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2849 | if (_PyObject_SetAttrId(result, &PyId_starargs, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2850 | goto failed; |
| 2851 | Py_DECREF(value); |
| 2852 | value = ast2obj_expr(o->v.Call.kwargs); |
| 2853 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2854 | if (_PyObject_SetAttrId(result, &PyId_kwargs, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2855 | goto failed; |
| 2856 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2857 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2858 | case Num_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2859 | result = PyType_GenericNew(Num_type, NULL, NULL); |
| 2860 | if (!result) goto failed; |
| 2861 | value = ast2obj_object(o->v.Num.n); |
| 2862 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2863 | if (_PyObject_SetAttrId(result, &PyId_n, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2864 | goto failed; |
| 2865 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2866 | break; |
| 2867 | case Str_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2868 | result = PyType_GenericNew(Str_type, NULL, NULL); |
| 2869 | if (!result) goto failed; |
| 2870 | value = ast2obj_string(o->v.Str.s); |
| 2871 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2872 | if (_PyObject_SetAttrId(result, &PyId_s, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2873 | goto failed; |
| 2874 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2875 | break; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 2876 | case Bytes_kind: |
| 2877 | result = PyType_GenericNew(Bytes_type, NULL, NULL); |
| 2878 | if (!result) goto failed; |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 2879 | value = ast2obj_bytes(o->v.Bytes.s); |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 2880 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2881 | if (_PyObject_SetAttrId(result, &PyId_s, value) == -1) |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 2882 | goto failed; |
| 2883 | Py_DECREF(value); |
| 2884 | break; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 2885 | case Ellipsis_kind: |
| 2886 | result = PyType_GenericNew(Ellipsis_type, NULL, NULL); |
| 2887 | if (!result) goto failed; |
| 2888 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2889 | case Attribute_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2890 | result = PyType_GenericNew(Attribute_type, NULL, NULL); |
| 2891 | if (!result) goto failed; |
| 2892 | value = ast2obj_expr(o->v.Attribute.value); |
| 2893 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2894 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2895 | goto failed; |
| 2896 | Py_DECREF(value); |
| 2897 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 2898 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2899 | if (_PyObject_SetAttrId(result, &PyId_attr, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2900 | goto failed; |
| 2901 | Py_DECREF(value); |
| 2902 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 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_ctx, 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 Subscript_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2909 | result = PyType_GenericNew(Subscript_type, NULL, NULL); |
| 2910 | if (!result) goto failed; |
| 2911 | value = ast2obj_expr(o->v.Subscript.value); |
| 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_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2914 | goto failed; |
| 2915 | Py_DECREF(value); |
| 2916 | value = ast2obj_slice(o->v.Subscript.slice); |
| 2917 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2918 | if (_PyObject_SetAttrId(result, &PyId_slice, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2919 | goto failed; |
| 2920 | Py_DECREF(value); |
| 2921 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 2922 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2923 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2924 | goto failed; |
| 2925 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2926 | break; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2927 | case Starred_kind: |
| 2928 | result = PyType_GenericNew(Starred_type, NULL, NULL); |
| 2929 | if (!result) goto failed; |
| 2930 | value = ast2obj_expr(o->v.Starred.value); |
| 2931 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2932 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2933 | goto failed; |
| 2934 | Py_DECREF(value); |
| 2935 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 2936 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2937 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2938 | goto failed; |
| 2939 | Py_DECREF(value); |
| 2940 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2941 | case Name_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2942 | result = PyType_GenericNew(Name_type, NULL, NULL); |
| 2943 | if (!result) goto failed; |
| 2944 | value = ast2obj_identifier(o->v.Name.id); |
| 2945 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2946 | if (_PyObject_SetAttrId(result, &PyId_id, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2947 | goto failed; |
| 2948 | Py_DECREF(value); |
| 2949 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 2950 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2951 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2952 | goto failed; |
| 2953 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2954 | break; |
| 2955 | case List_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2956 | result = PyType_GenericNew(List_type, NULL, NULL); |
| 2957 | if (!result) goto failed; |
| 2958 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 2959 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2960 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2961 | goto failed; |
| 2962 | Py_DECREF(value); |
| 2963 | value = ast2obj_expr_context(o->v.List.ctx); |
| 2964 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2965 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2966 | goto failed; |
| 2967 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2968 | break; |
| 2969 | case Tuple_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2970 | result = PyType_GenericNew(Tuple_type, NULL, NULL); |
| 2971 | if (!result) goto failed; |
| 2972 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 2973 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2974 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2975 | goto failed; |
| 2976 | Py_DECREF(value); |
| 2977 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 2978 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2979 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2980 | goto failed; |
| 2981 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2982 | break; |
| 2983 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2984 | value = ast2obj_int(o->lineno); |
| 2985 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2986 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2987 | goto failed; |
| 2988 | Py_DECREF(value); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2989 | value = ast2obj_int(o->col_offset); |
| 2990 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2991 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2992 | goto failed; |
| 2993 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2994 | return result; |
| 2995 | failed: |
| 2996 | Py_XDECREF(value); |
| 2997 | Py_XDECREF(result); |
| 2998 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2999 | } |
| 3000 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3001 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3002 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3003 | switch(o) { |
| 3004 | case Load: |
| 3005 | Py_INCREF(Load_singleton); |
| 3006 | return Load_singleton; |
| 3007 | case Store: |
| 3008 | Py_INCREF(Store_singleton); |
| 3009 | return Store_singleton; |
| 3010 | case Del: |
| 3011 | Py_INCREF(Del_singleton); |
| 3012 | return Del_singleton; |
| 3013 | case AugLoad: |
| 3014 | Py_INCREF(AugLoad_singleton); |
| 3015 | return AugLoad_singleton; |
| 3016 | case AugStore: |
| 3017 | Py_INCREF(AugStore_singleton); |
| 3018 | return AugStore_singleton; |
| 3019 | case Param: |
| 3020 | Py_INCREF(Param_singleton); |
| 3021 | return Param_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3022 | default: |
| 3023 | /* should never happen, but just in case ... */ |
| 3024 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 3025 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3026 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3027 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3028 | PyObject* |
| 3029 | ast2obj_slice(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3030 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3031 | slice_ty o = (slice_ty)_o; |
| 3032 | PyObject *result = NULL, *value = NULL; |
| 3033 | if (!o) { |
| 3034 | Py_INCREF(Py_None); |
| 3035 | return Py_None; |
| 3036 | } |
| 3037 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3038 | switch (o->kind) { |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3039 | case Slice_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3040 | result = PyType_GenericNew(Slice_type, NULL, NULL); |
| 3041 | if (!result) goto failed; |
| 3042 | value = ast2obj_expr(o->v.Slice.lower); |
| 3043 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3044 | if (_PyObject_SetAttrId(result, &PyId_lower, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3045 | goto failed; |
| 3046 | Py_DECREF(value); |
| 3047 | value = ast2obj_expr(o->v.Slice.upper); |
| 3048 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3049 | if (_PyObject_SetAttrId(result, &PyId_upper, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3050 | goto failed; |
| 3051 | Py_DECREF(value); |
| 3052 | value = ast2obj_expr(o->v.Slice.step); |
| 3053 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3054 | if (_PyObject_SetAttrId(result, &PyId_step, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3055 | goto failed; |
| 3056 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3057 | break; |
| 3058 | case ExtSlice_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3059 | result = PyType_GenericNew(ExtSlice_type, NULL, NULL); |
| 3060 | if (!result) goto failed; |
| 3061 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 3062 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3063 | if (_PyObject_SetAttrId(result, &PyId_dims, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3064 | goto failed; |
| 3065 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3066 | break; |
| 3067 | case Index_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3068 | result = PyType_GenericNew(Index_type, NULL, NULL); |
| 3069 | if (!result) goto failed; |
| 3070 | value = ast2obj_expr(o->v.Index.value); |
| 3071 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3072 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3073 | goto failed; |
| 3074 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3075 | break; |
| 3076 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3077 | return result; |
| 3078 | failed: |
| 3079 | Py_XDECREF(value); |
| 3080 | Py_XDECREF(result); |
| 3081 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3082 | } |
| 3083 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3084 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3085 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3086 | switch(o) { |
| 3087 | case And: |
| 3088 | Py_INCREF(And_singleton); |
| 3089 | return And_singleton; |
| 3090 | case Or: |
| 3091 | Py_INCREF(Or_singleton); |
| 3092 | return Or_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3093 | default: |
| 3094 | /* should never happen, but just in case ... */ |
| 3095 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 3096 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3097 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3098 | } |
| 3099 | PyObject* ast2obj_operator(operator_ty o) |
| 3100 | { |
| 3101 | switch(o) { |
| 3102 | case Add: |
| 3103 | Py_INCREF(Add_singleton); |
| 3104 | return Add_singleton; |
| 3105 | case Sub: |
| 3106 | Py_INCREF(Sub_singleton); |
| 3107 | return Sub_singleton; |
| 3108 | case Mult: |
| 3109 | Py_INCREF(Mult_singleton); |
| 3110 | return Mult_singleton; |
| 3111 | case Div: |
| 3112 | Py_INCREF(Div_singleton); |
| 3113 | return Div_singleton; |
| 3114 | case Mod: |
| 3115 | Py_INCREF(Mod_singleton); |
| 3116 | return Mod_singleton; |
| 3117 | case Pow: |
| 3118 | Py_INCREF(Pow_singleton); |
| 3119 | return Pow_singleton; |
| 3120 | case LShift: |
| 3121 | Py_INCREF(LShift_singleton); |
| 3122 | return LShift_singleton; |
| 3123 | case RShift: |
| 3124 | Py_INCREF(RShift_singleton); |
| 3125 | return RShift_singleton; |
| 3126 | case BitOr: |
| 3127 | Py_INCREF(BitOr_singleton); |
| 3128 | return BitOr_singleton; |
| 3129 | case BitXor: |
| 3130 | Py_INCREF(BitXor_singleton); |
| 3131 | return BitXor_singleton; |
| 3132 | case BitAnd: |
| 3133 | Py_INCREF(BitAnd_singleton); |
| 3134 | return BitAnd_singleton; |
| 3135 | case FloorDiv: |
| 3136 | Py_INCREF(FloorDiv_singleton); |
| 3137 | return FloorDiv_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3138 | default: |
| 3139 | /* should never happen, but just in case ... */ |
| 3140 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 3141 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3142 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3143 | } |
| 3144 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 3145 | { |
| 3146 | switch(o) { |
| 3147 | case Invert: |
| 3148 | Py_INCREF(Invert_singleton); |
| 3149 | return Invert_singleton; |
| 3150 | case Not: |
| 3151 | Py_INCREF(Not_singleton); |
| 3152 | return Not_singleton; |
| 3153 | case UAdd: |
| 3154 | Py_INCREF(UAdd_singleton); |
| 3155 | return UAdd_singleton; |
| 3156 | case USub: |
| 3157 | Py_INCREF(USub_singleton); |
| 3158 | return USub_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3159 | default: |
| 3160 | /* should never happen, but just in case ... */ |
| 3161 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 3162 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3163 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3164 | } |
| 3165 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 3166 | { |
| 3167 | switch(o) { |
| 3168 | case Eq: |
| 3169 | Py_INCREF(Eq_singleton); |
| 3170 | return Eq_singleton; |
| 3171 | case NotEq: |
| 3172 | Py_INCREF(NotEq_singleton); |
| 3173 | return NotEq_singleton; |
| 3174 | case Lt: |
| 3175 | Py_INCREF(Lt_singleton); |
| 3176 | return Lt_singleton; |
| 3177 | case LtE: |
| 3178 | Py_INCREF(LtE_singleton); |
| 3179 | return LtE_singleton; |
| 3180 | case Gt: |
| 3181 | Py_INCREF(Gt_singleton); |
| 3182 | return Gt_singleton; |
| 3183 | case GtE: |
| 3184 | Py_INCREF(GtE_singleton); |
| 3185 | return GtE_singleton; |
| 3186 | case Is: |
| 3187 | Py_INCREF(Is_singleton); |
| 3188 | return Is_singleton; |
| 3189 | case IsNot: |
| 3190 | Py_INCREF(IsNot_singleton); |
| 3191 | return IsNot_singleton; |
| 3192 | case In: |
| 3193 | Py_INCREF(In_singleton); |
| 3194 | return In_singleton; |
| 3195 | case NotIn: |
| 3196 | Py_INCREF(NotIn_singleton); |
| 3197 | return NotIn_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3198 | default: |
| 3199 | /* should never happen, but just in case ... */ |
| 3200 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 3201 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3202 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3203 | } |
| 3204 | PyObject* |
| 3205 | ast2obj_comprehension(void* _o) |
| 3206 | { |
| 3207 | comprehension_ty o = (comprehension_ty)_o; |
| 3208 | PyObject *result = NULL, *value = NULL; |
| 3209 | if (!o) { |
| 3210 | Py_INCREF(Py_None); |
| 3211 | return Py_None; |
| 3212 | } |
| 3213 | |
| 3214 | result = PyType_GenericNew(comprehension_type, NULL, NULL); |
| 3215 | if (!result) return NULL; |
| 3216 | value = ast2obj_expr(o->target); |
| 3217 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3218 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3219 | goto failed; |
| 3220 | Py_DECREF(value); |
| 3221 | value = ast2obj_expr(o->iter); |
| 3222 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3223 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3224 | goto failed; |
| 3225 | Py_DECREF(value); |
| 3226 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 3227 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3228 | if (_PyObject_SetAttrId(result, &PyId_ifs, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3229 | goto failed; |
| 3230 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3231 | return result; |
| 3232 | failed: |
| 3233 | Py_XDECREF(value); |
| 3234 | Py_XDECREF(result); |
| 3235 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3236 | } |
| 3237 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3238 | PyObject* |
| 3239 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3240 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3241 | excepthandler_ty o = (excepthandler_ty)_o; |
| 3242 | PyObject *result = NULL, *value = NULL; |
| 3243 | if (!o) { |
| 3244 | Py_INCREF(Py_None); |
| 3245 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3246 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3247 | |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3248 | switch (o->kind) { |
| 3249 | case ExceptHandler_kind: |
| 3250 | result = PyType_GenericNew(ExceptHandler_type, NULL, NULL); |
| 3251 | if (!result) goto failed; |
| 3252 | value = ast2obj_expr(o->v.ExceptHandler.type); |
| 3253 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3254 | if (_PyObject_SetAttrId(result, &PyId_type, value) == -1) |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3255 | goto failed; |
| 3256 | Py_DECREF(value); |
| 3257 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
| 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_name, value) == -1) |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3260 | goto failed; |
| 3261 | Py_DECREF(value); |
| 3262 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 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_body, value) == -1) |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3265 | goto failed; |
| 3266 | Py_DECREF(value); |
| 3267 | break; |
| 3268 | } |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3269 | value = ast2obj_int(o->lineno); |
| 3270 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3271 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3272 | goto failed; |
| 3273 | Py_DECREF(value); |
| 3274 | value = ast2obj_int(o->col_offset); |
| 3275 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3276 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3277 | goto failed; |
| 3278 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3279 | return result; |
| 3280 | failed: |
| 3281 | Py_XDECREF(value); |
| 3282 | Py_XDECREF(result); |
| 3283 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3284 | } |
| 3285 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3286 | PyObject* |
| 3287 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3288 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3289 | arguments_ty o = (arguments_ty)_o; |
| 3290 | PyObject *result = NULL, *value = NULL; |
| 3291 | if (!o) { |
| 3292 | Py_INCREF(Py_None); |
| 3293 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3294 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3295 | |
| 3296 | result = PyType_GenericNew(arguments_type, NULL, NULL); |
| 3297 | if (!result) return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3298 | value = ast2obj_list(o->args, ast2obj_arg); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 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_args, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3301 | goto failed; |
| 3302 | Py_DECREF(value); |
| 3303 | value = ast2obj_identifier(o->vararg); |
| 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_vararg, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3306 | goto failed; |
| 3307 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3308 | value = ast2obj_expr(o->varargannotation); |
| 3309 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3310 | if (_PyObject_SetAttrId(result, &PyId_varargannotation, value) == -1) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3311 | goto failed; |
| 3312 | Py_DECREF(value); |
| 3313 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 3314 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3315 | if (_PyObject_SetAttrId(result, &PyId_kwonlyargs, value) == -1) |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 3316 | goto failed; |
| 3317 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3318 | value = ast2obj_identifier(o->kwarg); |
| 3319 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3320 | if (_PyObject_SetAttrId(result, &PyId_kwarg, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3321 | goto failed; |
| 3322 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3323 | value = ast2obj_expr(o->kwargannotation); |
| 3324 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3325 | if (_PyObject_SetAttrId(result, &PyId_kwargannotation, value) == -1) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3326 | goto failed; |
| 3327 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3328 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 3329 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3330 | if (_PyObject_SetAttrId(result, &PyId_defaults, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3331 | goto failed; |
| 3332 | Py_DECREF(value); |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 3333 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
| 3334 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3335 | if (_PyObject_SetAttrId(result, &PyId_kw_defaults, value) == -1) |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 3336 | goto failed; |
| 3337 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3338 | return result; |
| 3339 | failed: |
| 3340 | Py_XDECREF(value); |
| 3341 | Py_XDECREF(result); |
| 3342 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3343 | } |
| 3344 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3345 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3346 | ast2obj_arg(void* _o) |
| 3347 | { |
| 3348 | arg_ty o = (arg_ty)_o; |
| 3349 | PyObject *result = NULL, *value = NULL; |
| 3350 | if (!o) { |
| 3351 | Py_INCREF(Py_None); |
| 3352 | return Py_None; |
| 3353 | } |
| 3354 | |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 3355 | result = PyType_GenericNew(arg_type, NULL, NULL); |
| 3356 | if (!result) return NULL; |
| 3357 | value = ast2obj_identifier(o->arg); |
| 3358 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3359 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 3360 | goto failed; |
| 3361 | Py_DECREF(value); |
| 3362 | value = ast2obj_expr(o->annotation); |
| 3363 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3364 | if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 3365 | goto failed; |
| 3366 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3367 | return result; |
| 3368 | failed: |
| 3369 | Py_XDECREF(value); |
| 3370 | Py_XDECREF(result); |
| 3371 | return NULL; |
| 3372 | } |
| 3373 | |
| 3374 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3375 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3376 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3377 | keyword_ty o = (keyword_ty)_o; |
| 3378 | PyObject *result = NULL, *value = NULL; |
| 3379 | if (!o) { |
| 3380 | Py_INCREF(Py_None); |
| 3381 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3382 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3383 | |
| 3384 | result = PyType_GenericNew(keyword_type, NULL, NULL); |
| 3385 | if (!result) return NULL; |
| 3386 | value = ast2obj_identifier(o->arg); |
| 3387 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3388 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3389 | goto failed; |
| 3390 | Py_DECREF(value); |
| 3391 | value = ast2obj_expr(o->value); |
| 3392 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3393 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3394 | goto failed; |
| 3395 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3396 | return result; |
| 3397 | failed: |
| 3398 | Py_XDECREF(value); |
| 3399 | Py_XDECREF(result); |
| 3400 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3401 | } |
| 3402 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3403 | PyObject* |
| 3404 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3405 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3406 | alias_ty o = (alias_ty)_o; |
| 3407 | PyObject *result = NULL, *value = NULL; |
| 3408 | if (!o) { |
| 3409 | Py_INCREF(Py_None); |
| 3410 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3411 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3412 | |
| 3413 | result = PyType_GenericNew(alias_type, NULL, NULL); |
| 3414 | if (!result) return NULL; |
| 3415 | value = ast2obj_identifier(o->name); |
| 3416 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3417 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3418 | goto failed; |
| 3419 | Py_DECREF(value); |
| 3420 | value = ast2obj_identifier(o->asname); |
| 3421 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3422 | if (_PyObject_SetAttrId(result, &PyId_asname, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3423 | goto failed; |
| 3424 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3425 | return result; |
| 3426 | failed: |
| 3427 | Py_XDECREF(value); |
| 3428 | Py_XDECREF(result); |
| 3429 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3430 | } |
| 3431 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3432 | PyObject* |
| 3433 | ast2obj_withitem(void* _o) |
| 3434 | { |
| 3435 | withitem_ty o = (withitem_ty)_o; |
| 3436 | PyObject *result = NULL, *value = NULL; |
| 3437 | if (!o) { |
| 3438 | Py_INCREF(Py_None); |
| 3439 | return Py_None; |
| 3440 | } |
| 3441 | |
| 3442 | result = PyType_GenericNew(withitem_type, NULL, NULL); |
| 3443 | if (!result) return NULL; |
| 3444 | value = ast2obj_expr(o->context_expr); |
| 3445 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3446 | if (_PyObject_SetAttrId(result, &PyId_context_expr, value) == -1) |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3447 | goto failed; |
| 3448 | Py_DECREF(value); |
| 3449 | value = ast2obj_expr(o->optional_vars); |
| 3450 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3451 | if (_PyObject_SetAttrId(result, &PyId_optional_vars, value) == -1) |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3452 | goto failed; |
| 3453 | Py_DECREF(value); |
| 3454 | return result; |
| 3455 | failed: |
| 3456 | Py_XDECREF(value); |
| 3457 | Py_XDECREF(result); |
| 3458 | return NULL; |
| 3459 | } |
| 3460 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3461 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3462 | int |
| 3463 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 3464 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3465 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3466 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 3467 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3468 | |
| 3469 | if (obj == Py_None) { |
| 3470 | *out = NULL; |
| 3471 | return 0; |
| 3472 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3473 | isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type); |
| 3474 | if (isinstance == -1) { |
| 3475 | return 1; |
| 3476 | } |
| 3477 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3478 | asdl_seq* body; |
| 3479 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3480 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3481 | int res; |
| 3482 | Py_ssize_t len; |
| 3483 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3484 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3485 | if (tmp == NULL) goto failed; |
| 3486 | if (!PyList_Check(tmp)) { |
| 3487 | PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3488 | goto failed; |
| 3489 | } |
| 3490 | len = PyList_GET_SIZE(tmp); |
| 3491 | body = asdl_seq_new(len, arena); |
| 3492 | if (body == NULL) goto failed; |
| 3493 | for (i = 0; i < len; i++) { |
| 3494 | stmt_ty value; |
| 3495 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3496 | if (res != 0) goto failed; |
| 3497 | asdl_seq_SET(body, i, value); |
| 3498 | } |
| 3499 | Py_XDECREF(tmp); |
| 3500 | tmp = NULL; |
| 3501 | } else { |
| 3502 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 3503 | return 1; |
| 3504 | } |
| 3505 | *out = Module(body, arena); |
| 3506 | if (*out == NULL) goto failed; |
| 3507 | return 0; |
| 3508 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3509 | isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type); |
| 3510 | if (isinstance == -1) { |
| 3511 | return 1; |
| 3512 | } |
| 3513 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3514 | asdl_seq* body; |
| 3515 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3516 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3517 | int res; |
| 3518 | Py_ssize_t len; |
| 3519 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3520 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3521 | if (tmp == NULL) goto failed; |
| 3522 | if (!PyList_Check(tmp)) { |
| 3523 | PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3524 | goto failed; |
| 3525 | } |
| 3526 | len = PyList_GET_SIZE(tmp); |
| 3527 | body = asdl_seq_new(len, arena); |
| 3528 | if (body == NULL) goto failed; |
| 3529 | for (i = 0; i < len; i++) { |
| 3530 | stmt_ty value; |
| 3531 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3532 | if (res != 0) goto failed; |
| 3533 | asdl_seq_SET(body, i, value); |
| 3534 | } |
| 3535 | Py_XDECREF(tmp); |
| 3536 | tmp = NULL; |
| 3537 | } else { |
| 3538 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 3539 | return 1; |
| 3540 | } |
| 3541 | *out = Interactive(body, arena); |
| 3542 | if (*out == NULL) goto failed; |
| 3543 | return 0; |
| 3544 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3545 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type); |
| 3546 | if (isinstance == -1) { |
| 3547 | return 1; |
| 3548 | } |
| 3549 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3550 | expr_ty body; |
| 3551 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3552 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3553 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3554 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3555 | if (tmp == NULL) goto failed; |
| 3556 | res = obj2ast_expr(tmp, &body, arena); |
| 3557 | if (res != 0) goto failed; |
| 3558 | Py_XDECREF(tmp); |
| 3559 | tmp = NULL; |
| 3560 | } else { |
| 3561 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 3562 | return 1; |
| 3563 | } |
| 3564 | *out = Expression(body, arena); |
| 3565 | if (*out == NULL) goto failed; |
| 3566 | return 0; |
| 3567 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3568 | isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type); |
| 3569 | if (isinstance == -1) { |
| 3570 | return 1; |
| 3571 | } |
| 3572 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3573 | asdl_seq* body; |
| 3574 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3575 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3576 | int res; |
| 3577 | Py_ssize_t len; |
| 3578 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3579 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3580 | if (tmp == NULL) goto failed; |
| 3581 | if (!PyList_Check(tmp)) { |
| 3582 | PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3583 | goto failed; |
| 3584 | } |
| 3585 | len = PyList_GET_SIZE(tmp); |
| 3586 | body = asdl_seq_new(len, arena); |
| 3587 | if (body == NULL) goto failed; |
| 3588 | for (i = 0; i < len; i++) { |
| 3589 | stmt_ty value; |
| 3590 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3591 | if (res != 0) goto failed; |
| 3592 | asdl_seq_SET(body, i, value); |
| 3593 | } |
| 3594 | Py_XDECREF(tmp); |
| 3595 | tmp = NULL; |
| 3596 | } else { |
| 3597 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite"); |
| 3598 | return 1; |
| 3599 | } |
| 3600 | *out = Suite(body, arena); |
| 3601 | if (*out == NULL) goto failed; |
| 3602 | return 0; |
| 3603 | } |
| 3604 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 3605 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
| 3606 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 3607 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3608 | return 1; |
| 3609 | } |
| 3610 | |
| 3611 | int |
| 3612 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 3613 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3614 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3615 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 3616 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3617 | int lineno; |
| 3618 | int col_offset; |
| 3619 | |
| 3620 | if (obj == Py_None) { |
| 3621 | *out = NULL; |
| 3622 | return 0; |
| 3623 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3624 | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3625 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3626 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3627 | if (tmp == NULL) goto failed; |
| 3628 | res = obj2ast_int(tmp, &lineno, arena); |
| 3629 | if (res != 0) goto failed; |
| 3630 | Py_XDECREF(tmp); |
| 3631 | tmp = NULL; |
| 3632 | } else { |
| 3633 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 3634 | return 1; |
| 3635 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3636 | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3637 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3638 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3639 | if (tmp == NULL) goto failed; |
| 3640 | res = obj2ast_int(tmp, &col_offset, arena); |
| 3641 | if (res != 0) goto failed; |
| 3642 | Py_XDECREF(tmp); |
| 3643 | tmp = NULL; |
| 3644 | } else { |
| 3645 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 3646 | return 1; |
| 3647 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3648 | isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type); |
| 3649 | if (isinstance == -1) { |
| 3650 | return 1; |
| 3651 | } |
| 3652 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3653 | identifier name; |
| 3654 | arguments_ty args; |
| 3655 | asdl_seq* body; |
| 3656 | asdl_seq* decorator_list; |
| 3657 | expr_ty returns; |
| 3658 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3659 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3660 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3661 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3662 | if (tmp == NULL) goto failed; |
| 3663 | res = obj2ast_identifier(tmp, &name, arena); |
| 3664 | if (res != 0) goto failed; |
| 3665 | Py_XDECREF(tmp); |
| 3666 | tmp = NULL; |
| 3667 | } else { |
| 3668 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 3669 | return 1; |
| 3670 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3671 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3672 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3673 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3674 | if (tmp == NULL) goto failed; |
| 3675 | res = obj2ast_arguments(tmp, &args, arena); |
| 3676 | if (res != 0) goto failed; |
| 3677 | Py_XDECREF(tmp); |
| 3678 | tmp = NULL; |
| 3679 | } else { |
| 3680 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 3681 | return 1; |
| 3682 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3683 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3684 | int res; |
| 3685 | Py_ssize_t len; |
| 3686 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3687 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3688 | if (tmp == NULL) goto failed; |
| 3689 | if (!PyList_Check(tmp)) { |
| 3690 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3691 | goto failed; |
| 3692 | } |
| 3693 | len = PyList_GET_SIZE(tmp); |
| 3694 | body = asdl_seq_new(len, arena); |
| 3695 | if (body == NULL) goto failed; |
| 3696 | for (i = 0; i < len; i++) { |
| 3697 | stmt_ty value; |
| 3698 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3699 | if (res != 0) goto failed; |
| 3700 | asdl_seq_SET(body, i, value); |
| 3701 | } |
| 3702 | Py_XDECREF(tmp); |
| 3703 | tmp = NULL; |
| 3704 | } else { |
| 3705 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 3706 | return 1; |
| 3707 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3708 | if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3709 | int res; |
| 3710 | Py_ssize_t len; |
| 3711 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3712 | tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3713 | if (tmp == NULL) goto failed; |
| 3714 | if (!PyList_Check(tmp)) { |
| 3715 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3716 | goto failed; |
| 3717 | } |
| 3718 | len = PyList_GET_SIZE(tmp); |
| 3719 | decorator_list = asdl_seq_new(len, arena); |
| 3720 | if (decorator_list == NULL) goto failed; |
| 3721 | for (i = 0; i < len; i++) { |
| 3722 | expr_ty value; |
| 3723 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3724 | if (res != 0) goto failed; |
| 3725 | asdl_seq_SET(decorator_list, i, value); |
| 3726 | } |
| 3727 | Py_XDECREF(tmp); |
| 3728 | tmp = NULL; |
| 3729 | } else { |
| 3730 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 3731 | return 1; |
| 3732 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3733 | if (_PyObject_HasAttrId(obj, &PyId_returns)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3734 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3735 | tmp = _PyObject_GetAttrId(obj, &PyId_returns); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3736 | if (tmp == NULL) goto failed; |
| 3737 | res = obj2ast_expr(tmp, &returns, arena); |
| 3738 | if (res != 0) goto failed; |
| 3739 | Py_XDECREF(tmp); |
| 3740 | tmp = NULL; |
| 3741 | } else { |
| 3742 | returns = NULL; |
| 3743 | } |
| 3744 | *out = FunctionDef(name, args, body, decorator_list, returns, |
| 3745 | lineno, col_offset, arena); |
| 3746 | if (*out == NULL) goto failed; |
| 3747 | return 0; |
| 3748 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3749 | isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type); |
| 3750 | if (isinstance == -1) { |
| 3751 | return 1; |
| 3752 | } |
| 3753 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3754 | identifier name; |
| 3755 | asdl_seq* bases; |
| 3756 | asdl_seq* keywords; |
| 3757 | expr_ty starargs; |
| 3758 | expr_ty kwargs; |
| 3759 | asdl_seq* body; |
| 3760 | asdl_seq* decorator_list; |
| 3761 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3762 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3763 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3764 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3765 | if (tmp == NULL) goto failed; |
| 3766 | res = obj2ast_identifier(tmp, &name, arena); |
| 3767 | if (res != 0) goto failed; |
| 3768 | Py_XDECREF(tmp); |
| 3769 | tmp = NULL; |
| 3770 | } else { |
| 3771 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 3772 | return 1; |
| 3773 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3774 | if (_PyObject_HasAttrId(obj, &PyId_bases)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3775 | int res; |
| 3776 | Py_ssize_t len; |
| 3777 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3778 | tmp = _PyObject_GetAttrId(obj, &PyId_bases); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3779 | if (tmp == NULL) goto failed; |
| 3780 | if (!PyList_Check(tmp)) { |
| 3781 | PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3782 | goto failed; |
| 3783 | } |
| 3784 | len = PyList_GET_SIZE(tmp); |
| 3785 | bases = asdl_seq_new(len, arena); |
| 3786 | if (bases == NULL) goto failed; |
| 3787 | for (i = 0; i < len; i++) { |
| 3788 | expr_ty value; |
| 3789 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3790 | if (res != 0) goto failed; |
| 3791 | asdl_seq_SET(bases, i, value); |
| 3792 | } |
| 3793 | Py_XDECREF(tmp); |
| 3794 | tmp = NULL; |
| 3795 | } else { |
| 3796 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 3797 | return 1; |
| 3798 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3799 | if (_PyObject_HasAttrId(obj, &PyId_keywords)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3800 | int res; |
| 3801 | Py_ssize_t len; |
| 3802 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3803 | tmp = _PyObject_GetAttrId(obj, &PyId_keywords); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3804 | if (tmp == NULL) goto failed; |
| 3805 | if (!PyList_Check(tmp)) { |
| 3806 | PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3807 | goto failed; |
| 3808 | } |
| 3809 | len = PyList_GET_SIZE(tmp); |
| 3810 | keywords = asdl_seq_new(len, arena); |
| 3811 | if (keywords == NULL) goto failed; |
| 3812 | for (i = 0; i < len; i++) { |
| 3813 | keyword_ty value; |
| 3814 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3815 | if (res != 0) goto failed; |
| 3816 | asdl_seq_SET(keywords, i, value); |
| 3817 | } |
| 3818 | Py_XDECREF(tmp); |
| 3819 | tmp = NULL; |
| 3820 | } else { |
| 3821 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 3822 | return 1; |
| 3823 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3824 | if (_PyObject_HasAttrId(obj, &PyId_starargs)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3825 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3826 | tmp = _PyObject_GetAttrId(obj, &PyId_starargs); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3827 | if (tmp == NULL) goto failed; |
| 3828 | res = obj2ast_expr(tmp, &starargs, arena); |
| 3829 | if (res != 0) goto failed; |
| 3830 | Py_XDECREF(tmp); |
| 3831 | tmp = NULL; |
| 3832 | } else { |
| 3833 | starargs = NULL; |
| 3834 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3835 | if (_PyObject_HasAttrId(obj, &PyId_kwargs)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3836 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3837 | tmp = _PyObject_GetAttrId(obj, &PyId_kwargs); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3838 | if (tmp == NULL) goto failed; |
| 3839 | res = obj2ast_expr(tmp, &kwargs, arena); |
| 3840 | if (res != 0) goto failed; |
| 3841 | Py_XDECREF(tmp); |
| 3842 | tmp = NULL; |
| 3843 | } else { |
| 3844 | kwargs = NULL; |
| 3845 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3846 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3847 | int res; |
| 3848 | Py_ssize_t len; |
| 3849 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3850 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3851 | if (tmp == NULL) goto failed; |
| 3852 | if (!PyList_Check(tmp)) { |
| 3853 | PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3854 | goto failed; |
| 3855 | } |
| 3856 | len = PyList_GET_SIZE(tmp); |
| 3857 | body = asdl_seq_new(len, arena); |
| 3858 | if (body == NULL) goto failed; |
| 3859 | for (i = 0; i < len; i++) { |
| 3860 | stmt_ty value; |
| 3861 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3862 | if (res != 0) goto failed; |
| 3863 | asdl_seq_SET(body, i, value); |
| 3864 | } |
| 3865 | Py_XDECREF(tmp); |
| 3866 | tmp = NULL; |
| 3867 | } else { |
| 3868 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 3869 | return 1; |
| 3870 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3871 | if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3872 | int res; |
| 3873 | Py_ssize_t len; |
| 3874 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3875 | tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3876 | if (tmp == NULL) goto failed; |
| 3877 | if (!PyList_Check(tmp)) { |
| 3878 | PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3879 | goto failed; |
| 3880 | } |
| 3881 | len = PyList_GET_SIZE(tmp); |
| 3882 | decorator_list = asdl_seq_new(len, arena); |
| 3883 | if (decorator_list == NULL) goto failed; |
| 3884 | for (i = 0; i < len; i++) { |
| 3885 | expr_ty value; |
| 3886 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3887 | if (res != 0) goto failed; |
| 3888 | asdl_seq_SET(decorator_list, i, value); |
| 3889 | } |
| 3890 | Py_XDECREF(tmp); |
| 3891 | tmp = NULL; |
| 3892 | } else { |
| 3893 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 3894 | return 1; |
| 3895 | } |
| 3896 | *out = ClassDef(name, bases, keywords, starargs, kwargs, body, |
| 3897 | decorator_list, lineno, col_offset, arena); |
| 3898 | if (*out == NULL) goto failed; |
| 3899 | return 0; |
| 3900 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3901 | isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type); |
| 3902 | if (isinstance == -1) { |
| 3903 | return 1; |
| 3904 | } |
| 3905 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3906 | expr_ty value; |
| 3907 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3908 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3909 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3910 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3911 | if (tmp == NULL) goto failed; |
| 3912 | res = obj2ast_expr(tmp, &value, arena); |
| 3913 | if (res != 0) goto failed; |
| 3914 | Py_XDECREF(tmp); |
| 3915 | tmp = NULL; |
| 3916 | } else { |
| 3917 | value = NULL; |
| 3918 | } |
| 3919 | *out = Return(value, lineno, col_offset, arena); |
| 3920 | if (*out == NULL) goto failed; |
| 3921 | return 0; |
| 3922 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3923 | isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type); |
| 3924 | if (isinstance == -1) { |
| 3925 | return 1; |
| 3926 | } |
| 3927 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3928 | asdl_seq* targets; |
| 3929 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3930 | if (_PyObject_HasAttrId(obj, &PyId_targets)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3931 | int res; |
| 3932 | Py_ssize_t len; |
| 3933 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3934 | tmp = _PyObject_GetAttrId(obj, &PyId_targets); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3935 | if (tmp == NULL) goto failed; |
| 3936 | if (!PyList_Check(tmp)) { |
| 3937 | PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3938 | goto failed; |
| 3939 | } |
| 3940 | len = PyList_GET_SIZE(tmp); |
| 3941 | targets = asdl_seq_new(len, arena); |
| 3942 | if (targets == NULL) goto failed; |
| 3943 | for (i = 0; i < len; i++) { |
| 3944 | expr_ty value; |
| 3945 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3946 | if (res != 0) goto failed; |
| 3947 | asdl_seq_SET(targets, i, value); |
| 3948 | } |
| 3949 | Py_XDECREF(tmp); |
| 3950 | tmp = NULL; |
| 3951 | } else { |
| 3952 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 3953 | return 1; |
| 3954 | } |
| 3955 | *out = Delete(targets, lineno, col_offset, arena); |
| 3956 | if (*out == NULL) goto failed; |
| 3957 | return 0; |
| 3958 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3959 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type); |
| 3960 | if (isinstance == -1) { |
| 3961 | return 1; |
| 3962 | } |
| 3963 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3964 | asdl_seq* targets; |
| 3965 | expr_ty value; |
| 3966 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3967 | if (_PyObject_HasAttrId(obj, &PyId_targets)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3968 | int res; |
| 3969 | Py_ssize_t len; |
| 3970 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3971 | tmp = _PyObject_GetAttrId(obj, &PyId_targets); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3972 | if (tmp == NULL) goto failed; |
| 3973 | if (!PyList_Check(tmp)) { |
| 3974 | PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3975 | goto failed; |
| 3976 | } |
| 3977 | len = PyList_GET_SIZE(tmp); |
| 3978 | targets = asdl_seq_new(len, arena); |
| 3979 | if (targets == NULL) goto failed; |
| 3980 | for (i = 0; i < len; i++) { |
| 3981 | expr_ty value; |
| 3982 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3983 | if (res != 0) goto failed; |
| 3984 | asdl_seq_SET(targets, i, value); |
| 3985 | } |
| 3986 | Py_XDECREF(tmp); |
| 3987 | tmp = NULL; |
| 3988 | } else { |
| 3989 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 3990 | return 1; |
| 3991 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3992 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3993 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3994 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3995 | if (tmp == NULL) goto failed; |
| 3996 | res = obj2ast_expr(tmp, &value, arena); |
| 3997 | if (res != 0) goto failed; |
| 3998 | Py_XDECREF(tmp); |
| 3999 | tmp = NULL; |
| 4000 | } else { |
| 4001 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 4002 | return 1; |
| 4003 | } |
| 4004 | *out = Assign(targets, value, lineno, col_offset, arena); |
| 4005 | if (*out == NULL) goto failed; |
| 4006 | return 0; |
| 4007 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4008 | isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type); |
| 4009 | if (isinstance == -1) { |
| 4010 | return 1; |
| 4011 | } |
| 4012 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4013 | expr_ty target; |
| 4014 | operator_ty op; |
| 4015 | expr_ty value; |
| 4016 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4017 | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4018 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4019 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4020 | if (tmp == NULL) goto failed; |
| 4021 | res = obj2ast_expr(tmp, &target, arena); |
| 4022 | if (res != 0) goto failed; |
| 4023 | Py_XDECREF(tmp); |
| 4024 | tmp = NULL; |
| 4025 | } else { |
| 4026 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 4027 | return 1; |
| 4028 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4029 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4030 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4031 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4032 | if (tmp == NULL) goto failed; |
| 4033 | res = obj2ast_operator(tmp, &op, arena); |
| 4034 | if (res != 0) goto failed; |
| 4035 | Py_XDECREF(tmp); |
| 4036 | tmp = NULL; |
| 4037 | } else { |
| 4038 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 4039 | return 1; |
| 4040 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4041 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4042 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4043 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4044 | if (tmp == NULL) goto failed; |
| 4045 | res = obj2ast_expr(tmp, &value, arena); |
| 4046 | if (res != 0) goto failed; |
| 4047 | Py_XDECREF(tmp); |
| 4048 | tmp = NULL; |
| 4049 | } else { |
| 4050 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 4051 | return 1; |
| 4052 | } |
| 4053 | *out = AugAssign(target, op, value, lineno, col_offset, arena); |
| 4054 | if (*out == NULL) goto failed; |
| 4055 | return 0; |
| 4056 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4057 | isinstance = PyObject_IsInstance(obj, (PyObject*)For_type); |
| 4058 | if (isinstance == -1) { |
| 4059 | return 1; |
| 4060 | } |
| 4061 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4062 | expr_ty target; |
| 4063 | expr_ty iter; |
| 4064 | asdl_seq* body; |
| 4065 | asdl_seq* orelse; |
| 4066 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4067 | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4068 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4069 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4070 | if (tmp == NULL) goto failed; |
| 4071 | res = obj2ast_expr(tmp, &target, arena); |
| 4072 | if (res != 0) goto failed; |
| 4073 | Py_XDECREF(tmp); |
| 4074 | tmp = NULL; |
| 4075 | } else { |
| 4076 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 4077 | return 1; |
| 4078 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4079 | if (_PyObject_HasAttrId(obj, &PyId_iter)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4080 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4081 | tmp = _PyObject_GetAttrId(obj, &PyId_iter); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4082 | if (tmp == NULL) goto failed; |
| 4083 | res = obj2ast_expr(tmp, &iter, arena); |
| 4084 | if (res != 0) goto failed; |
| 4085 | Py_XDECREF(tmp); |
| 4086 | tmp = NULL; |
| 4087 | } else { |
| 4088 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 4089 | return 1; |
| 4090 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4091 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4092 | int res; |
| 4093 | Py_ssize_t len; |
| 4094 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4095 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4096 | if (tmp == NULL) goto failed; |
| 4097 | if (!PyList_Check(tmp)) { |
| 4098 | PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4099 | goto failed; |
| 4100 | } |
| 4101 | len = PyList_GET_SIZE(tmp); |
| 4102 | body = asdl_seq_new(len, arena); |
| 4103 | if (body == NULL) goto failed; |
| 4104 | for (i = 0; i < len; i++) { |
| 4105 | stmt_ty value; |
| 4106 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4107 | if (res != 0) goto failed; |
| 4108 | asdl_seq_SET(body, i, value); |
| 4109 | } |
| 4110 | Py_XDECREF(tmp); |
| 4111 | tmp = NULL; |
| 4112 | } else { |
| 4113 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 4114 | return 1; |
| 4115 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4116 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4117 | int res; |
| 4118 | Py_ssize_t len; |
| 4119 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4120 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4121 | if (tmp == NULL) goto failed; |
| 4122 | if (!PyList_Check(tmp)) { |
| 4123 | PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4124 | goto failed; |
| 4125 | } |
| 4126 | len = PyList_GET_SIZE(tmp); |
| 4127 | orelse = asdl_seq_new(len, arena); |
| 4128 | if (orelse == NULL) goto failed; |
| 4129 | for (i = 0; i < len; i++) { |
| 4130 | stmt_ty value; |
| 4131 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4132 | if (res != 0) goto failed; |
| 4133 | asdl_seq_SET(orelse, i, value); |
| 4134 | } |
| 4135 | Py_XDECREF(tmp); |
| 4136 | tmp = NULL; |
| 4137 | } else { |
| 4138 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 4139 | return 1; |
| 4140 | } |
| 4141 | *out = For(target, iter, body, orelse, lineno, col_offset, |
| 4142 | arena); |
| 4143 | if (*out == NULL) goto failed; |
| 4144 | return 0; |
| 4145 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4146 | isinstance = PyObject_IsInstance(obj, (PyObject*)While_type); |
| 4147 | if (isinstance == -1) { |
| 4148 | return 1; |
| 4149 | } |
| 4150 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4151 | expr_ty test; |
| 4152 | asdl_seq* body; |
| 4153 | asdl_seq* orelse; |
| 4154 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4155 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4156 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4157 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4158 | if (tmp == NULL) goto failed; |
| 4159 | res = obj2ast_expr(tmp, &test, arena); |
| 4160 | if (res != 0) goto failed; |
| 4161 | Py_XDECREF(tmp); |
| 4162 | tmp = NULL; |
| 4163 | } else { |
| 4164 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 4165 | return 1; |
| 4166 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4167 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4168 | int res; |
| 4169 | Py_ssize_t len; |
| 4170 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4171 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4172 | if (tmp == NULL) goto failed; |
| 4173 | if (!PyList_Check(tmp)) { |
| 4174 | PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4175 | goto failed; |
| 4176 | } |
| 4177 | len = PyList_GET_SIZE(tmp); |
| 4178 | body = asdl_seq_new(len, arena); |
| 4179 | if (body == NULL) goto failed; |
| 4180 | for (i = 0; i < len; i++) { |
| 4181 | stmt_ty value; |
| 4182 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4183 | if (res != 0) goto failed; |
| 4184 | asdl_seq_SET(body, i, value); |
| 4185 | } |
| 4186 | Py_XDECREF(tmp); |
| 4187 | tmp = NULL; |
| 4188 | } else { |
| 4189 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 4190 | return 1; |
| 4191 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4192 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4193 | int res; |
| 4194 | Py_ssize_t len; |
| 4195 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4196 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4197 | if (tmp == NULL) goto failed; |
| 4198 | if (!PyList_Check(tmp)) { |
| 4199 | PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4200 | goto failed; |
| 4201 | } |
| 4202 | len = PyList_GET_SIZE(tmp); |
| 4203 | orelse = asdl_seq_new(len, arena); |
| 4204 | if (orelse == NULL) goto failed; |
| 4205 | for (i = 0; i < len; i++) { |
| 4206 | stmt_ty value; |
| 4207 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4208 | if (res != 0) goto failed; |
| 4209 | asdl_seq_SET(orelse, i, value); |
| 4210 | } |
| 4211 | Py_XDECREF(tmp); |
| 4212 | tmp = NULL; |
| 4213 | } else { |
| 4214 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 4215 | return 1; |
| 4216 | } |
| 4217 | *out = While(test, body, orelse, lineno, col_offset, arena); |
| 4218 | if (*out == NULL) goto failed; |
| 4219 | return 0; |
| 4220 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4221 | isinstance = PyObject_IsInstance(obj, (PyObject*)If_type); |
| 4222 | if (isinstance == -1) { |
| 4223 | return 1; |
| 4224 | } |
| 4225 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4226 | expr_ty test; |
| 4227 | asdl_seq* body; |
| 4228 | asdl_seq* orelse; |
| 4229 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4230 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4231 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4232 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4233 | if (tmp == NULL) goto failed; |
| 4234 | res = obj2ast_expr(tmp, &test, arena); |
| 4235 | if (res != 0) goto failed; |
| 4236 | Py_XDECREF(tmp); |
| 4237 | tmp = NULL; |
| 4238 | } else { |
| 4239 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 4240 | return 1; |
| 4241 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4242 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4243 | int res; |
| 4244 | Py_ssize_t len; |
| 4245 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4246 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4247 | if (tmp == NULL) goto failed; |
| 4248 | if (!PyList_Check(tmp)) { |
| 4249 | PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4250 | goto failed; |
| 4251 | } |
| 4252 | len = PyList_GET_SIZE(tmp); |
| 4253 | body = asdl_seq_new(len, arena); |
| 4254 | if (body == NULL) goto failed; |
| 4255 | for (i = 0; i < len; i++) { |
| 4256 | stmt_ty value; |
| 4257 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4258 | if (res != 0) goto failed; |
| 4259 | asdl_seq_SET(body, i, value); |
| 4260 | } |
| 4261 | Py_XDECREF(tmp); |
| 4262 | tmp = NULL; |
| 4263 | } else { |
| 4264 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 4265 | return 1; |
| 4266 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4267 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4268 | int res; |
| 4269 | Py_ssize_t len; |
| 4270 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4271 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4272 | if (tmp == NULL) goto failed; |
| 4273 | if (!PyList_Check(tmp)) { |
| 4274 | PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4275 | goto failed; |
| 4276 | } |
| 4277 | len = PyList_GET_SIZE(tmp); |
| 4278 | orelse = asdl_seq_new(len, arena); |
| 4279 | if (orelse == NULL) goto failed; |
| 4280 | for (i = 0; i < len; i++) { |
| 4281 | stmt_ty value; |
| 4282 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4283 | if (res != 0) goto failed; |
| 4284 | asdl_seq_SET(orelse, i, value); |
| 4285 | } |
| 4286 | Py_XDECREF(tmp); |
| 4287 | tmp = NULL; |
| 4288 | } else { |
| 4289 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 4290 | return 1; |
| 4291 | } |
| 4292 | *out = If(test, body, orelse, lineno, col_offset, arena); |
| 4293 | if (*out == NULL) goto failed; |
| 4294 | return 0; |
| 4295 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4296 | isinstance = PyObject_IsInstance(obj, (PyObject*)With_type); |
| 4297 | if (isinstance == -1) { |
| 4298 | return 1; |
| 4299 | } |
| 4300 | if (isinstance) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4301 | asdl_seq* items; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4302 | asdl_seq* body; |
| 4303 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4304 | if (_PyObject_HasAttrId(obj, &PyId_items)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4305 | int res; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4306 | Py_ssize_t len; |
| 4307 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4308 | tmp = _PyObject_GetAttrId(obj, &PyId_items); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4309 | if (tmp == NULL) goto failed; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4310 | if (!PyList_Check(tmp)) { |
| 4311 | PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4312 | goto failed; |
| 4313 | } |
| 4314 | len = PyList_GET_SIZE(tmp); |
| 4315 | items = asdl_seq_new(len, arena); |
| 4316 | if (items == NULL) goto failed; |
| 4317 | for (i = 0; i < len; i++) { |
| 4318 | withitem_ty value; |
| 4319 | res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4320 | if (res != 0) goto failed; |
| 4321 | asdl_seq_SET(items, i, value); |
| 4322 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4323 | Py_XDECREF(tmp); |
| 4324 | tmp = NULL; |
| 4325 | } else { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4326 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4327 | return 1; |
| 4328 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4329 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4330 | int res; |
| 4331 | Py_ssize_t len; |
| 4332 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4333 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4334 | if (tmp == NULL) goto failed; |
| 4335 | if (!PyList_Check(tmp)) { |
| 4336 | PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4337 | goto failed; |
| 4338 | } |
| 4339 | len = PyList_GET_SIZE(tmp); |
| 4340 | body = asdl_seq_new(len, arena); |
| 4341 | if (body == NULL) goto failed; |
| 4342 | for (i = 0; i < len; i++) { |
| 4343 | stmt_ty value; |
| 4344 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4345 | if (res != 0) goto failed; |
| 4346 | asdl_seq_SET(body, i, value); |
| 4347 | } |
| 4348 | Py_XDECREF(tmp); |
| 4349 | tmp = NULL; |
| 4350 | } else { |
| 4351 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 4352 | return 1; |
| 4353 | } |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4354 | *out = With(items, body, lineno, col_offset, arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4355 | if (*out == NULL) goto failed; |
| 4356 | return 0; |
| 4357 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4358 | isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type); |
| 4359 | if (isinstance == -1) { |
| 4360 | return 1; |
| 4361 | } |
| 4362 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4363 | expr_ty exc; |
| 4364 | expr_ty cause; |
| 4365 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4366 | if (_PyObject_HasAttrId(obj, &PyId_exc)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4367 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4368 | tmp = _PyObject_GetAttrId(obj, &PyId_exc); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4369 | if (tmp == NULL) goto failed; |
| 4370 | res = obj2ast_expr(tmp, &exc, arena); |
| 4371 | if (res != 0) goto failed; |
| 4372 | Py_XDECREF(tmp); |
| 4373 | tmp = NULL; |
| 4374 | } else { |
| 4375 | exc = NULL; |
| 4376 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4377 | if (_PyObject_HasAttrId(obj, &PyId_cause)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4378 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4379 | tmp = _PyObject_GetAttrId(obj, &PyId_cause); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4380 | if (tmp == NULL) goto failed; |
| 4381 | res = obj2ast_expr(tmp, &cause, arena); |
| 4382 | if (res != 0) goto failed; |
| 4383 | Py_XDECREF(tmp); |
| 4384 | tmp = NULL; |
| 4385 | } else { |
| 4386 | cause = NULL; |
| 4387 | } |
| 4388 | *out = Raise(exc, cause, lineno, col_offset, arena); |
| 4389 | if (*out == NULL) goto failed; |
| 4390 | return 0; |
| 4391 | } |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4392 | isinstance = PyObject_IsInstance(obj, (PyObject*)Try_type); |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4393 | if (isinstance == -1) { |
| 4394 | return 1; |
| 4395 | } |
| 4396 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4397 | asdl_seq* body; |
| 4398 | asdl_seq* handlers; |
| 4399 | asdl_seq* orelse; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4400 | asdl_seq* finalbody; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4401 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4402 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4403 | int res; |
| 4404 | Py_ssize_t len; |
| 4405 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4406 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4407 | if (tmp == NULL) goto failed; |
| 4408 | if (!PyList_Check(tmp)) { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4409 | 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] | 4410 | goto failed; |
| 4411 | } |
| 4412 | len = PyList_GET_SIZE(tmp); |
| 4413 | body = asdl_seq_new(len, arena); |
| 4414 | if (body == NULL) goto failed; |
| 4415 | for (i = 0; i < len; i++) { |
| 4416 | stmt_ty value; |
| 4417 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4418 | if (res != 0) goto failed; |
| 4419 | asdl_seq_SET(body, i, value); |
| 4420 | } |
| 4421 | Py_XDECREF(tmp); |
| 4422 | tmp = NULL; |
| 4423 | } else { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4424 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4425 | return 1; |
| 4426 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4427 | if (_PyObject_HasAttrId(obj, &PyId_handlers)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4428 | int res; |
| 4429 | Py_ssize_t len; |
| 4430 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4431 | tmp = _PyObject_GetAttrId(obj, &PyId_handlers); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4432 | if (tmp == NULL) goto failed; |
| 4433 | if (!PyList_Check(tmp)) { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4434 | 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] | 4435 | goto failed; |
| 4436 | } |
| 4437 | len = PyList_GET_SIZE(tmp); |
| 4438 | handlers = asdl_seq_new(len, arena); |
| 4439 | if (handlers == NULL) goto failed; |
| 4440 | for (i = 0; i < len; i++) { |
| 4441 | excepthandler_ty value; |
| 4442 | res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4443 | if (res != 0) goto failed; |
| 4444 | asdl_seq_SET(handlers, i, value); |
| 4445 | } |
| 4446 | Py_XDECREF(tmp); |
| 4447 | tmp = NULL; |
| 4448 | } else { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4449 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4450 | return 1; |
| 4451 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4452 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4453 | int res; |
| 4454 | Py_ssize_t len; |
| 4455 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4456 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4457 | if (tmp == NULL) goto failed; |
| 4458 | if (!PyList_Check(tmp)) { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4459 | 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] | 4460 | goto failed; |
| 4461 | } |
| 4462 | len = PyList_GET_SIZE(tmp); |
| 4463 | orelse = asdl_seq_new(len, arena); |
| 4464 | if (orelse == NULL) goto failed; |
| 4465 | for (i = 0; i < len; i++) { |
| 4466 | stmt_ty value; |
| 4467 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4468 | if (res != 0) goto failed; |
| 4469 | asdl_seq_SET(orelse, i, value); |
| 4470 | } |
| 4471 | Py_XDECREF(tmp); |
| 4472 | tmp = NULL; |
| 4473 | } else { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4474 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4475 | return 1; |
| 4476 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4477 | if (_PyObject_HasAttrId(obj, &PyId_finalbody)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4478 | int res; |
| 4479 | Py_ssize_t len; |
| 4480 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4481 | tmp = _PyObject_GetAttrId(obj, &PyId_finalbody); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4482 | if (tmp == NULL) goto failed; |
| 4483 | if (!PyList_Check(tmp)) { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4484 | 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] | 4485 | goto failed; |
| 4486 | } |
| 4487 | len = PyList_GET_SIZE(tmp); |
| 4488 | finalbody = asdl_seq_new(len, arena); |
| 4489 | if (finalbody == NULL) goto failed; |
| 4490 | for (i = 0; i < len; i++) { |
| 4491 | stmt_ty value; |
| 4492 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4493 | if (res != 0) goto failed; |
| 4494 | asdl_seq_SET(finalbody, i, value); |
| 4495 | } |
| 4496 | Py_XDECREF(tmp); |
| 4497 | tmp = NULL; |
| 4498 | } else { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4499 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4500 | return 1; |
| 4501 | } |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4502 | *out = Try(body, handlers, orelse, finalbody, lineno, |
| 4503 | col_offset, arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4504 | if (*out == NULL) goto failed; |
| 4505 | return 0; |
| 4506 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4507 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type); |
| 4508 | if (isinstance == -1) { |
| 4509 | return 1; |
| 4510 | } |
| 4511 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4512 | expr_ty test; |
| 4513 | expr_ty msg; |
| 4514 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4515 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4516 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4517 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4518 | if (tmp == NULL) goto failed; |
| 4519 | res = obj2ast_expr(tmp, &test, arena); |
| 4520 | if (res != 0) goto failed; |
| 4521 | Py_XDECREF(tmp); |
| 4522 | tmp = NULL; |
| 4523 | } else { |
| 4524 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 4525 | return 1; |
| 4526 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4527 | if (_PyObject_HasAttrId(obj, &PyId_msg)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4528 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4529 | tmp = _PyObject_GetAttrId(obj, &PyId_msg); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4530 | if (tmp == NULL) goto failed; |
| 4531 | res = obj2ast_expr(tmp, &msg, arena); |
| 4532 | if (res != 0) goto failed; |
| 4533 | Py_XDECREF(tmp); |
| 4534 | tmp = NULL; |
| 4535 | } else { |
| 4536 | msg = NULL; |
| 4537 | } |
| 4538 | *out = Assert(test, msg, lineno, col_offset, arena); |
| 4539 | if (*out == NULL) goto failed; |
| 4540 | return 0; |
| 4541 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4542 | isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type); |
| 4543 | if (isinstance == -1) { |
| 4544 | return 1; |
| 4545 | } |
| 4546 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4547 | asdl_seq* names; |
| 4548 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4549 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4550 | int res; |
| 4551 | Py_ssize_t len; |
| 4552 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4553 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4554 | if (tmp == NULL) goto failed; |
| 4555 | if (!PyList_Check(tmp)) { |
| 4556 | PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4557 | goto failed; |
| 4558 | } |
| 4559 | len = PyList_GET_SIZE(tmp); |
| 4560 | names = asdl_seq_new(len, arena); |
| 4561 | if (names == NULL) goto failed; |
| 4562 | for (i = 0; i < len; i++) { |
| 4563 | alias_ty value; |
| 4564 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4565 | if (res != 0) goto failed; |
| 4566 | asdl_seq_SET(names, i, value); |
| 4567 | } |
| 4568 | Py_XDECREF(tmp); |
| 4569 | tmp = NULL; |
| 4570 | } else { |
| 4571 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 4572 | return 1; |
| 4573 | } |
| 4574 | *out = Import(names, lineno, col_offset, arena); |
| 4575 | if (*out == NULL) goto failed; |
| 4576 | return 0; |
| 4577 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4578 | isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type); |
| 4579 | if (isinstance == -1) { |
| 4580 | return 1; |
| 4581 | } |
| 4582 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4583 | identifier module; |
| 4584 | asdl_seq* names; |
| 4585 | int level; |
| 4586 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4587 | if (_PyObject_HasAttrId(obj, &PyId_module)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4588 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4589 | tmp = _PyObject_GetAttrId(obj, &PyId_module); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4590 | if (tmp == NULL) goto failed; |
| 4591 | res = obj2ast_identifier(tmp, &module, arena); |
| 4592 | if (res != 0) goto failed; |
| 4593 | Py_XDECREF(tmp); |
| 4594 | tmp = NULL; |
| 4595 | } else { |
Benjamin Peterson | 78565b2 | 2009-06-28 19:19:51 +0000 | [diff] [blame] | 4596 | module = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4597 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4598 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4599 | int res; |
| 4600 | Py_ssize_t len; |
| 4601 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4602 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4603 | if (tmp == NULL) goto failed; |
| 4604 | if (!PyList_Check(tmp)) { |
| 4605 | PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4606 | goto failed; |
| 4607 | } |
| 4608 | len = PyList_GET_SIZE(tmp); |
| 4609 | names = asdl_seq_new(len, arena); |
| 4610 | if (names == NULL) goto failed; |
| 4611 | for (i = 0; i < len; i++) { |
| 4612 | alias_ty value; |
| 4613 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4614 | if (res != 0) goto failed; |
| 4615 | asdl_seq_SET(names, i, value); |
| 4616 | } |
| 4617 | Py_XDECREF(tmp); |
| 4618 | tmp = NULL; |
| 4619 | } else { |
| 4620 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 4621 | return 1; |
| 4622 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4623 | if (_PyObject_HasAttrId(obj, &PyId_level)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4624 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4625 | tmp = _PyObject_GetAttrId(obj, &PyId_level); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4626 | if (tmp == NULL) goto failed; |
| 4627 | res = obj2ast_int(tmp, &level, arena); |
| 4628 | if (res != 0) goto failed; |
| 4629 | Py_XDECREF(tmp); |
| 4630 | tmp = NULL; |
| 4631 | } else { |
| 4632 | level = 0; |
| 4633 | } |
| 4634 | *out = ImportFrom(module, names, level, lineno, col_offset, |
| 4635 | arena); |
| 4636 | if (*out == NULL) goto failed; |
| 4637 | return 0; |
| 4638 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4639 | isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type); |
| 4640 | if (isinstance == -1) { |
| 4641 | return 1; |
| 4642 | } |
| 4643 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4644 | asdl_seq* names; |
| 4645 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4646 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4647 | int res; |
| 4648 | Py_ssize_t len; |
| 4649 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4650 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4651 | if (tmp == NULL) goto failed; |
| 4652 | if (!PyList_Check(tmp)) { |
| 4653 | PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4654 | goto failed; |
| 4655 | } |
| 4656 | len = PyList_GET_SIZE(tmp); |
| 4657 | names = asdl_seq_new(len, arena); |
| 4658 | if (names == NULL) goto failed; |
| 4659 | for (i = 0; i < len; i++) { |
| 4660 | identifier value; |
| 4661 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4662 | if (res != 0) goto failed; |
| 4663 | asdl_seq_SET(names, i, value); |
| 4664 | } |
| 4665 | Py_XDECREF(tmp); |
| 4666 | tmp = NULL; |
| 4667 | } else { |
| 4668 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 4669 | return 1; |
| 4670 | } |
| 4671 | *out = Global(names, lineno, col_offset, arena); |
| 4672 | if (*out == NULL) goto failed; |
| 4673 | return 0; |
| 4674 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4675 | isinstance = PyObject_IsInstance(obj, (PyObject*)Nonlocal_type); |
| 4676 | if (isinstance == -1) { |
| 4677 | return 1; |
| 4678 | } |
| 4679 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4680 | asdl_seq* names; |
| 4681 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4682 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4683 | int res; |
| 4684 | Py_ssize_t len; |
| 4685 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4686 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4687 | if (tmp == NULL) goto failed; |
| 4688 | if (!PyList_Check(tmp)) { |
| 4689 | PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4690 | goto failed; |
| 4691 | } |
| 4692 | len = PyList_GET_SIZE(tmp); |
| 4693 | names = asdl_seq_new(len, arena); |
| 4694 | if (names == NULL) goto failed; |
| 4695 | for (i = 0; i < len; i++) { |
| 4696 | identifier value; |
| 4697 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4698 | if (res != 0) goto failed; |
| 4699 | asdl_seq_SET(names, i, value); |
| 4700 | } |
| 4701 | Py_XDECREF(tmp); |
| 4702 | tmp = NULL; |
| 4703 | } else { |
| 4704 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 4705 | return 1; |
| 4706 | } |
| 4707 | *out = Nonlocal(names, lineno, col_offset, arena); |
| 4708 | if (*out == NULL) goto failed; |
| 4709 | return 0; |
| 4710 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4711 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type); |
| 4712 | if (isinstance == -1) { |
| 4713 | return 1; |
| 4714 | } |
| 4715 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4716 | expr_ty value; |
| 4717 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4718 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4719 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4720 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4721 | if (tmp == NULL) goto failed; |
| 4722 | res = obj2ast_expr(tmp, &value, arena); |
| 4723 | if (res != 0) goto failed; |
| 4724 | Py_XDECREF(tmp); |
| 4725 | tmp = NULL; |
| 4726 | } else { |
| 4727 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 4728 | return 1; |
| 4729 | } |
| 4730 | *out = Expr(value, lineno, col_offset, arena); |
| 4731 | if (*out == NULL) goto failed; |
| 4732 | return 0; |
| 4733 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4734 | isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type); |
| 4735 | if (isinstance == -1) { |
| 4736 | return 1; |
| 4737 | } |
| 4738 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4739 | |
| 4740 | *out = Pass(lineno, col_offset, arena); |
| 4741 | if (*out == NULL) goto failed; |
| 4742 | return 0; |
| 4743 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4744 | isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type); |
| 4745 | if (isinstance == -1) { |
| 4746 | return 1; |
| 4747 | } |
| 4748 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4749 | |
| 4750 | *out = Break(lineno, col_offset, arena); |
| 4751 | if (*out == NULL) goto failed; |
| 4752 | return 0; |
| 4753 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4754 | isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type); |
| 4755 | if (isinstance == -1) { |
| 4756 | return 1; |
| 4757 | } |
| 4758 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4759 | |
| 4760 | *out = Continue(lineno, col_offset, arena); |
| 4761 | if (*out == NULL) goto failed; |
| 4762 | return 0; |
| 4763 | } |
| 4764 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 4765 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
| 4766 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 4767 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4768 | return 1; |
| 4769 | } |
| 4770 | |
| 4771 | int |
| 4772 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 4773 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4774 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4775 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 4776 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4777 | int lineno; |
| 4778 | int col_offset; |
| 4779 | |
| 4780 | if (obj == Py_None) { |
| 4781 | *out = NULL; |
| 4782 | return 0; |
| 4783 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4784 | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4785 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4786 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4787 | if (tmp == NULL) goto failed; |
| 4788 | res = obj2ast_int(tmp, &lineno, arena); |
| 4789 | if (res != 0) goto failed; |
| 4790 | Py_XDECREF(tmp); |
| 4791 | tmp = NULL; |
| 4792 | } else { |
| 4793 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 4794 | return 1; |
| 4795 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4796 | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4797 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4798 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4799 | if (tmp == NULL) goto failed; |
| 4800 | res = obj2ast_int(tmp, &col_offset, arena); |
| 4801 | if (res != 0) goto failed; |
| 4802 | Py_XDECREF(tmp); |
| 4803 | tmp = NULL; |
| 4804 | } else { |
| 4805 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 4806 | return 1; |
| 4807 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4808 | isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type); |
| 4809 | if (isinstance == -1) { |
| 4810 | return 1; |
| 4811 | } |
| 4812 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4813 | boolop_ty op; |
| 4814 | asdl_seq* values; |
| 4815 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4816 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4817 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4818 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4819 | if (tmp == NULL) goto failed; |
| 4820 | res = obj2ast_boolop(tmp, &op, arena); |
| 4821 | if (res != 0) goto failed; |
| 4822 | Py_XDECREF(tmp); |
| 4823 | tmp = NULL; |
| 4824 | } else { |
| 4825 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 4826 | return 1; |
| 4827 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4828 | if (_PyObject_HasAttrId(obj, &PyId_values)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4829 | int res; |
| 4830 | Py_ssize_t len; |
| 4831 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4832 | tmp = _PyObject_GetAttrId(obj, &PyId_values); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4833 | if (tmp == NULL) goto failed; |
| 4834 | if (!PyList_Check(tmp)) { |
| 4835 | PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4836 | goto failed; |
| 4837 | } |
| 4838 | len = PyList_GET_SIZE(tmp); |
| 4839 | values = asdl_seq_new(len, arena); |
| 4840 | if (values == NULL) goto failed; |
| 4841 | for (i = 0; i < len; i++) { |
| 4842 | expr_ty value; |
| 4843 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4844 | if (res != 0) goto failed; |
| 4845 | asdl_seq_SET(values, i, value); |
| 4846 | } |
| 4847 | Py_XDECREF(tmp); |
| 4848 | tmp = NULL; |
| 4849 | } else { |
| 4850 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 4851 | return 1; |
| 4852 | } |
| 4853 | *out = BoolOp(op, values, lineno, col_offset, arena); |
| 4854 | if (*out == NULL) goto failed; |
| 4855 | return 0; |
| 4856 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4857 | isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type); |
| 4858 | if (isinstance == -1) { |
| 4859 | return 1; |
| 4860 | } |
| 4861 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4862 | expr_ty left; |
| 4863 | operator_ty op; |
| 4864 | expr_ty right; |
| 4865 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4866 | if (_PyObject_HasAttrId(obj, &PyId_left)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4867 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4868 | tmp = _PyObject_GetAttrId(obj, &PyId_left); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4869 | if (tmp == NULL) goto failed; |
| 4870 | res = obj2ast_expr(tmp, &left, arena); |
| 4871 | if (res != 0) goto failed; |
| 4872 | Py_XDECREF(tmp); |
| 4873 | tmp = NULL; |
| 4874 | } else { |
| 4875 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 4876 | return 1; |
| 4877 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4878 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4879 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4880 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4881 | if (tmp == NULL) goto failed; |
| 4882 | res = obj2ast_operator(tmp, &op, arena); |
| 4883 | if (res != 0) goto failed; |
| 4884 | Py_XDECREF(tmp); |
| 4885 | tmp = NULL; |
| 4886 | } else { |
| 4887 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 4888 | return 1; |
| 4889 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4890 | if (_PyObject_HasAttrId(obj, &PyId_right)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4891 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4892 | tmp = _PyObject_GetAttrId(obj, &PyId_right); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4893 | if (tmp == NULL) goto failed; |
| 4894 | res = obj2ast_expr(tmp, &right, arena); |
| 4895 | if (res != 0) goto failed; |
| 4896 | Py_XDECREF(tmp); |
| 4897 | tmp = NULL; |
| 4898 | } else { |
| 4899 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 4900 | return 1; |
| 4901 | } |
| 4902 | *out = BinOp(left, op, right, lineno, col_offset, arena); |
| 4903 | if (*out == NULL) goto failed; |
| 4904 | return 0; |
| 4905 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4906 | isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type); |
| 4907 | if (isinstance == -1) { |
| 4908 | return 1; |
| 4909 | } |
| 4910 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4911 | unaryop_ty op; |
| 4912 | expr_ty operand; |
| 4913 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4914 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4915 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4916 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4917 | if (tmp == NULL) goto failed; |
| 4918 | res = obj2ast_unaryop(tmp, &op, arena); |
| 4919 | if (res != 0) goto failed; |
| 4920 | Py_XDECREF(tmp); |
| 4921 | tmp = NULL; |
| 4922 | } else { |
| 4923 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 4924 | return 1; |
| 4925 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4926 | if (_PyObject_HasAttrId(obj, &PyId_operand)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4927 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4928 | tmp = _PyObject_GetAttrId(obj, &PyId_operand); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4929 | if (tmp == NULL) goto failed; |
| 4930 | res = obj2ast_expr(tmp, &operand, arena); |
| 4931 | if (res != 0) goto failed; |
| 4932 | Py_XDECREF(tmp); |
| 4933 | tmp = NULL; |
| 4934 | } else { |
| 4935 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 4936 | return 1; |
| 4937 | } |
| 4938 | *out = UnaryOp(op, operand, lineno, col_offset, arena); |
| 4939 | if (*out == NULL) goto failed; |
| 4940 | return 0; |
| 4941 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4942 | isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type); |
| 4943 | if (isinstance == -1) { |
| 4944 | return 1; |
| 4945 | } |
| 4946 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4947 | arguments_ty args; |
| 4948 | expr_ty body; |
| 4949 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4950 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4951 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4952 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4953 | if (tmp == NULL) goto failed; |
| 4954 | res = obj2ast_arguments(tmp, &args, arena); |
| 4955 | if (res != 0) goto failed; |
| 4956 | Py_XDECREF(tmp); |
| 4957 | tmp = NULL; |
| 4958 | } else { |
| 4959 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 4960 | return 1; |
| 4961 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4962 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4963 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4964 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4965 | if (tmp == NULL) goto failed; |
| 4966 | res = obj2ast_expr(tmp, &body, arena); |
| 4967 | if (res != 0) goto failed; |
| 4968 | Py_XDECREF(tmp); |
| 4969 | tmp = NULL; |
| 4970 | } else { |
| 4971 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 4972 | return 1; |
| 4973 | } |
| 4974 | *out = Lambda(args, body, lineno, col_offset, arena); |
| 4975 | if (*out == NULL) goto failed; |
| 4976 | return 0; |
| 4977 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4978 | isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type); |
| 4979 | if (isinstance == -1) { |
| 4980 | return 1; |
| 4981 | } |
| 4982 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4983 | expr_ty test; |
| 4984 | expr_ty body; |
| 4985 | expr_ty orelse; |
| 4986 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4987 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4988 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4989 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4990 | if (tmp == NULL) goto failed; |
| 4991 | res = obj2ast_expr(tmp, &test, arena); |
| 4992 | if (res != 0) goto failed; |
| 4993 | Py_XDECREF(tmp); |
| 4994 | tmp = NULL; |
| 4995 | } else { |
| 4996 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 4997 | return 1; |
| 4998 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4999 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5000 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5001 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5002 | if (tmp == NULL) goto failed; |
| 5003 | res = obj2ast_expr(tmp, &body, arena); |
| 5004 | if (res != 0) goto failed; |
| 5005 | Py_XDECREF(tmp); |
| 5006 | tmp = NULL; |
| 5007 | } else { |
| 5008 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 5009 | return 1; |
| 5010 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5011 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5012 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5013 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5014 | if (tmp == NULL) goto failed; |
| 5015 | res = obj2ast_expr(tmp, &orelse, arena); |
| 5016 | if (res != 0) goto failed; |
| 5017 | Py_XDECREF(tmp); |
| 5018 | tmp = NULL; |
| 5019 | } else { |
| 5020 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 5021 | return 1; |
| 5022 | } |
| 5023 | *out = IfExp(test, body, orelse, lineno, col_offset, arena); |
| 5024 | if (*out == NULL) goto failed; |
| 5025 | return 0; |
| 5026 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5027 | isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type); |
| 5028 | if (isinstance == -1) { |
| 5029 | return 1; |
| 5030 | } |
| 5031 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5032 | asdl_seq* keys; |
| 5033 | asdl_seq* values; |
| 5034 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5035 | if (_PyObject_HasAttrId(obj, &PyId_keys)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5036 | int res; |
| 5037 | Py_ssize_t len; |
| 5038 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5039 | tmp = _PyObject_GetAttrId(obj, &PyId_keys); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5040 | if (tmp == NULL) goto failed; |
| 5041 | if (!PyList_Check(tmp)) { |
| 5042 | PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5043 | goto failed; |
| 5044 | } |
| 5045 | len = PyList_GET_SIZE(tmp); |
| 5046 | keys = asdl_seq_new(len, arena); |
| 5047 | if (keys == NULL) goto failed; |
| 5048 | for (i = 0; i < len; i++) { |
| 5049 | expr_ty value; |
| 5050 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5051 | if (res != 0) goto failed; |
| 5052 | asdl_seq_SET(keys, i, value); |
| 5053 | } |
| 5054 | Py_XDECREF(tmp); |
| 5055 | tmp = NULL; |
| 5056 | } else { |
| 5057 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 5058 | return 1; |
| 5059 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5060 | if (_PyObject_HasAttrId(obj, &PyId_values)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5061 | int res; |
| 5062 | Py_ssize_t len; |
| 5063 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5064 | tmp = _PyObject_GetAttrId(obj, &PyId_values); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5065 | if (tmp == NULL) goto failed; |
| 5066 | if (!PyList_Check(tmp)) { |
| 5067 | PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5068 | goto failed; |
| 5069 | } |
| 5070 | len = PyList_GET_SIZE(tmp); |
| 5071 | values = asdl_seq_new(len, arena); |
| 5072 | if (values == NULL) goto failed; |
| 5073 | for (i = 0; i < len; i++) { |
| 5074 | expr_ty value; |
| 5075 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5076 | if (res != 0) goto failed; |
| 5077 | asdl_seq_SET(values, i, value); |
| 5078 | } |
| 5079 | Py_XDECREF(tmp); |
| 5080 | tmp = NULL; |
| 5081 | } else { |
| 5082 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 5083 | return 1; |
| 5084 | } |
| 5085 | *out = Dict(keys, values, lineno, col_offset, arena); |
| 5086 | if (*out == NULL) goto failed; |
| 5087 | return 0; |
| 5088 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5089 | isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type); |
| 5090 | if (isinstance == -1) { |
| 5091 | return 1; |
| 5092 | } |
| 5093 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5094 | asdl_seq* elts; |
| 5095 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5096 | if (_PyObject_HasAttrId(obj, &PyId_elts)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5097 | int res; |
| 5098 | Py_ssize_t len; |
| 5099 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5100 | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5101 | if (tmp == NULL) goto failed; |
| 5102 | if (!PyList_Check(tmp)) { |
| 5103 | PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5104 | goto failed; |
| 5105 | } |
| 5106 | len = PyList_GET_SIZE(tmp); |
| 5107 | elts = asdl_seq_new(len, arena); |
| 5108 | if (elts == NULL) goto failed; |
| 5109 | for (i = 0; i < len; i++) { |
| 5110 | expr_ty value; |
| 5111 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5112 | if (res != 0) goto failed; |
| 5113 | asdl_seq_SET(elts, i, value); |
| 5114 | } |
| 5115 | Py_XDECREF(tmp); |
| 5116 | tmp = NULL; |
| 5117 | } else { |
| 5118 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 5119 | return 1; |
| 5120 | } |
| 5121 | *out = Set(elts, lineno, col_offset, arena); |
| 5122 | if (*out == NULL) goto failed; |
| 5123 | return 0; |
| 5124 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5125 | isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type); |
| 5126 | if (isinstance == -1) { |
| 5127 | return 1; |
| 5128 | } |
| 5129 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5130 | expr_ty elt; |
| 5131 | asdl_seq* generators; |
| 5132 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5133 | if (_PyObject_HasAttrId(obj, &PyId_elt)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5134 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5135 | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5136 | if (tmp == NULL) goto failed; |
| 5137 | res = obj2ast_expr(tmp, &elt, arena); |
| 5138 | if (res != 0) goto failed; |
| 5139 | Py_XDECREF(tmp); |
| 5140 | tmp = NULL; |
| 5141 | } else { |
| 5142 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 5143 | return 1; |
| 5144 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5145 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5146 | int res; |
| 5147 | Py_ssize_t len; |
| 5148 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5149 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5150 | if (tmp == NULL) goto failed; |
| 5151 | if (!PyList_Check(tmp)) { |
| 5152 | PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5153 | goto failed; |
| 5154 | } |
| 5155 | len = PyList_GET_SIZE(tmp); |
| 5156 | generators = asdl_seq_new(len, arena); |
| 5157 | if (generators == NULL) goto failed; |
| 5158 | for (i = 0; i < len; i++) { |
| 5159 | comprehension_ty value; |
| 5160 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5161 | if (res != 0) goto failed; |
| 5162 | asdl_seq_SET(generators, i, value); |
| 5163 | } |
| 5164 | Py_XDECREF(tmp); |
| 5165 | tmp = NULL; |
| 5166 | } else { |
| 5167 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 5168 | return 1; |
| 5169 | } |
| 5170 | *out = ListComp(elt, generators, lineno, col_offset, arena); |
| 5171 | if (*out == NULL) goto failed; |
| 5172 | return 0; |
| 5173 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5174 | isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type); |
| 5175 | if (isinstance == -1) { |
| 5176 | return 1; |
| 5177 | } |
| 5178 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5179 | expr_ty elt; |
| 5180 | asdl_seq* generators; |
| 5181 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5182 | if (_PyObject_HasAttrId(obj, &PyId_elt)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5183 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5184 | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5185 | if (tmp == NULL) goto failed; |
| 5186 | res = obj2ast_expr(tmp, &elt, arena); |
| 5187 | if (res != 0) goto failed; |
| 5188 | Py_XDECREF(tmp); |
| 5189 | tmp = NULL; |
| 5190 | } else { |
| 5191 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 5192 | return 1; |
| 5193 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5194 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5195 | int res; |
| 5196 | Py_ssize_t len; |
| 5197 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5198 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5199 | if (tmp == NULL) goto failed; |
| 5200 | if (!PyList_Check(tmp)) { |
| 5201 | PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5202 | goto failed; |
| 5203 | } |
| 5204 | len = PyList_GET_SIZE(tmp); |
| 5205 | generators = asdl_seq_new(len, arena); |
| 5206 | if (generators == NULL) goto failed; |
| 5207 | for (i = 0; i < len; i++) { |
| 5208 | comprehension_ty value; |
| 5209 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5210 | if (res != 0) goto failed; |
| 5211 | asdl_seq_SET(generators, i, value); |
| 5212 | } |
| 5213 | Py_XDECREF(tmp); |
| 5214 | tmp = NULL; |
| 5215 | } else { |
| 5216 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 5217 | return 1; |
| 5218 | } |
| 5219 | *out = SetComp(elt, generators, lineno, col_offset, arena); |
| 5220 | if (*out == NULL) goto failed; |
| 5221 | return 0; |
| 5222 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5223 | isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type); |
| 5224 | if (isinstance == -1) { |
| 5225 | return 1; |
| 5226 | } |
| 5227 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5228 | expr_ty key; |
| 5229 | expr_ty value; |
| 5230 | asdl_seq* generators; |
| 5231 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5232 | if (_PyObject_HasAttrId(obj, &PyId_key)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5233 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5234 | tmp = _PyObject_GetAttrId(obj, &PyId_key); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5235 | if (tmp == NULL) goto failed; |
| 5236 | res = obj2ast_expr(tmp, &key, arena); |
| 5237 | if (res != 0) goto failed; |
| 5238 | Py_XDECREF(tmp); |
| 5239 | tmp = NULL; |
| 5240 | } else { |
| 5241 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 5242 | return 1; |
| 5243 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5244 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5245 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5246 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5247 | if (tmp == NULL) goto failed; |
| 5248 | res = obj2ast_expr(tmp, &value, arena); |
| 5249 | if (res != 0) goto failed; |
| 5250 | Py_XDECREF(tmp); |
| 5251 | tmp = NULL; |
| 5252 | } else { |
| 5253 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 5254 | return 1; |
| 5255 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5256 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5257 | int res; |
| 5258 | Py_ssize_t len; |
| 5259 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5260 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5261 | if (tmp == NULL) goto failed; |
| 5262 | if (!PyList_Check(tmp)) { |
| 5263 | PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5264 | goto failed; |
| 5265 | } |
| 5266 | len = PyList_GET_SIZE(tmp); |
| 5267 | generators = asdl_seq_new(len, arena); |
| 5268 | if (generators == NULL) goto failed; |
| 5269 | for (i = 0; i < len; i++) { |
| 5270 | comprehension_ty value; |
| 5271 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5272 | if (res != 0) goto failed; |
| 5273 | asdl_seq_SET(generators, i, value); |
| 5274 | } |
| 5275 | Py_XDECREF(tmp); |
| 5276 | tmp = NULL; |
| 5277 | } else { |
| 5278 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 5279 | return 1; |
| 5280 | } |
| 5281 | *out = DictComp(key, value, generators, lineno, col_offset, |
| 5282 | arena); |
| 5283 | if (*out == NULL) goto failed; |
| 5284 | return 0; |
| 5285 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5286 | isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type); |
| 5287 | if (isinstance == -1) { |
| 5288 | return 1; |
| 5289 | } |
| 5290 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5291 | expr_ty elt; |
| 5292 | asdl_seq* generators; |
| 5293 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5294 | if (_PyObject_HasAttrId(obj, &PyId_elt)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5295 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5296 | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5297 | if (tmp == NULL) goto failed; |
| 5298 | res = obj2ast_expr(tmp, &elt, arena); |
| 5299 | if (res != 0) goto failed; |
| 5300 | Py_XDECREF(tmp); |
| 5301 | tmp = NULL; |
| 5302 | } else { |
| 5303 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 5304 | return 1; |
| 5305 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5306 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5307 | int res; |
| 5308 | Py_ssize_t len; |
| 5309 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5310 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5311 | if (tmp == NULL) goto failed; |
| 5312 | if (!PyList_Check(tmp)) { |
| 5313 | PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5314 | goto failed; |
| 5315 | } |
| 5316 | len = PyList_GET_SIZE(tmp); |
| 5317 | generators = asdl_seq_new(len, arena); |
| 5318 | if (generators == NULL) goto failed; |
| 5319 | for (i = 0; i < len; i++) { |
| 5320 | comprehension_ty value; |
| 5321 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5322 | if (res != 0) goto failed; |
| 5323 | asdl_seq_SET(generators, i, value); |
| 5324 | } |
| 5325 | Py_XDECREF(tmp); |
| 5326 | tmp = NULL; |
| 5327 | } else { |
| 5328 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 5329 | return 1; |
| 5330 | } |
| 5331 | *out = GeneratorExp(elt, generators, lineno, col_offset, arena); |
| 5332 | if (*out == NULL) goto failed; |
| 5333 | return 0; |
| 5334 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5335 | isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); |
| 5336 | if (isinstance == -1) { |
| 5337 | return 1; |
| 5338 | } |
| 5339 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5340 | expr_ty value; |
| 5341 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5342 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5343 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5344 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5345 | if (tmp == NULL) goto failed; |
| 5346 | res = obj2ast_expr(tmp, &value, arena); |
| 5347 | if (res != 0) goto failed; |
| 5348 | Py_XDECREF(tmp); |
| 5349 | tmp = NULL; |
| 5350 | } else { |
| 5351 | value = NULL; |
| 5352 | } |
| 5353 | *out = Yield(value, lineno, col_offset, arena); |
| 5354 | if (*out == NULL) goto failed; |
| 5355 | return 0; |
| 5356 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5357 | isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); |
| 5358 | if (isinstance == -1) { |
| 5359 | return 1; |
| 5360 | } |
| 5361 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5362 | expr_ty left; |
| 5363 | asdl_int_seq* ops; |
| 5364 | asdl_seq* comparators; |
| 5365 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5366 | if (_PyObject_HasAttrId(obj, &PyId_left)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5367 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5368 | tmp = _PyObject_GetAttrId(obj, &PyId_left); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5369 | if (tmp == NULL) goto failed; |
| 5370 | res = obj2ast_expr(tmp, &left, arena); |
| 5371 | if (res != 0) goto failed; |
| 5372 | Py_XDECREF(tmp); |
| 5373 | tmp = NULL; |
| 5374 | } else { |
| 5375 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 5376 | return 1; |
| 5377 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5378 | if (_PyObject_HasAttrId(obj, &PyId_ops)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5379 | int res; |
| 5380 | Py_ssize_t len; |
| 5381 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5382 | tmp = _PyObject_GetAttrId(obj, &PyId_ops); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5383 | if (tmp == NULL) goto failed; |
| 5384 | if (!PyList_Check(tmp)) { |
| 5385 | PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5386 | goto failed; |
| 5387 | } |
| 5388 | len = PyList_GET_SIZE(tmp); |
| 5389 | ops = asdl_int_seq_new(len, arena); |
| 5390 | if (ops == NULL) goto failed; |
| 5391 | for (i = 0; i < len; i++) { |
| 5392 | cmpop_ty value; |
| 5393 | res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5394 | if (res != 0) goto failed; |
| 5395 | asdl_seq_SET(ops, i, value); |
| 5396 | } |
| 5397 | Py_XDECREF(tmp); |
| 5398 | tmp = NULL; |
| 5399 | } else { |
| 5400 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 5401 | return 1; |
| 5402 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5403 | if (_PyObject_HasAttrId(obj, &PyId_comparators)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5404 | int res; |
| 5405 | Py_ssize_t len; |
| 5406 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5407 | tmp = _PyObject_GetAttrId(obj, &PyId_comparators); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5408 | if (tmp == NULL) goto failed; |
| 5409 | if (!PyList_Check(tmp)) { |
| 5410 | PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5411 | goto failed; |
| 5412 | } |
| 5413 | len = PyList_GET_SIZE(tmp); |
| 5414 | comparators = asdl_seq_new(len, arena); |
| 5415 | if (comparators == NULL) goto failed; |
| 5416 | for (i = 0; i < len; i++) { |
| 5417 | expr_ty value; |
| 5418 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5419 | if (res != 0) goto failed; |
| 5420 | asdl_seq_SET(comparators, i, value); |
| 5421 | } |
| 5422 | Py_XDECREF(tmp); |
| 5423 | tmp = NULL; |
| 5424 | } else { |
| 5425 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 5426 | return 1; |
| 5427 | } |
| 5428 | *out = Compare(left, ops, comparators, lineno, col_offset, |
| 5429 | arena); |
| 5430 | if (*out == NULL) goto failed; |
| 5431 | return 0; |
| 5432 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5433 | isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type); |
| 5434 | if (isinstance == -1) { |
| 5435 | return 1; |
| 5436 | } |
| 5437 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5438 | expr_ty func; |
| 5439 | asdl_seq* args; |
| 5440 | asdl_seq* keywords; |
| 5441 | expr_ty starargs; |
| 5442 | expr_ty kwargs; |
| 5443 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5444 | if (_PyObject_HasAttrId(obj, &PyId_func)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5445 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5446 | tmp = _PyObject_GetAttrId(obj, &PyId_func); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5447 | if (tmp == NULL) goto failed; |
| 5448 | res = obj2ast_expr(tmp, &func, arena); |
| 5449 | if (res != 0) goto failed; |
| 5450 | Py_XDECREF(tmp); |
| 5451 | tmp = NULL; |
| 5452 | } else { |
| 5453 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 5454 | return 1; |
| 5455 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5456 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5457 | int res; |
| 5458 | Py_ssize_t len; |
| 5459 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5460 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5461 | if (tmp == NULL) goto failed; |
| 5462 | if (!PyList_Check(tmp)) { |
| 5463 | PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5464 | goto failed; |
| 5465 | } |
| 5466 | len = PyList_GET_SIZE(tmp); |
| 5467 | args = asdl_seq_new(len, arena); |
| 5468 | if (args == NULL) goto failed; |
| 5469 | for (i = 0; i < len; i++) { |
| 5470 | expr_ty value; |
| 5471 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5472 | if (res != 0) goto failed; |
| 5473 | asdl_seq_SET(args, i, value); |
| 5474 | } |
| 5475 | Py_XDECREF(tmp); |
| 5476 | tmp = NULL; |
| 5477 | } else { |
| 5478 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 5479 | return 1; |
| 5480 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5481 | if (_PyObject_HasAttrId(obj, &PyId_keywords)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5482 | int res; |
| 5483 | Py_ssize_t len; |
| 5484 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5485 | tmp = _PyObject_GetAttrId(obj, &PyId_keywords); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5486 | if (tmp == NULL) goto failed; |
| 5487 | if (!PyList_Check(tmp)) { |
| 5488 | PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5489 | goto failed; |
| 5490 | } |
| 5491 | len = PyList_GET_SIZE(tmp); |
| 5492 | keywords = asdl_seq_new(len, arena); |
| 5493 | if (keywords == NULL) goto failed; |
| 5494 | for (i = 0; i < len; i++) { |
| 5495 | keyword_ty value; |
| 5496 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5497 | if (res != 0) goto failed; |
| 5498 | asdl_seq_SET(keywords, i, value); |
| 5499 | } |
| 5500 | Py_XDECREF(tmp); |
| 5501 | tmp = NULL; |
| 5502 | } else { |
| 5503 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 5504 | return 1; |
| 5505 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5506 | if (_PyObject_HasAttrId(obj, &PyId_starargs)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5507 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5508 | tmp = _PyObject_GetAttrId(obj, &PyId_starargs); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5509 | if (tmp == NULL) goto failed; |
| 5510 | res = obj2ast_expr(tmp, &starargs, arena); |
| 5511 | if (res != 0) goto failed; |
| 5512 | Py_XDECREF(tmp); |
| 5513 | tmp = NULL; |
| 5514 | } else { |
| 5515 | starargs = NULL; |
| 5516 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5517 | if (_PyObject_HasAttrId(obj, &PyId_kwargs)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5518 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5519 | tmp = _PyObject_GetAttrId(obj, &PyId_kwargs); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5520 | if (tmp == NULL) goto failed; |
| 5521 | res = obj2ast_expr(tmp, &kwargs, arena); |
| 5522 | if (res != 0) goto failed; |
| 5523 | Py_XDECREF(tmp); |
| 5524 | tmp = NULL; |
| 5525 | } else { |
| 5526 | kwargs = NULL; |
| 5527 | } |
| 5528 | *out = Call(func, args, keywords, starargs, kwargs, lineno, |
| 5529 | col_offset, arena); |
| 5530 | if (*out == NULL) goto failed; |
| 5531 | return 0; |
| 5532 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5533 | isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type); |
| 5534 | if (isinstance == -1) { |
| 5535 | return 1; |
| 5536 | } |
| 5537 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5538 | object n; |
| 5539 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5540 | if (_PyObject_HasAttrId(obj, &PyId_n)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5541 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5542 | tmp = _PyObject_GetAttrId(obj, &PyId_n); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5543 | if (tmp == NULL) goto failed; |
| 5544 | res = obj2ast_object(tmp, &n, arena); |
| 5545 | if (res != 0) goto failed; |
| 5546 | Py_XDECREF(tmp); |
| 5547 | tmp = NULL; |
| 5548 | } else { |
| 5549 | PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num"); |
| 5550 | return 1; |
| 5551 | } |
| 5552 | *out = Num(n, lineno, col_offset, arena); |
| 5553 | if (*out == NULL) goto failed; |
| 5554 | return 0; |
| 5555 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5556 | isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type); |
| 5557 | if (isinstance == -1) { |
| 5558 | return 1; |
| 5559 | } |
| 5560 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5561 | string s; |
| 5562 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5563 | if (_PyObject_HasAttrId(obj, &PyId_s)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5564 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5565 | tmp = _PyObject_GetAttrId(obj, &PyId_s); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5566 | if (tmp == NULL) goto failed; |
| 5567 | res = obj2ast_string(tmp, &s, arena); |
| 5568 | if (res != 0) goto failed; |
| 5569 | Py_XDECREF(tmp); |
| 5570 | tmp = NULL; |
| 5571 | } else { |
| 5572 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str"); |
| 5573 | return 1; |
| 5574 | } |
| 5575 | *out = Str(s, lineno, col_offset, arena); |
| 5576 | if (*out == NULL) goto failed; |
| 5577 | return 0; |
| 5578 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5579 | isinstance = PyObject_IsInstance(obj, (PyObject*)Bytes_type); |
| 5580 | if (isinstance == -1) { |
| 5581 | return 1; |
| 5582 | } |
| 5583 | if (isinstance) { |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 5584 | bytes s; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5585 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5586 | if (_PyObject_HasAttrId(obj, &PyId_s)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5587 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5588 | tmp = _PyObject_GetAttrId(obj, &PyId_s); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5589 | if (tmp == NULL) goto failed; |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 5590 | res = obj2ast_bytes(tmp, &s, arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5591 | if (res != 0) goto failed; |
| 5592 | Py_XDECREF(tmp); |
| 5593 | tmp = NULL; |
| 5594 | } else { |
| 5595 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Bytes"); |
| 5596 | return 1; |
| 5597 | } |
| 5598 | *out = Bytes(s, lineno, col_offset, arena); |
| 5599 | if (*out == NULL) goto failed; |
| 5600 | return 0; |
| 5601 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5602 | isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type); |
| 5603 | if (isinstance == -1) { |
| 5604 | return 1; |
| 5605 | } |
| 5606 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5607 | |
| 5608 | *out = Ellipsis(lineno, col_offset, arena); |
| 5609 | if (*out == NULL) goto failed; |
| 5610 | return 0; |
| 5611 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5612 | isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type); |
| 5613 | if (isinstance == -1) { |
| 5614 | return 1; |
| 5615 | } |
| 5616 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5617 | expr_ty value; |
| 5618 | identifier attr; |
| 5619 | expr_context_ty ctx; |
| 5620 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5621 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5622 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5623 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5624 | if (tmp == NULL) goto failed; |
| 5625 | res = obj2ast_expr(tmp, &value, arena); |
| 5626 | if (res != 0) goto failed; |
| 5627 | Py_XDECREF(tmp); |
| 5628 | tmp = NULL; |
| 5629 | } else { |
| 5630 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 5631 | return 1; |
| 5632 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5633 | if (_PyObject_HasAttrId(obj, &PyId_attr)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5634 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5635 | tmp = _PyObject_GetAttrId(obj, &PyId_attr); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5636 | if (tmp == NULL) goto failed; |
| 5637 | res = obj2ast_identifier(tmp, &attr, arena); |
| 5638 | if (res != 0) goto failed; |
| 5639 | Py_XDECREF(tmp); |
| 5640 | tmp = NULL; |
| 5641 | } else { |
| 5642 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 5643 | return 1; |
| 5644 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5645 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5646 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5647 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5648 | if (tmp == NULL) goto failed; |
| 5649 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5650 | if (res != 0) goto failed; |
| 5651 | Py_XDECREF(tmp); |
| 5652 | tmp = NULL; |
| 5653 | } else { |
| 5654 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 5655 | return 1; |
| 5656 | } |
| 5657 | *out = Attribute(value, attr, ctx, lineno, col_offset, arena); |
| 5658 | if (*out == NULL) goto failed; |
| 5659 | return 0; |
| 5660 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5661 | isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type); |
| 5662 | if (isinstance == -1) { |
| 5663 | return 1; |
| 5664 | } |
| 5665 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5666 | expr_ty value; |
| 5667 | slice_ty slice; |
| 5668 | expr_context_ty ctx; |
| 5669 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5670 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5671 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5672 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5673 | if (tmp == NULL) goto failed; |
| 5674 | res = obj2ast_expr(tmp, &value, arena); |
| 5675 | if (res != 0) goto failed; |
| 5676 | Py_XDECREF(tmp); |
| 5677 | tmp = NULL; |
| 5678 | } else { |
| 5679 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 5680 | return 1; |
| 5681 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5682 | if (_PyObject_HasAttrId(obj, &PyId_slice)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5683 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5684 | tmp = _PyObject_GetAttrId(obj, &PyId_slice); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5685 | if (tmp == NULL) goto failed; |
| 5686 | res = obj2ast_slice(tmp, &slice, arena); |
| 5687 | if (res != 0) goto failed; |
| 5688 | Py_XDECREF(tmp); |
| 5689 | tmp = NULL; |
| 5690 | } else { |
| 5691 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 5692 | return 1; |
| 5693 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5694 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5695 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5696 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5697 | if (tmp == NULL) goto failed; |
| 5698 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5699 | if (res != 0) goto failed; |
| 5700 | Py_XDECREF(tmp); |
| 5701 | tmp = NULL; |
| 5702 | } else { |
| 5703 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 5704 | return 1; |
| 5705 | } |
| 5706 | *out = Subscript(value, slice, ctx, lineno, col_offset, arena); |
| 5707 | if (*out == NULL) goto failed; |
| 5708 | return 0; |
| 5709 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5710 | isinstance = PyObject_IsInstance(obj, (PyObject*)Starred_type); |
| 5711 | if (isinstance == -1) { |
| 5712 | return 1; |
| 5713 | } |
| 5714 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5715 | expr_ty value; |
| 5716 | expr_context_ty ctx; |
| 5717 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5718 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5719 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5720 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5721 | if (tmp == NULL) goto failed; |
| 5722 | res = obj2ast_expr(tmp, &value, arena); |
| 5723 | if (res != 0) goto failed; |
| 5724 | Py_XDECREF(tmp); |
| 5725 | tmp = NULL; |
| 5726 | } else { |
| 5727 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 5728 | return 1; |
| 5729 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5730 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5731 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5732 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5733 | if (tmp == NULL) goto failed; |
| 5734 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5735 | if (res != 0) goto failed; |
| 5736 | Py_XDECREF(tmp); |
| 5737 | tmp = NULL; |
| 5738 | } else { |
| 5739 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 5740 | return 1; |
| 5741 | } |
| 5742 | *out = Starred(value, ctx, lineno, col_offset, arena); |
| 5743 | if (*out == NULL) goto failed; |
| 5744 | return 0; |
| 5745 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5746 | isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type); |
| 5747 | if (isinstance == -1) { |
| 5748 | return 1; |
| 5749 | } |
| 5750 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5751 | identifier id; |
| 5752 | expr_context_ty ctx; |
| 5753 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5754 | if (_PyObject_HasAttrId(obj, &PyId_id)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5755 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5756 | tmp = _PyObject_GetAttrId(obj, &PyId_id); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5757 | if (tmp == NULL) goto failed; |
| 5758 | res = obj2ast_identifier(tmp, &id, arena); |
| 5759 | if (res != 0) goto failed; |
| 5760 | Py_XDECREF(tmp); |
| 5761 | tmp = NULL; |
| 5762 | } else { |
| 5763 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 5764 | return 1; |
| 5765 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5766 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5767 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5768 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5769 | if (tmp == NULL) goto failed; |
| 5770 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5771 | if (res != 0) goto failed; |
| 5772 | Py_XDECREF(tmp); |
| 5773 | tmp = NULL; |
| 5774 | } else { |
| 5775 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 5776 | return 1; |
| 5777 | } |
| 5778 | *out = Name(id, ctx, lineno, col_offset, arena); |
| 5779 | if (*out == NULL) goto failed; |
| 5780 | return 0; |
| 5781 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5782 | isinstance = PyObject_IsInstance(obj, (PyObject*)List_type); |
| 5783 | if (isinstance == -1) { |
| 5784 | return 1; |
| 5785 | } |
| 5786 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5787 | asdl_seq* elts; |
| 5788 | expr_context_ty ctx; |
| 5789 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5790 | if (_PyObject_HasAttrId(obj, &PyId_elts)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5791 | int res; |
| 5792 | Py_ssize_t len; |
| 5793 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5794 | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5795 | if (tmp == NULL) goto failed; |
| 5796 | if (!PyList_Check(tmp)) { |
| 5797 | PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5798 | goto failed; |
| 5799 | } |
| 5800 | len = PyList_GET_SIZE(tmp); |
| 5801 | elts = asdl_seq_new(len, arena); |
| 5802 | if (elts == NULL) goto failed; |
| 5803 | for (i = 0; i < len; i++) { |
| 5804 | expr_ty value; |
| 5805 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5806 | if (res != 0) goto failed; |
| 5807 | asdl_seq_SET(elts, i, value); |
| 5808 | } |
| 5809 | Py_XDECREF(tmp); |
| 5810 | tmp = NULL; |
| 5811 | } else { |
| 5812 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 5813 | return 1; |
| 5814 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5815 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5816 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5817 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5818 | if (tmp == NULL) goto failed; |
| 5819 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5820 | if (res != 0) goto failed; |
| 5821 | Py_XDECREF(tmp); |
| 5822 | tmp = NULL; |
| 5823 | } else { |
| 5824 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 5825 | return 1; |
| 5826 | } |
| 5827 | *out = List(elts, ctx, lineno, col_offset, arena); |
| 5828 | if (*out == NULL) goto failed; |
| 5829 | return 0; |
| 5830 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5831 | isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type); |
| 5832 | if (isinstance == -1) { |
| 5833 | return 1; |
| 5834 | } |
| 5835 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5836 | asdl_seq* elts; |
| 5837 | expr_context_ty ctx; |
| 5838 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5839 | if (_PyObject_HasAttrId(obj, &PyId_elts)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5840 | int res; |
| 5841 | Py_ssize_t len; |
| 5842 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5843 | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5844 | if (tmp == NULL) goto failed; |
| 5845 | if (!PyList_Check(tmp)) { |
| 5846 | PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5847 | goto failed; |
| 5848 | } |
| 5849 | len = PyList_GET_SIZE(tmp); |
| 5850 | elts = asdl_seq_new(len, arena); |
| 5851 | if (elts == NULL) goto failed; |
| 5852 | for (i = 0; i < len; i++) { |
| 5853 | expr_ty value; |
| 5854 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5855 | if (res != 0) goto failed; |
| 5856 | asdl_seq_SET(elts, i, value); |
| 5857 | } |
| 5858 | Py_XDECREF(tmp); |
| 5859 | tmp = NULL; |
| 5860 | } else { |
| 5861 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 5862 | return 1; |
| 5863 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5864 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5865 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5866 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5867 | if (tmp == NULL) goto failed; |
| 5868 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5869 | if (res != 0) goto failed; |
| 5870 | Py_XDECREF(tmp); |
| 5871 | tmp = NULL; |
| 5872 | } else { |
| 5873 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 5874 | return 1; |
| 5875 | } |
| 5876 | *out = Tuple(elts, ctx, lineno, col_offset, arena); |
| 5877 | if (*out == NULL) goto failed; |
| 5878 | return 0; |
| 5879 | } |
| 5880 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 5881 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
| 5882 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 5883 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5884 | return 1; |
| 5885 | } |
| 5886 | |
| 5887 | int |
| 5888 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 5889 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5890 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5891 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5892 | isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); |
| 5893 | if (isinstance == -1) { |
| 5894 | return 1; |
| 5895 | } |
| 5896 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5897 | *out = Load; |
| 5898 | return 0; |
| 5899 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5900 | isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type); |
| 5901 | if (isinstance == -1) { |
| 5902 | return 1; |
| 5903 | } |
| 5904 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5905 | *out = Store; |
| 5906 | return 0; |
| 5907 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5908 | isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type); |
| 5909 | if (isinstance == -1) { |
| 5910 | return 1; |
| 5911 | } |
| 5912 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5913 | *out = Del; |
| 5914 | return 0; |
| 5915 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5916 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type); |
| 5917 | if (isinstance == -1) { |
| 5918 | return 1; |
| 5919 | } |
| 5920 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5921 | *out = AugLoad; |
| 5922 | return 0; |
| 5923 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5924 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type); |
| 5925 | if (isinstance == -1) { |
| 5926 | return 1; |
| 5927 | } |
| 5928 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5929 | *out = AugStore; |
| 5930 | return 0; |
| 5931 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5932 | isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type); |
| 5933 | if (isinstance == -1) { |
| 5934 | return 1; |
| 5935 | } |
| 5936 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5937 | *out = Param; |
| 5938 | return 0; |
| 5939 | } |
| 5940 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 5941 | 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] | 5942 | return 1; |
| 5943 | } |
| 5944 | |
| 5945 | int |
| 5946 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
| 5947 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5948 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5949 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 5950 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5951 | |
| 5952 | if (obj == Py_None) { |
| 5953 | *out = NULL; |
| 5954 | return 0; |
| 5955 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5956 | isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type); |
| 5957 | if (isinstance == -1) { |
| 5958 | return 1; |
| 5959 | } |
| 5960 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5961 | expr_ty lower; |
| 5962 | expr_ty upper; |
| 5963 | expr_ty step; |
| 5964 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5965 | if (_PyObject_HasAttrId(obj, &PyId_lower)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5966 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5967 | tmp = _PyObject_GetAttrId(obj, &PyId_lower); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5968 | if (tmp == NULL) goto failed; |
| 5969 | res = obj2ast_expr(tmp, &lower, arena); |
| 5970 | if (res != 0) goto failed; |
| 5971 | Py_XDECREF(tmp); |
| 5972 | tmp = NULL; |
| 5973 | } else { |
| 5974 | lower = NULL; |
| 5975 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5976 | if (_PyObject_HasAttrId(obj, &PyId_upper)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5977 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5978 | tmp = _PyObject_GetAttrId(obj, &PyId_upper); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5979 | if (tmp == NULL) goto failed; |
| 5980 | res = obj2ast_expr(tmp, &upper, arena); |
| 5981 | if (res != 0) goto failed; |
| 5982 | Py_XDECREF(tmp); |
| 5983 | tmp = NULL; |
| 5984 | } else { |
| 5985 | upper = NULL; |
| 5986 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5987 | if (_PyObject_HasAttrId(obj, &PyId_step)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5988 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5989 | tmp = _PyObject_GetAttrId(obj, &PyId_step); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5990 | if (tmp == NULL) goto failed; |
| 5991 | res = obj2ast_expr(tmp, &step, arena); |
| 5992 | if (res != 0) goto failed; |
| 5993 | Py_XDECREF(tmp); |
| 5994 | tmp = NULL; |
| 5995 | } else { |
| 5996 | step = NULL; |
| 5997 | } |
| 5998 | *out = Slice(lower, upper, step, arena); |
| 5999 | if (*out == NULL) goto failed; |
| 6000 | return 0; |
| 6001 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6002 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type); |
| 6003 | if (isinstance == -1) { |
| 6004 | return 1; |
| 6005 | } |
| 6006 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6007 | asdl_seq* dims; |
| 6008 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6009 | if (_PyObject_HasAttrId(obj, &PyId_dims)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6010 | int res; |
| 6011 | Py_ssize_t len; |
| 6012 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6013 | tmp = _PyObject_GetAttrId(obj, &PyId_dims); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6014 | if (tmp == NULL) goto failed; |
| 6015 | if (!PyList_Check(tmp)) { |
| 6016 | PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6017 | goto failed; |
| 6018 | } |
| 6019 | len = PyList_GET_SIZE(tmp); |
| 6020 | dims = asdl_seq_new(len, arena); |
| 6021 | if (dims == NULL) goto failed; |
| 6022 | for (i = 0; i < len; i++) { |
| 6023 | slice_ty value; |
| 6024 | res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6025 | if (res != 0) goto failed; |
| 6026 | asdl_seq_SET(dims, i, value); |
| 6027 | } |
| 6028 | Py_XDECREF(tmp); |
| 6029 | tmp = NULL; |
| 6030 | } else { |
| 6031 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
| 6032 | return 1; |
| 6033 | } |
| 6034 | *out = ExtSlice(dims, arena); |
| 6035 | if (*out == NULL) goto failed; |
| 6036 | return 0; |
| 6037 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6038 | isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type); |
| 6039 | if (isinstance == -1) { |
| 6040 | return 1; |
| 6041 | } |
| 6042 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6043 | expr_ty value; |
| 6044 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6045 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6046 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6047 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6048 | if (tmp == NULL) goto failed; |
| 6049 | res = obj2ast_expr(tmp, &value, arena); |
| 6050 | if (res != 0) goto failed; |
| 6051 | Py_XDECREF(tmp); |
| 6052 | tmp = NULL; |
| 6053 | } else { |
| 6054 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
| 6055 | return 1; |
| 6056 | } |
| 6057 | *out = Index(value, arena); |
| 6058 | if (*out == NULL) goto failed; |
| 6059 | return 0; |
| 6060 | } |
| 6061 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6062 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj); |
| 6063 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 6064 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6065 | return 1; |
| 6066 | } |
| 6067 | |
| 6068 | int |
| 6069 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 6070 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6071 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6072 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6073 | isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); |
| 6074 | if (isinstance == -1) { |
| 6075 | return 1; |
| 6076 | } |
| 6077 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6078 | *out = And; |
| 6079 | return 0; |
| 6080 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6081 | isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type); |
| 6082 | if (isinstance == -1) { |
| 6083 | return 1; |
| 6084 | } |
| 6085 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6086 | *out = Or; |
| 6087 | return 0; |
| 6088 | } |
| 6089 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6090 | 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] | 6091 | return 1; |
| 6092 | } |
| 6093 | |
| 6094 | int |
| 6095 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 6096 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6097 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6098 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6099 | isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); |
| 6100 | if (isinstance == -1) { |
| 6101 | return 1; |
| 6102 | } |
| 6103 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6104 | *out = Add; |
| 6105 | return 0; |
| 6106 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6107 | isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type); |
| 6108 | if (isinstance == -1) { |
| 6109 | return 1; |
| 6110 | } |
| 6111 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6112 | *out = Sub; |
| 6113 | return 0; |
| 6114 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6115 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type); |
| 6116 | if (isinstance == -1) { |
| 6117 | return 1; |
| 6118 | } |
| 6119 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6120 | *out = Mult; |
| 6121 | return 0; |
| 6122 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6123 | isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type); |
| 6124 | if (isinstance == -1) { |
| 6125 | return 1; |
| 6126 | } |
| 6127 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6128 | *out = Div; |
| 6129 | return 0; |
| 6130 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6131 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type); |
| 6132 | if (isinstance == -1) { |
| 6133 | return 1; |
| 6134 | } |
| 6135 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6136 | *out = Mod; |
| 6137 | return 0; |
| 6138 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6139 | isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type); |
| 6140 | if (isinstance == -1) { |
| 6141 | return 1; |
| 6142 | } |
| 6143 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6144 | *out = Pow; |
| 6145 | return 0; |
| 6146 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6147 | isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type); |
| 6148 | if (isinstance == -1) { |
| 6149 | return 1; |
| 6150 | } |
| 6151 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6152 | *out = LShift; |
| 6153 | return 0; |
| 6154 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6155 | isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type); |
| 6156 | if (isinstance == -1) { |
| 6157 | return 1; |
| 6158 | } |
| 6159 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6160 | *out = RShift; |
| 6161 | return 0; |
| 6162 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6163 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type); |
| 6164 | if (isinstance == -1) { |
| 6165 | return 1; |
| 6166 | } |
| 6167 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6168 | *out = BitOr; |
| 6169 | return 0; |
| 6170 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6171 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type); |
| 6172 | if (isinstance == -1) { |
| 6173 | return 1; |
| 6174 | } |
| 6175 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6176 | *out = BitXor; |
| 6177 | return 0; |
| 6178 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6179 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type); |
| 6180 | if (isinstance == -1) { |
| 6181 | return 1; |
| 6182 | } |
| 6183 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6184 | *out = BitAnd; |
| 6185 | return 0; |
| 6186 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6187 | isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type); |
| 6188 | if (isinstance == -1) { |
| 6189 | return 1; |
| 6190 | } |
| 6191 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6192 | *out = FloorDiv; |
| 6193 | return 0; |
| 6194 | } |
| 6195 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6196 | 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] | 6197 | return 1; |
| 6198 | } |
| 6199 | |
| 6200 | int |
| 6201 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 6202 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6203 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6204 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6205 | isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); |
| 6206 | if (isinstance == -1) { |
| 6207 | return 1; |
| 6208 | } |
| 6209 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6210 | *out = Invert; |
| 6211 | return 0; |
| 6212 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6213 | isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type); |
| 6214 | if (isinstance == -1) { |
| 6215 | return 1; |
| 6216 | } |
| 6217 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6218 | *out = Not; |
| 6219 | return 0; |
| 6220 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6221 | isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type); |
| 6222 | if (isinstance == -1) { |
| 6223 | return 1; |
| 6224 | } |
| 6225 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6226 | *out = UAdd; |
| 6227 | return 0; |
| 6228 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6229 | isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type); |
| 6230 | if (isinstance == -1) { |
| 6231 | return 1; |
| 6232 | } |
| 6233 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6234 | *out = USub; |
| 6235 | return 0; |
| 6236 | } |
| 6237 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6238 | 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] | 6239 | return 1; |
| 6240 | } |
| 6241 | |
| 6242 | int |
| 6243 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 6244 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6245 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6246 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6247 | isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); |
| 6248 | if (isinstance == -1) { |
| 6249 | return 1; |
| 6250 | } |
| 6251 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6252 | *out = Eq; |
| 6253 | return 0; |
| 6254 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6255 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type); |
| 6256 | if (isinstance == -1) { |
| 6257 | return 1; |
| 6258 | } |
| 6259 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6260 | *out = NotEq; |
| 6261 | return 0; |
| 6262 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6263 | isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type); |
| 6264 | if (isinstance == -1) { |
| 6265 | return 1; |
| 6266 | } |
| 6267 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6268 | *out = Lt; |
| 6269 | return 0; |
| 6270 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6271 | isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type); |
| 6272 | if (isinstance == -1) { |
| 6273 | return 1; |
| 6274 | } |
| 6275 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6276 | *out = LtE; |
| 6277 | return 0; |
| 6278 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6279 | isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type); |
| 6280 | if (isinstance == -1) { |
| 6281 | return 1; |
| 6282 | } |
| 6283 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6284 | *out = Gt; |
| 6285 | return 0; |
| 6286 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6287 | isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type); |
| 6288 | if (isinstance == -1) { |
| 6289 | return 1; |
| 6290 | } |
| 6291 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6292 | *out = GtE; |
| 6293 | return 0; |
| 6294 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6295 | isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type); |
| 6296 | if (isinstance == -1) { |
| 6297 | return 1; |
| 6298 | } |
| 6299 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6300 | *out = Is; |
| 6301 | return 0; |
| 6302 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6303 | isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type); |
| 6304 | if (isinstance == -1) { |
| 6305 | return 1; |
| 6306 | } |
| 6307 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6308 | *out = IsNot; |
| 6309 | return 0; |
| 6310 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6311 | isinstance = PyObject_IsInstance(obj, (PyObject *)In_type); |
| 6312 | if (isinstance == -1) { |
| 6313 | return 1; |
| 6314 | } |
| 6315 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6316 | *out = In; |
| 6317 | return 0; |
| 6318 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6319 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type); |
| 6320 | if (isinstance == -1) { |
| 6321 | return 1; |
| 6322 | } |
| 6323 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6324 | *out = NotIn; |
| 6325 | return 0; |
| 6326 | } |
| 6327 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6328 | 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] | 6329 | return 1; |
| 6330 | } |
| 6331 | |
| 6332 | int |
| 6333 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 6334 | { |
| 6335 | PyObject* tmp = NULL; |
| 6336 | expr_ty target; |
| 6337 | expr_ty iter; |
| 6338 | asdl_seq* ifs; |
| 6339 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6340 | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6341 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6342 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6343 | if (tmp == NULL) goto failed; |
| 6344 | res = obj2ast_expr(tmp, &target, arena); |
| 6345 | if (res != 0) goto failed; |
| 6346 | Py_XDECREF(tmp); |
| 6347 | tmp = NULL; |
| 6348 | } else { |
| 6349 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 6350 | return 1; |
| 6351 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6352 | if (_PyObject_HasAttrId(obj, &PyId_iter)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6353 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6354 | tmp = _PyObject_GetAttrId(obj, &PyId_iter); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6355 | if (tmp == NULL) goto failed; |
| 6356 | res = obj2ast_expr(tmp, &iter, arena); |
| 6357 | if (res != 0) goto failed; |
| 6358 | Py_XDECREF(tmp); |
| 6359 | tmp = NULL; |
| 6360 | } else { |
| 6361 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 6362 | return 1; |
| 6363 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6364 | if (_PyObject_HasAttrId(obj, &PyId_ifs)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6365 | int res; |
| 6366 | Py_ssize_t len; |
| 6367 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6368 | tmp = _PyObject_GetAttrId(obj, &PyId_ifs); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6369 | if (tmp == NULL) goto failed; |
| 6370 | if (!PyList_Check(tmp)) { |
| 6371 | PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6372 | goto failed; |
| 6373 | } |
| 6374 | len = PyList_GET_SIZE(tmp); |
| 6375 | ifs = asdl_seq_new(len, arena); |
| 6376 | if (ifs == NULL) goto failed; |
| 6377 | for (i = 0; i < len; i++) { |
| 6378 | expr_ty value; |
| 6379 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6380 | if (res != 0) goto failed; |
| 6381 | asdl_seq_SET(ifs, i, value); |
| 6382 | } |
| 6383 | Py_XDECREF(tmp); |
| 6384 | tmp = NULL; |
| 6385 | } else { |
| 6386 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 6387 | return 1; |
| 6388 | } |
| 6389 | *out = comprehension(target, iter, ifs, arena); |
| 6390 | return 0; |
| 6391 | failed: |
| 6392 | Py_XDECREF(tmp); |
| 6393 | return 1; |
| 6394 | } |
| 6395 | |
| 6396 | int |
| 6397 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 6398 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6399 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6400 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 6401 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6402 | int lineno; |
| 6403 | int col_offset; |
| 6404 | |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6405 | if (obj == Py_None) { |
| 6406 | *out = NULL; |
| 6407 | return 0; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6408 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6409 | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6410 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6411 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6412 | if (tmp == NULL) goto failed; |
| 6413 | res = obj2ast_int(tmp, &lineno, arena); |
| 6414 | if (res != 0) goto failed; |
| 6415 | Py_XDECREF(tmp); |
| 6416 | tmp = NULL; |
| 6417 | } else { |
| 6418 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 6419 | return 1; |
| 6420 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6421 | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6422 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6423 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6424 | if (tmp == NULL) goto failed; |
| 6425 | res = obj2ast_int(tmp, &col_offset, arena); |
| 6426 | if (res != 0) goto failed; |
| 6427 | Py_XDECREF(tmp); |
| 6428 | tmp = NULL; |
| 6429 | } else { |
| 6430 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 6431 | return 1; |
| 6432 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6433 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type); |
| 6434 | if (isinstance == -1) { |
| 6435 | return 1; |
| 6436 | } |
| 6437 | if (isinstance) { |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6438 | expr_ty type; |
| 6439 | identifier name; |
| 6440 | asdl_seq* body; |
| 6441 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6442 | if (_PyObject_HasAttrId(obj, &PyId_type)) { |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6443 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6444 | tmp = _PyObject_GetAttrId(obj, &PyId_type); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6445 | if (tmp == NULL) goto failed; |
| 6446 | res = obj2ast_expr(tmp, &type, arena); |
| 6447 | if (res != 0) goto failed; |
| 6448 | Py_XDECREF(tmp); |
| 6449 | tmp = NULL; |
| 6450 | } else { |
| 6451 | type = NULL; |
| 6452 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6453 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6454 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6455 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6456 | if (tmp == NULL) goto failed; |
| 6457 | res = obj2ast_identifier(tmp, &name, arena); |
| 6458 | if (res != 0) goto failed; |
| 6459 | Py_XDECREF(tmp); |
| 6460 | tmp = NULL; |
| 6461 | } else { |
| 6462 | name = NULL; |
| 6463 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6464 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6465 | int res; |
| 6466 | Py_ssize_t len; |
| 6467 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6468 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6469 | if (tmp == NULL) goto failed; |
| 6470 | if (!PyList_Check(tmp)) { |
| 6471 | PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6472 | goto failed; |
| 6473 | } |
| 6474 | len = PyList_GET_SIZE(tmp); |
| 6475 | body = asdl_seq_new(len, arena); |
| 6476 | if (body == NULL) goto failed; |
| 6477 | for (i = 0; i < len; i++) { |
| 6478 | stmt_ty value; |
| 6479 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6480 | if (res != 0) goto failed; |
| 6481 | asdl_seq_SET(body, i, value); |
| 6482 | } |
| 6483 | Py_XDECREF(tmp); |
| 6484 | tmp = NULL; |
| 6485 | } else { |
| 6486 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 6487 | return 1; |
| 6488 | } |
| 6489 | *out = ExceptHandler(type, name, body, lineno, col_offset, |
| 6490 | arena); |
| 6491 | if (*out == NULL) goto failed; |
| 6492 | return 0; |
| 6493 | } |
| 6494 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6495 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
| 6496 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 6497 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6498 | return 1; |
| 6499 | } |
| 6500 | |
| 6501 | int |
| 6502 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 6503 | { |
| 6504 | PyObject* tmp = NULL; |
| 6505 | asdl_seq* args; |
| 6506 | identifier vararg; |
| 6507 | expr_ty varargannotation; |
| 6508 | asdl_seq* kwonlyargs; |
| 6509 | identifier kwarg; |
| 6510 | expr_ty kwargannotation; |
| 6511 | asdl_seq* defaults; |
| 6512 | asdl_seq* kw_defaults; |
| 6513 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6514 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6515 | int res; |
| 6516 | Py_ssize_t len; |
| 6517 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6518 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6519 | if (tmp == NULL) goto failed; |
| 6520 | if (!PyList_Check(tmp)) { |
| 6521 | PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6522 | goto failed; |
| 6523 | } |
| 6524 | len = PyList_GET_SIZE(tmp); |
| 6525 | args = asdl_seq_new(len, arena); |
| 6526 | if (args == NULL) goto failed; |
| 6527 | for (i = 0; i < len; i++) { |
| 6528 | arg_ty value; |
| 6529 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6530 | if (res != 0) goto failed; |
| 6531 | asdl_seq_SET(args, i, value); |
| 6532 | } |
| 6533 | Py_XDECREF(tmp); |
| 6534 | tmp = NULL; |
| 6535 | } else { |
| 6536 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 6537 | return 1; |
| 6538 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6539 | if (_PyObject_HasAttrId(obj, &PyId_vararg)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6540 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6541 | tmp = _PyObject_GetAttrId(obj, &PyId_vararg); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6542 | if (tmp == NULL) goto failed; |
| 6543 | res = obj2ast_identifier(tmp, &vararg, arena); |
| 6544 | if (res != 0) goto failed; |
| 6545 | Py_XDECREF(tmp); |
| 6546 | tmp = NULL; |
| 6547 | } else { |
| 6548 | vararg = NULL; |
| 6549 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6550 | if (_PyObject_HasAttrId(obj, &PyId_varargannotation)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6551 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6552 | tmp = _PyObject_GetAttrId(obj, &PyId_varargannotation); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6553 | if (tmp == NULL) goto failed; |
| 6554 | res = obj2ast_expr(tmp, &varargannotation, arena); |
| 6555 | if (res != 0) goto failed; |
| 6556 | Py_XDECREF(tmp); |
| 6557 | tmp = NULL; |
| 6558 | } else { |
| 6559 | varargannotation = NULL; |
| 6560 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6561 | if (_PyObject_HasAttrId(obj, &PyId_kwonlyargs)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6562 | int res; |
| 6563 | Py_ssize_t len; |
| 6564 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6565 | tmp = _PyObject_GetAttrId(obj, &PyId_kwonlyargs); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6566 | if (tmp == NULL) goto failed; |
| 6567 | if (!PyList_Check(tmp)) { |
| 6568 | PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6569 | goto failed; |
| 6570 | } |
| 6571 | len = PyList_GET_SIZE(tmp); |
| 6572 | kwonlyargs = asdl_seq_new(len, arena); |
| 6573 | if (kwonlyargs == NULL) goto failed; |
| 6574 | for (i = 0; i < len; i++) { |
| 6575 | arg_ty value; |
| 6576 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6577 | if (res != 0) goto failed; |
| 6578 | asdl_seq_SET(kwonlyargs, i, value); |
| 6579 | } |
| 6580 | Py_XDECREF(tmp); |
| 6581 | tmp = NULL; |
| 6582 | } else { |
| 6583 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 6584 | return 1; |
| 6585 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6586 | if (_PyObject_HasAttrId(obj, &PyId_kwarg)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6587 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6588 | tmp = _PyObject_GetAttrId(obj, &PyId_kwarg); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6589 | if (tmp == NULL) goto failed; |
| 6590 | res = obj2ast_identifier(tmp, &kwarg, arena); |
| 6591 | if (res != 0) goto failed; |
| 6592 | Py_XDECREF(tmp); |
| 6593 | tmp = NULL; |
| 6594 | } else { |
| 6595 | kwarg = NULL; |
| 6596 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6597 | if (_PyObject_HasAttrId(obj, &PyId_kwargannotation)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6598 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6599 | tmp = _PyObject_GetAttrId(obj, &PyId_kwargannotation); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6600 | if (tmp == NULL) goto failed; |
| 6601 | res = obj2ast_expr(tmp, &kwargannotation, arena); |
| 6602 | if (res != 0) goto failed; |
| 6603 | Py_XDECREF(tmp); |
| 6604 | tmp = NULL; |
| 6605 | } else { |
| 6606 | kwargannotation = NULL; |
| 6607 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6608 | if (_PyObject_HasAttrId(obj, &PyId_defaults)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6609 | int res; |
| 6610 | Py_ssize_t len; |
| 6611 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6612 | tmp = _PyObject_GetAttrId(obj, &PyId_defaults); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6613 | if (tmp == NULL) goto failed; |
| 6614 | if (!PyList_Check(tmp)) { |
| 6615 | PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6616 | goto failed; |
| 6617 | } |
| 6618 | len = PyList_GET_SIZE(tmp); |
| 6619 | defaults = asdl_seq_new(len, arena); |
| 6620 | if (defaults == NULL) goto failed; |
| 6621 | for (i = 0; i < len; i++) { |
| 6622 | expr_ty value; |
| 6623 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6624 | if (res != 0) goto failed; |
| 6625 | asdl_seq_SET(defaults, i, value); |
| 6626 | } |
| 6627 | Py_XDECREF(tmp); |
| 6628 | tmp = NULL; |
| 6629 | } else { |
| 6630 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 6631 | return 1; |
| 6632 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6633 | if (_PyObject_HasAttrId(obj, &PyId_kw_defaults)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6634 | int res; |
| 6635 | Py_ssize_t len; |
| 6636 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6637 | tmp = _PyObject_GetAttrId(obj, &PyId_kw_defaults); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6638 | if (tmp == NULL) goto failed; |
| 6639 | if (!PyList_Check(tmp)) { |
| 6640 | PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6641 | goto failed; |
| 6642 | } |
| 6643 | len = PyList_GET_SIZE(tmp); |
| 6644 | kw_defaults = asdl_seq_new(len, arena); |
| 6645 | if (kw_defaults == NULL) goto failed; |
| 6646 | for (i = 0; i < len; i++) { |
| 6647 | expr_ty value; |
| 6648 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6649 | if (res != 0) goto failed; |
| 6650 | asdl_seq_SET(kw_defaults, i, value); |
| 6651 | } |
| 6652 | Py_XDECREF(tmp); |
| 6653 | tmp = NULL; |
| 6654 | } else { |
| 6655 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 6656 | return 1; |
| 6657 | } |
| 6658 | *out = arguments(args, vararg, varargannotation, kwonlyargs, kwarg, |
| 6659 | kwargannotation, defaults, kw_defaults, arena); |
| 6660 | return 0; |
| 6661 | failed: |
| 6662 | Py_XDECREF(tmp); |
| 6663 | return 1; |
| 6664 | } |
| 6665 | |
| 6666 | int |
| 6667 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 6668 | { |
| 6669 | PyObject* tmp = NULL; |
| 6670 | identifier arg; |
| 6671 | expr_ty annotation; |
| 6672 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6673 | if (_PyObject_HasAttrId(obj, &PyId_arg)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6674 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6675 | tmp = _PyObject_GetAttrId(obj, &PyId_arg); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6676 | if (tmp == NULL) goto failed; |
| 6677 | res = obj2ast_identifier(tmp, &arg, arena); |
| 6678 | if (res != 0) goto failed; |
| 6679 | Py_XDECREF(tmp); |
| 6680 | tmp = NULL; |
| 6681 | } else { |
| 6682 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
| 6683 | return 1; |
| 6684 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6685 | if (_PyObject_HasAttrId(obj, &PyId_annotation)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6686 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6687 | tmp = _PyObject_GetAttrId(obj, &PyId_annotation); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6688 | if (tmp == NULL) goto failed; |
| 6689 | res = obj2ast_expr(tmp, &annotation, arena); |
| 6690 | if (res != 0) goto failed; |
| 6691 | Py_XDECREF(tmp); |
| 6692 | tmp = NULL; |
| 6693 | } else { |
| 6694 | annotation = NULL; |
| 6695 | } |
| 6696 | *out = arg(arg, annotation, arena); |
| 6697 | return 0; |
| 6698 | failed: |
| 6699 | Py_XDECREF(tmp); |
| 6700 | return 1; |
| 6701 | } |
| 6702 | |
| 6703 | int |
| 6704 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 6705 | { |
| 6706 | PyObject* tmp = NULL; |
| 6707 | identifier arg; |
| 6708 | expr_ty value; |
| 6709 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6710 | if (_PyObject_HasAttrId(obj, &PyId_arg)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6711 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6712 | tmp = _PyObject_GetAttrId(obj, &PyId_arg); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6713 | if (tmp == NULL) goto failed; |
| 6714 | res = obj2ast_identifier(tmp, &arg, arena); |
| 6715 | if (res != 0) goto failed; |
| 6716 | Py_XDECREF(tmp); |
| 6717 | tmp = NULL; |
| 6718 | } else { |
| 6719 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from keyword"); |
| 6720 | return 1; |
| 6721 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6722 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6723 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6724 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6725 | if (tmp == NULL) goto failed; |
| 6726 | res = obj2ast_expr(tmp, &value, arena); |
| 6727 | if (res != 0) goto failed; |
| 6728 | Py_XDECREF(tmp); |
| 6729 | tmp = NULL; |
| 6730 | } else { |
| 6731 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 6732 | return 1; |
| 6733 | } |
| 6734 | *out = keyword(arg, value, arena); |
| 6735 | return 0; |
| 6736 | failed: |
| 6737 | Py_XDECREF(tmp); |
| 6738 | return 1; |
| 6739 | } |
| 6740 | |
| 6741 | int |
| 6742 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 6743 | { |
| 6744 | PyObject* tmp = NULL; |
| 6745 | identifier name; |
| 6746 | identifier asname; |
| 6747 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6748 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
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_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6751 | if (tmp == NULL) goto failed; |
| 6752 | res = obj2ast_identifier(tmp, &name, arena); |
| 6753 | if (res != 0) goto failed; |
| 6754 | Py_XDECREF(tmp); |
| 6755 | tmp = NULL; |
| 6756 | } else { |
| 6757 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 6758 | return 1; |
| 6759 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6760 | if (_PyObject_HasAttrId(obj, &PyId_asname)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6761 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6762 | tmp = _PyObject_GetAttrId(obj, &PyId_asname); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6763 | if (tmp == NULL) goto failed; |
| 6764 | res = obj2ast_identifier(tmp, &asname, arena); |
| 6765 | if (res != 0) goto failed; |
| 6766 | Py_XDECREF(tmp); |
| 6767 | tmp = NULL; |
| 6768 | } else { |
| 6769 | asname = NULL; |
| 6770 | } |
| 6771 | *out = alias(name, asname, arena); |
| 6772 | return 0; |
| 6773 | failed: |
| 6774 | Py_XDECREF(tmp); |
| 6775 | return 1; |
| 6776 | } |
| 6777 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6778 | int |
| 6779 | obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) |
| 6780 | { |
| 6781 | PyObject* tmp = NULL; |
| 6782 | expr_ty context_expr; |
| 6783 | expr_ty optional_vars; |
| 6784 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6785 | if (_PyObject_HasAttrId(obj, &PyId_context_expr)) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [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_context_expr); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6788 | if (tmp == NULL) goto failed; |
| 6789 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 6790 | if (res != 0) goto failed; |
| 6791 | Py_XDECREF(tmp); |
| 6792 | tmp = NULL; |
| 6793 | } else { |
| 6794 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); |
| 6795 | return 1; |
| 6796 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6797 | if (_PyObject_HasAttrId(obj, &PyId_optional_vars)) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6798 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6799 | tmp = _PyObject_GetAttrId(obj, &PyId_optional_vars); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6800 | if (tmp == NULL) goto failed; |
| 6801 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 6802 | if (res != 0) goto failed; |
| 6803 | Py_XDECREF(tmp); |
| 6804 | tmp = NULL; |
| 6805 | } else { |
| 6806 | optional_vars = NULL; |
| 6807 | } |
| 6808 | *out = withitem(context_expr, optional_vars, arena); |
| 6809 | return 0; |
| 6810 | failed: |
| 6811 | Py_XDECREF(tmp); |
| 6812 | return 1; |
| 6813 | } |
| 6814 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6815 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6816 | static struct PyModuleDef _astmodule = { |
| 6817 | PyModuleDef_HEAD_INIT, "_ast" |
| 6818 | }; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6819 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6820 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6821 | { |
| 6822 | PyObject *m, *d; |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6823 | if (!init_types()) return NULL; |
| 6824 | m = PyModule_Create(&_astmodule); |
| 6825 | if (!m) return NULL; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6826 | d = PyModule_GetDict(m); |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6827 | if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return |
| 6828 | NULL; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6829 | 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] | 6830 | return NULL; |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6831 | if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return |
| 6832 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6833 | if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6834 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6835 | if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6836 | < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6837 | if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6838 | 0) return NULL; |
| 6839 | if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return |
| 6840 | NULL; |
| 6841 | if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return |
| 6842 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6843 | if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6844 | < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6845 | if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6846 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6847 | if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6848 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6849 | if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6850 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6851 | if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6852 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6853 | if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6854 | 0) return NULL; |
| 6855 | if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return |
| 6856 | NULL; |
| 6857 | if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return |
| 6858 | NULL; |
| 6859 | if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return NULL; |
| 6860 | if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return |
| 6861 | NULL; |
| 6862 | if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return |
| 6863 | NULL; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 6864 | if (PyDict_SetItemString(d, "Try", (PyObject*)Try_type) < 0) return |
| 6865 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6866 | if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6867 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6868 | if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6869 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6870 | if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6871 | 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6872 | if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6873 | return NULL; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 6874 | if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6875 | return NULL; |
| 6876 | if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return |
| 6877 | NULL; |
| 6878 | if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return |
| 6879 | NULL; |
| 6880 | if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return |
| 6881 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6882 | if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6883 | return NULL; |
| 6884 | if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return |
| 6885 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6886 | if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6887 | return NULL; |
| 6888 | if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return |
| 6889 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6890 | if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6891 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6892 | if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6893 | return NULL; |
| 6894 | if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return |
| 6895 | NULL; |
| 6896 | if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return |
| 6897 | NULL; |
| 6898 | if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return |
| 6899 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6900 | if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6901 | return NULL; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 6902 | if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6903 | return NULL; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 6904 | if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6905 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6906 | if (PyDict_SetItemString(d, "GeneratorExp", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6907 | (PyObject*)GeneratorExp_type) < 0) return NULL; |
| 6908 | if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return |
| 6909 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6910 | if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6911 | return NULL; |
| 6912 | if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return |
| 6913 | NULL; |
| 6914 | if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return |
| 6915 | NULL; |
| 6916 | if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return |
| 6917 | NULL; |
| 6918 | if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return |
| 6919 | NULL; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 6920 | if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6921 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6922 | if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6923 | 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6924 | if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6925 | 0) return NULL; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 6926 | if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6927 | return NULL; |
| 6928 | if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return |
| 6929 | NULL; |
| 6930 | if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return |
| 6931 | NULL; |
| 6932 | if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return |
| 6933 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6934 | if (PyDict_SetItemString(d, "expr_context", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6935 | (PyObject*)expr_context_type) < 0) return NULL; |
| 6936 | if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return |
| 6937 | NULL; |
| 6938 | if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return |
| 6939 | NULL; |
| 6940 | if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return |
| 6941 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6942 | if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6943 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6944 | if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6945 | return NULL; |
| 6946 | if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return |
| 6947 | NULL; |
| 6948 | if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return |
| 6949 | NULL; |
| 6950 | if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return |
| 6951 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6952 | if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6953 | return NULL; |
| 6954 | if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return |
| 6955 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6956 | if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6957 | return NULL; |
| 6958 | if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return |
| 6959 | NULL; |
| 6960 | if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6961 | if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6962 | return NULL; |
| 6963 | if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return |
| 6964 | NULL; |
| 6965 | if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return |
| 6966 | NULL; |
| 6967 | if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return |
| 6968 | NULL; |
| 6969 | if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return |
| 6970 | NULL; |
| 6971 | if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return |
| 6972 | NULL; |
| 6973 | if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return |
| 6974 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6975 | if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6976 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6977 | if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6978 | return NULL; |
| 6979 | if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return |
| 6980 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6981 | if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6982 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6983 | if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6984 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6985 | if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_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, "unaryop", (PyObject*)unaryop_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6988 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6989 | if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6990 | return NULL; |
| 6991 | if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return |
| 6992 | NULL; |
| 6993 | if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return |
| 6994 | NULL; |
| 6995 | if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return |
| 6996 | NULL; |
| 6997 | if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return |
| 6998 | NULL; |
| 6999 | if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return NULL; |
| 7000 | if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return |
| 7001 | NULL; |
| 7002 | if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return NULL; |
| 7003 | if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return |
| 7004 | NULL; |
| 7005 | if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return NULL; |
| 7006 | if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return |
| 7007 | NULL; |
| 7008 | if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return NULL; |
| 7009 | if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return |
| 7010 | NULL; |
| 7011 | if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return NULL; |
| 7012 | if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return |
| 7013 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7014 | if (PyDict_SetItemString(d, "comprehension", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7015 | (PyObject*)comprehension_type) < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7016 | if (PyDict_SetItemString(d, "excepthandler", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7017 | (PyObject*)excepthandler_type) < 0) return NULL; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 7018 | if (PyDict_SetItemString(d, "ExceptHandler", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7019 | (PyObject*)ExceptHandler_type) < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7020 | if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7021 | 0) return NULL; |
| 7022 | if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return |
| 7023 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7024 | if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7025 | return NULL; |
| 7026 | if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return |
| 7027 | NULL; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 7028 | if (PyDict_SetItemString(d, "withitem", (PyObject*)withitem_type) < 0) |
| 7029 | return NULL; |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7030 | return m; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 7031 | } |
| 7032 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 7033 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 7034 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 7035 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 7036 | init_types(); |
| 7037 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 7038 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 7039 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7040 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 7041 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7042 | { |
| 7043 | mod_ty res; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7044 | PyObject *req_type[] = {(PyObject*)Module_type, (PyObject*)Expression_type, |
| 7045 | (PyObject*)Interactive_type}; |
| 7046 | char *req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 7047 | int isinstance; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7048 | assert(0 <= mode && mode <= 2); |
| 7049 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7050 | init_types(); |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7051 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 7052 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 7053 | if (isinstance == -1) |
| 7054 | return NULL; |
| 7055 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7056 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
| 7057 | req_name[mode], Py_TYPE(ast)->tp_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7058 | return NULL; |
| 7059 | } |
| 7060 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 7061 | return NULL; |
| 7062 | else |
| 7063 | return res; |
| 7064 | } |
| 7065 | |
| 7066 | int PyAST_Check(PyObject* obj) |
| 7067 | { |
| 7068 | init_types(); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 7069 | return PyObject_IsInstance(obj, (PyObject*)&AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7070 | } |
| 7071 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 7072 | |