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; |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame^] | 234 | _Py_IDENTIFIER(is_from); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 235 | static char *Yield_fields[]={ |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame^] | 236 | "is_from", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 237 | "value", |
| 238 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 239 | static PyTypeObject *Compare_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 240 | _Py_IDENTIFIER(ops); |
| 241 | _Py_IDENTIFIER(comparators); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 242 | static char *Compare_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 243 | "left", |
| 244 | "ops", |
| 245 | "comparators", |
| 246 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 247 | static PyTypeObject *Call_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 248 | _Py_IDENTIFIER(func); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 249 | static char *Call_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 250 | "func", |
| 251 | "args", |
| 252 | "keywords", |
| 253 | "starargs", |
| 254 | "kwargs", |
| 255 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 256 | static PyTypeObject *Num_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 257 | _Py_IDENTIFIER(n); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 258 | static char *Num_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 259 | "n", |
| 260 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 261 | static PyTypeObject *Str_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 262 | _Py_IDENTIFIER(s); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 263 | static char *Str_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 264 | "s", |
| 265 | }; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 266 | static PyTypeObject *Bytes_type; |
| 267 | static char *Bytes_fields[]={ |
| 268 | "s", |
| 269 | }; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 270 | static PyTypeObject *Ellipsis_type; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 271 | static PyTypeObject *Attribute_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 272 | _Py_IDENTIFIER(attr); |
| 273 | _Py_IDENTIFIER(ctx); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 274 | static char *Attribute_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 275 | "value", |
| 276 | "attr", |
| 277 | "ctx", |
| 278 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 279 | static PyTypeObject *Subscript_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 280 | _Py_IDENTIFIER(slice); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 281 | static char *Subscript_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 282 | "value", |
| 283 | "slice", |
| 284 | "ctx", |
| 285 | }; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 286 | static PyTypeObject *Starred_type; |
| 287 | static char *Starred_fields[]={ |
| 288 | "value", |
| 289 | "ctx", |
| 290 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 291 | static PyTypeObject *Name_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 292 | _Py_IDENTIFIER(id); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 293 | static char *Name_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 294 | "id", |
| 295 | "ctx", |
| 296 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 297 | static PyTypeObject *List_type; |
| 298 | static char *List_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 299 | "elts", |
| 300 | "ctx", |
| 301 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 302 | static PyTypeObject *Tuple_type; |
| 303 | static char *Tuple_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 304 | "elts", |
| 305 | "ctx", |
| 306 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 307 | static PyTypeObject *expr_context_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 308 | static PyObject *Load_singleton, *Store_singleton, *Del_singleton, |
| 309 | *AugLoad_singleton, *AugStore_singleton, *Param_singleton; |
| 310 | static PyObject* ast2obj_expr_context(expr_context_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 311 | static PyTypeObject *Load_type; |
| 312 | static PyTypeObject *Store_type; |
| 313 | static PyTypeObject *Del_type; |
| 314 | static PyTypeObject *AugLoad_type; |
| 315 | static PyTypeObject *AugStore_type; |
| 316 | static PyTypeObject *Param_type; |
| 317 | static PyTypeObject *slice_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 318 | static PyObject* ast2obj_slice(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 319 | static PyTypeObject *Slice_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 320 | _Py_IDENTIFIER(lower); |
| 321 | _Py_IDENTIFIER(upper); |
| 322 | _Py_IDENTIFIER(step); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 323 | static char *Slice_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 324 | "lower", |
| 325 | "upper", |
| 326 | "step", |
| 327 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 328 | static PyTypeObject *ExtSlice_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 329 | _Py_IDENTIFIER(dims); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 330 | static char *ExtSlice_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 331 | "dims", |
| 332 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 333 | static PyTypeObject *Index_type; |
| 334 | static char *Index_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 335 | "value", |
| 336 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 337 | static PyTypeObject *boolop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 338 | static PyObject *And_singleton, *Or_singleton; |
| 339 | static PyObject* ast2obj_boolop(boolop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 340 | static PyTypeObject *And_type; |
| 341 | static PyTypeObject *Or_type; |
| 342 | static PyTypeObject *operator_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 343 | static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton, |
| 344 | *Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton, |
| 345 | *RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton, |
| 346 | *FloorDiv_singleton; |
| 347 | static PyObject* ast2obj_operator(operator_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 348 | static PyTypeObject *Add_type; |
| 349 | static PyTypeObject *Sub_type; |
| 350 | static PyTypeObject *Mult_type; |
| 351 | static PyTypeObject *Div_type; |
| 352 | static PyTypeObject *Mod_type; |
| 353 | static PyTypeObject *Pow_type; |
| 354 | static PyTypeObject *LShift_type; |
| 355 | static PyTypeObject *RShift_type; |
| 356 | static PyTypeObject *BitOr_type; |
| 357 | static PyTypeObject *BitXor_type; |
| 358 | static PyTypeObject *BitAnd_type; |
| 359 | static PyTypeObject *FloorDiv_type; |
| 360 | static PyTypeObject *unaryop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 361 | static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton, |
| 362 | *USub_singleton; |
| 363 | static PyObject* ast2obj_unaryop(unaryop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 364 | static PyTypeObject *Invert_type; |
| 365 | static PyTypeObject *Not_type; |
| 366 | static PyTypeObject *UAdd_type; |
| 367 | static PyTypeObject *USub_type; |
| 368 | static PyTypeObject *cmpop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 369 | static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton, |
| 370 | *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton, |
| 371 | *NotIn_singleton; |
| 372 | static PyObject* ast2obj_cmpop(cmpop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 373 | static PyTypeObject *Eq_type; |
| 374 | static PyTypeObject *NotEq_type; |
| 375 | static PyTypeObject *Lt_type; |
| 376 | static PyTypeObject *LtE_type; |
| 377 | static PyTypeObject *Gt_type; |
| 378 | static PyTypeObject *GtE_type; |
| 379 | static PyTypeObject *Is_type; |
| 380 | static PyTypeObject *IsNot_type; |
| 381 | static PyTypeObject *In_type; |
| 382 | static PyTypeObject *NotIn_type; |
| 383 | static PyTypeObject *comprehension_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 384 | static PyObject* ast2obj_comprehension(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 385 | _Py_IDENTIFIER(ifs); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 386 | static char *comprehension_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 387 | "target", |
| 388 | "iter", |
| 389 | "ifs", |
| 390 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 391 | static PyTypeObject *excepthandler_type; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 392 | static char *excepthandler_attributes[] = { |
| 393 | "lineno", |
| 394 | "col_offset", |
| 395 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 396 | static PyObject* ast2obj_excepthandler(void*); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 397 | static PyTypeObject *ExceptHandler_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 398 | _Py_IDENTIFIER(type); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 399 | static char *ExceptHandler_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 400 | "type", |
| 401 | "name", |
| 402 | "body", |
| 403 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 404 | static PyTypeObject *arguments_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 405 | static PyObject* ast2obj_arguments(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 406 | _Py_IDENTIFIER(vararg); |
| 407 | _Py_IDENTIFIER(varargannotation); |
| 408 | _Py_IDENTIFIER(kwonlyargs); |
| 409 | _Py_IDENTIFIER(kwarg); |
| 410 | _Py_IDENTIFIER(kwargannotation); |
| 411 | _Py_IDENTIFIER(defaults); |
| 412 | _Py_IDENTIFIER(kw_defaults); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 413 | static char *arguments_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 414 | "args", |
| 415 | "vararg", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 416 | "varargannotation", |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 417 | "kwonlyargs", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 418 | "kwarg", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 419 | "kwargannotation", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 420 | "defaults", |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 421 | "kw_defaults", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 422 | }; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 423 | static PyTypeObject *arg_type; |
| 424 | static PyObject* ast2obj_arg(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 425 | _Py_IDENTIFIER(arg); |
| 426 | _Py_IDENTIFIER(annotation); |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 427 | static char *arg_fields[]={ |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 428 | "arg", |
| 429 | "annotation", |
| 430 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 431 | static PyTypeObject *keyword_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 432 | static PyObject* ast2obj_keyword(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 433 | static char *keyword_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 434 | "arg", |
| 435 | "value", |
| 436 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 437 | static PyTypeObject *alias_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 438 | static PyObject* ast2obj_alias(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 439 | _Py_IDENTIFIER(asname); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 440 | static char *alias_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 441 | "name", |
| 442 | "asname", |
| 443 | }; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 444 | static PyTypeObject *withitem_type; |
| 445 | static PyObject* ast2obj_withitem(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 446 | _Py_IDENTIFIER(context_expr); |
| 447 | _Py_IDENTIFIER(optional_vars); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 448 | static char *withitem_fields[]={ |
| 449 | "context_expr", |
| 450 | "optional_vars", |
| 451 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 452 | |
| 453 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 454 | static int |
| 455 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 456 | { |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 457 | _Py_IDENTIFIER(_fields); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 458 | Py_ssize_t i, numfields = 0; |
| 459 | int res = -1; |
| 460 | PyObject *key, *value, *fields; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 461 | fields = _PyObject_GetAttrId((PyObject*)Py_TYPE(self), &PyId__fields); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 462 | if (!fields) |
| 463 | PyErr_Clear(); |
| 464 | if (fields) { |
| 465 | numfields = PySequence_Size(fields); |
| 466 | if (numfields == -1) |
| 467 | goto cleanup; |
| 468 | } |
| 469 | res = 0; /* if no error occurs, this stays 0 to the end */ |
| 470 | if (PyTuple_GET_SIZE(args) > 0) { |
| 471 | if (numfields != PyTuple_GET_SIZE(args)) { |
| 472 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes %s" |
Amaury Forgeot d'Arc | 245c70b | 2008-09-10 22:24:24 +0000 | [diff] [blame] | 473 | "%zd positional argument%s", |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 474 | Py_TYPE(self)->tp_name, |
| 475 | numfields == 0 ? "" : "either 0 or ", |
| 476 | numfields, numfields == 1 ? "" : "s"); |
| 477 | res = -1; |
| 478 | goto cleanup; |
| 479 | } |
| 480 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
| 481 | /* cannot be reached when fields is NULL */ |
| 482 | PyObject *name = PySequence_GetItem(fields, i); |
| 483 | if (!name) { |
| 484 | res = -1; |
| 485 | goto cleanup; |
| 486 | } |
| 487 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
| 488 | Py_DECREF(name); |
| 489 | if (res < 0) |
| 490 | goto cleanup; |
| 491 | } |
| 492 | } |
| 493 | if (kw) { |
| 494 | i = 0; /* needed by PyDict_Next */ |
| 495 | while (PyDict_Next(kw, &i, &key, &value)) { |
| 496 | res = PyObject_SetAttr(self, key, value); |
| 497 | if (res < 0) |
| 498 | goto cleanup; |
| 499 | } |
| 500 | } |
| 501 | cleanup: |
| 502 | Py_XDECREF(fields); |
| 503 | return res; |
| 504 | } |
| 505 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 506 | /* Pickling support */ |
| 507 | static PyObject * |
| 508 | ast_type_reduce(PyObject *self, PyObject *unused) |
| 509 | { |
| 510 | PyObject *res; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 511 | _Py_IDENTIFIER(__dict__); |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 512 | PyObject *dict = _PyObject_GetAttrId(self, &PyId___dict__); |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 513 | if (dict == NULL) { |
| 514 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) |
| 515 | PyErr_Clear(); |
| 516 | else |
| 517 | return NULL; |
| 518 | } |
| 519 | if (dict) { |
| 520 | res = Py_BuildValue("O()O", Py_TYPE(self), dict); |
| 521 | Py_DECREF(dict); |
| 522 | return res; |
| 523 | } |
| 524 | return Py_BuildValue("O()", Py_TYPE(self)); |
| 525 | } |
| 526 | |
| 527 | static PyMethodDef ast_type_methods[] = { |
| 528 | {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, |
| 529 | {NULL} |
| 530 | }; |
| 531 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 532 | static PyTypeObject AST_type = { |
| 533 | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 534 | "_ast.AST", |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 535 | sizeof(PyObject), |
| 536 | 0, |
| 537 | 0, /* tp_dealloc */ |
| 538 | 0, /* tp_print */ |
| 539 | 0, /* tp_getattr */ |
| 540 | 0, /* tp_setattr */ |
Mark Dickinson | e94c679 | 2009-02-02 20:36:42 +0000 | [diff] [blame] | 541 | 0, /* tp_reserved */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 542 | 0, /* tp_repr */ |
| 543 | 0, /* tp_as_number */ |
| 544 | 0, /* tp_as_sequence */ |
| 545 | 0, /* tp_as_mapping */ |
| 546 | 0, /* tp_hash */ |
| 547 | 0, /* tp_call */ |
| 548 | 0, /* tp_str */ |
| 549 | PyObject_GenericGetAttr, /* tp_getattro */ |
| 550 | PyObject_GenericSetAttr, /* tp_setattro */ |
| 551 | 0, /* tp_as_buffer */ |
| 552 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
| 553 | 0, /* tp_doc */ |
| 554 | 0, /* tp_traverse */ |
| 555 | 0, /* tp_clear */ |
| 556 | 0, /* tp_richcompare */ |
| 557 | 0, /* tp_weaklistoffset */ |
| 558 | 0, /* tp_iter */ |
| 559 | 0, /* tp_iternext */ |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 560 | ast_type_methods, /* tp_methods */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 561 | 0, /* tp_members */ |
| 562 | 0, /* tp_getset */ |
| 563 | 0, /* tp_base */ |
| 564 | 0, /* tp_dict */ |
| 565 | 0, /* tp_descr_get */ |
| 566 | 0, /* tp_descr_set */ |
| 567 | 0, /* tp_dictoffset */ |
| 568 | (initproc)ast_type_init, /* tp_init */ |
| 569 | PyType_GenericAlloc, /* tp_alloc */ |
| 570 | PyType_GenericNew, /* tp_new */ |
| 571 | PyObject_Del, /* tp_free */ |
| 572 | }; |
| 573 | |
| 574 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 575 | static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields) |
| 576 | { |
| 577 | PyObject *fnames, *result; |
| 578 | int i; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 579 | fnames = PyTuple_New(num_fields); |
| 580 | if (!fnames) return NULL; |
| 581 | for (i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 582 | PyObject *field = PyUnicode_FromString(fields[i]); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 583 | if (!field) { |
| 584 | Py_DECREF(fnames); |
| 585 | return NULL; |
| 586 | } |
| 587 | PyTuple_SET_ITEM(fnames, i, field); |
| 588 | } |
Victor Stinner | 7eeb5b5 | 2010-06-07 19:57:46 +0000 | [diff] [blame] | 589 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 590 | type, base, "_fields", fnames, "__module__", "_ast"); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 591 | Py_DECREF(fnames); |
| 592 | return (PyTypeObject*)result; |
| 593 | } |
| 594 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 595 | static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) |
| 596 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 597 | int i, result; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 598 | _Py_IDENTIFIER(_attributes); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 599 | PyObject *s, *l = PyTuple_New(num_fields); |
Benjamin Peterson | 3e5cd1d | 2010-06-27 21:45:24 +0000 | [diff] [blame] | 600 | if (!l) |
| 601 | return 0; |
| 602 | for (i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 603 | s = PyUnicode_FromString(attrs[i]); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 604 | if (!s) { |
| 605 | Py_DECREF(l); |
| 606 | return 0; |
| 607 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 608 | PyTuple_SET_ITEM(l, i, s); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 609 | } |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 610 | result = _PyObject_SetAttrId((PyObject*)type, &PyId__attributes, l) >= 0; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 611 | Py_DECREF(l); |
| 612 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 613 | } |
| 614 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 615 | /* Conversion AST -> Python */ |
| 616 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 617 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 618 | { |
| 619 | int i, n = asdl_seq_LEN(seq); |
| 620 | PyObject *result = PyList_New(n); |
| 621 | PyObject *value; |
| 622 | if (!result) |
| 623 | return NULL; |
| 624 | for (i = 0; i < n; i++) { |
| 625 | value = func(asdl_seq_GET(seq, i)); |
| 626 | if (!value) { |
| 627 | Py_DECREF(result); |
| 628 | return NULL; |
| 629 | } |
| 630 | PyList_SET_ITEM(result, i, value); |
| 631 | } |
| 632 | return result; |
| 633 | } |
| 634 | |
| 635 | static PyObject* ast2obj_object(void *o) |
| 636 | { |
| 637 | if (!o) |
| 638 | o = Py_None; |
| 639 | Py_INCREF((PyObject*)o); |
| 640 | return (PyObject*)o; |
| 641 | } |
| 642 | #define ast2obj_identifier ast2obj_object |
| 643 | #define ast2obj_string ast2obj_object |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 644 | #define ast2obj_bytes ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 645 | |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 646 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 647 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 648 | return PyLong_FromLong(b); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 649 | } |
| 650 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 651 | /* Conversion Python -> AST */ |
| 652 | |
| 653 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 654 | { |
| 655 | if (obj == Py_None) |
| 656 | obj = NULL; |
| 657 | if (obj) |
| 658 | PyArena_AddPyObject(arena, obj); |
| 659 | Py_XINCREF(obj); |
| 660 | *out = obj; |
| 661 | return 0; |
| 662 | } |
| 663 | |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 664 | static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 665 | { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 666 | if (!PyUnicode_CheckExact(obj) && obj != Py_None) { |
| 667 | PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 668 | return 1; |
| 669 | } |
| 670 | return obj2ast_object(obj, out, arena); |
| 671 | } |
| 672 | |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 673 | static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) |
| 674 | { |
Benjamin Peterson | 0224d4e | 2011-08-31 22:13:03 -0400 | [diff] [blame] | 675 | if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 676 | PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); |
| 677 | return 1; |
| 678 | } |
| 679 | return obj2ast_object(obj, out, arena); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 680 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 681 | |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 682 | static int obj2ast_bytes(PyObject* obj, PyObject** out, PyArena* arena) |
| 683 | { |
| 684 | if (!PyBytes_CheckExact(obj)) { |
| 685 | PyErr_SetString(PyExc_TypeError, "AST bytes must be of type bytes"); |
| 686 | return 1; |
| 687 | } |
| 688 | return obj2ast_object(obj, out, arena); |
| 689 | } |
| 690 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 691 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 692 | { |
| 693 | int i; |
| 694 | if (!PyLong_Check(obj)) { |
Amaury Forgeot d'Arc | 5e8f810 | 2011-11-22 21:52:30 +0100 | [diff] [blame] | 695 | PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 696 | return 1; |
| 697 | } |
| 698 | |
| 699 | i = (int)PyLong_AsLong(obj); |
| 700 | if (i == -1 && PyErr_Occurred()) |
| 701 | return 1; |
| 702 | *out = i; |
| 703 | return 0; |
| 704 | } |
| 705 | |
Benjamin Peterson | 1a6e0d0 | 2008-10-25 15:49:17 +0000 | [diff] [blame] | 706 | static int add_ast_fields(void) |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 707 | { |
| 708 | PyObject *empty_tuple, *d; |
| 709 | if (PyType_Ready(&AST_type) < 0) |
| 710 | return -1; |
| 711 | d = AST_type.tp_dict; |
| 712 | empty_tuple = PyTuple_New(0); |
| 713 | if (!empty_tuple || |
| 714 | PyDict_SetItemString(d, "_fields", empty_tuple) < 0 || |
| 715 | PyDict_SetItemString(d, "_attributes", empty_tuple) < 0) { |
| 716 | Py_XDECREF(empty_tuple); |
| 717 | return -1; |
| 718 | } |
| 719 | Py_DECREF(empty_tuple); |
| 720 | return 0; |
| 721 | } |
| 722 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 723 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 724 | static int init_types(void) |
| 725 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 726 | static int initialized; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 727 | if (initialized) return 1; |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 728 | if (add_ast_fields() < 0) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 729 | mod_type = make_type("mod", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 730 | if (!mod_type) return 0; |
| 731 | if (!add_attributes(mod_type, NULL, 0)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 732 | Module_type = make_type("Module", mod_type, Module_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 733 | if (!Module_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 734 | Interactive_type = make_type("Interactive", mod_type, |
| 735 | Interactive_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 736 | if (!Interactive_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 737 | Expression_type = make_type("Expression", mod_type, Expression_fields, |
| 738 | 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 739 | if (!Expression_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 740 | Suite_type = make_type("Suite", mod_type, Suite_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 741 | if (!Suite_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 742 | stmt_type = make_type("stmt", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 743 | if (!stmt_type) return 0; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 744 | if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 745 | FunctionDef_type = make_type("FunctionDef", stmt_type, |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 746 | FunctionDef_fields, 5); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 747 | if (!FunctionDef_type) return 0; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 748 | ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 7); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 749 | if (!ClassDef_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 750 | Return_type = make_type("Return", stmt_type, Return_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 751 | if (!Return_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 752 | Delete_type = make_type("Delete", stmt_type, Delete_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 753 | if (!Delete_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 754 | Assign_type = make_type("Assign", stmt_type, Assign_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 755 | if (!Assign_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 756 | AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 757 | if (!AugAssign_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 758 | For_type = make_type("For", stmt_type, For_fields, 4); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 759 | if (!For_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 760 | While_type = make_type("While", stmt_type, While_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 761 | if (!While_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 762 | If_type = make_type("If", stmt_type, If_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 763 | if (!If_type) return 0; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 764 | With_type = make_type("With", stmt_type, With_fields, 2); |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 765 | if (!With_type) return 0; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 766 | Raise_type = make_type("Raise", stmt_type, Raise_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 767 | if (!Raise_type) return 0; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 768 | Try_type = make_type("Try", stmt_type, Try_fields, 4); |
| 769 | if (!Try_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 770 | Assert_type = make_type("Assert", stmt_type, Assert_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 771 | if (!Assert_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 772 | Import_type = make_type("Import", stmt_type, Import_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 773 | if (!Import_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 774 | ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 775 | 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 776 | if (!ImportFrom_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 777 | Global_type = make_type("Global", stmt_type, Global_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 778 | if (!Global_type) return 0; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 779 | Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1); |
| 780 | if (!Nonlocal_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 781 | Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 782 | if (!Expr_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 783 | Pass_type = make_type("Pass", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 784 | if (!Pass_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 785 | Break_type = make_type("Break", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 786 | if (!Break_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 787 | Continue_type = make_type("Continue", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 788 | if (!Continue_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 789 | expr_type = make_type("expr", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 790 | if (!expr_type) return 0; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 791 | if (!add_attributes(expr_type, expr_attributes, 2)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 792 | BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 793 | if (!BoolOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 794 | BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 795 | if (!BinOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 796 | UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 797 | if (!UnaryOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 798 | Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 799 | if (!Lambda_type) return 0; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 800 | IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 801 | if (!IfExp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 802 | Dict_type = make_type("Dict", expr_type, Dict_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 803 | if (!Dict_type) return 0; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 804 | Set_type = make_type("Set", expr_type, Set_fields, 1); |
| 805 | if (!Set_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 806 | ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 807 | if (!ListComp_type) return 0; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 808 | SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2); |
| 809 | if (!SetComp_type) return 0; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 810 | DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3); |
| 811 | if (!DictComp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 812 | GeneratorExp_type = make_type("GeneratorExp", expr_type, |
| 813 | GeneratorExp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 814 | if (!GeneratorExp_type) return 0; |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame^] | 815 | Yield_type = make_type("Yield", expr_type, Yield_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 816 | if (!Yield_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 817 | Compare_type = make_type("Compare", expr_type, Compare_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 818 | if (!Compare_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 819 | Call_type = make_type("Call", expr_type, Call_fields, 5); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 820 | if (!Call_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 821 | Num_type = make_type("Num", expr_type, Num_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 822 | if (!Num_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 823 | Str_type = make_type("Str", expr_type, Str_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 824 | if (!Str_type) return 0; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 825 | Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1); |
| 826 | if (!Bytes_type) return 0; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 827 | Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0); |
| 828 | if (!Ellipsis_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 829 | Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 830 | if (!Attribute_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 831 | Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 832 | if (!Subscript_type) return 0; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 833 | Starred_type = make_type("Starred", expr_type, Starred_fields, 2); |
| 834 | if (!Starred_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 835 | Name_type = make_type("Name", expr_type, Name_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 836 | if (!Name_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 837 | List_type = make_type("List", expr_type, List_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 838 | if (!List_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 839 | Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 840 | if (!Tuple_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 841 | 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] | 842 | if (!expr_context_type) return 0; |
| 843 | if (!add_attributes(expr_context_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 844 | Load_type = make_type("Load", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 845 | if (!Load_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 846 | Load_singleton = PyType_GenericNew(Load_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 847 | if (!Load_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 848 | Store_type = make_type("Store", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 849 | if (!Store_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 850 | Store_singleton = PyType_GenericNew(Store_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 851 | if (!Store_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 852 | Del_type = make_type("Del", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 853 | if (!Del_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 854 | Del_singleton = PyType_GenericNew(Del_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 855 | if (!Del_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 856 | AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 857 | if (!AugLoad_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 858 | AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 859 | if (!AugLoad_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 860 | AugStore_type = make_type("AugStore", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 861 | if (!AugStore_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 862 | AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 863 | if (!AugStore_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 864 | Param_type = make_type("Param", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 865 | if (!Param_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 866 | Param_singleton = PyType_GenericNew(Param_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 867 | if (!Param_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 868 | slice_type = make_type("slice", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 869 | if (!slice_type) return 0; |
| 870 | if (!add_attributes(slice_type, NULL, 0)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 871 | Slice_type = make_type("Slice", slice_type, Slice_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 872 | if (!Slice_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 873 | ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 874 | if (!ExtSlice_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 875 | Index_type = make_type("Index", slice_type, Index_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 876 | if (!Index_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 877 | boolop_type = make_type("boolop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 878 | if (!boolop_type) return 0; |
| 879 | if (!add_attributes(boolop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 880 | And_type = make_type("And", boolop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 881 | if (!And_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 882 | And_singleton = PyType_GenericNew(And_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 883 | if (!And_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 884 | Or_type = make_type("Or", boolop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 885 | if (!Or_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 886 | Or_singleton = PyType_GenericNew(Or_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 887 | if (!Or_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 888 | operator_type = make_type("operator", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 889 | if (!operator_type) return 0; |
| 890 | if (!add_attributes(operator_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 891 | Add_type = make_type("Add", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 892 | if (!Add_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 893 | Add_singleton = PyType_GenericNew(Add_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 894 | if (!Add_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 895 | Sub_type = make_type("Sub", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 896 | if (!Sub_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 897 | Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 898 | if (!Sub_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 899 | Mult_type = make_type("Mult", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 900 | if (!Mult_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 901 | Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 902 | if (!Mult_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 903 | Div_type = make_type("Div", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 904 | if (!Div_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 905 | Div_singleton = PyType_GenericNew(Div_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 906 | if (!Div_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 907 | Mod_type = make_type("Mod", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 908 | if (!Mod_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 909 | Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 910 | if (!Mod_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 911 | Pow_type = make_type("Pow", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 912 | if (!Pow_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 913 | Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 914 | if (!Pow_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 915 | LShift_type = make_type("LShift", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 916 | if (!LShift_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 917 | LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 918 | if (!LShift_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 919 | RShift_type = make_type("RShift", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 920 | if (!RShift_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 921 | RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 922 | if (!RShift_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 923 | BitOr_type = make_type("BitOr", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 924 | if (!BitOr_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 925 | BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 926 | if (!BitOr_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 927 | BitXor_type = make_type("BitXor", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 928 | if (!BitXor_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 929 | BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 930 | if (!BitXor_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 931 | BitAnd_type = make_type("BitAnd", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 932 | if (!BitAnd_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 933 | BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 934 | if (!BitAnd_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 935 | FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 936 | if (!FloorDiv_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 937 | FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 938 | if (!FloorDiv_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 939 | unaryop_type = make_type("unaryop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 940 | if (!unaryop_type) return 0; |
| 941 | if (!add_attributes(unaryop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 942 | Invert_type = make_type("Invert", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 943 | if (!Invert_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 944 | Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 945 | if (!Invert_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 946 | Not_type = make_type("Not", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 947 | if (!Not_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 948 | Not_singleton = PyType_GenericNew(Not_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 949 | if (!Not_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 950 | UAdd_type = make_type("UAdd", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 951 | if (!UAdd_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 952 | UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 953 | if (!UAdd_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 954 | USub_type = make_type("USub", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 955 | if (!USub_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 956 | USub_singleton = PyType_GenericNew(USub_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 957 | if (!USub_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 958 | cmpop_type = make_type("cmpop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 959 | if (!cmpop_type) return 0; |
| 960 | if (!add_attributes(cmpop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 961 | Eq_type = make_type("Eq", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 962 | if (!Eq_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 963 | Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 964 | if (!Eq_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 965 | NotEq_type = make_type("NotEq", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 966 | if (!NotEq_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 967 | NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 968 | if (!NotEq_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 969 | Lt_type = make_type("Lt", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 970 | if (!Lt_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 971 | Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 972 | if (!Lt_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 973 | LtE_type = make_type("LtE", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 974 | if (!LtE_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 975 | LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 976 | if (!LtE_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 977 | Gt_type = make_type("Gt", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 978 | if (!Gt_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 979 | Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 980 | if (!Gt_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 981 | GtE_type = make_type("GtE", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 982 | if (!GtE_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 983 | GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 984 | if (!GtE_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 985 | Is_type = make_type("Is", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 986 | if (!Is_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 987 | Is_singleton = PyType_GenericNew(Is_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 988 | if (!Is_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 989 | IsNot_type = make_type("IsNot", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 990 | if (!IsNot_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 991 | IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 992 | if (!IsNot_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 993 | In_type = make_type("In", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 994 | if (!In_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 995 | In_singleton = PyType_GenericNew(In_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 996 | if (!In_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 997 | NotIn_type = make_type("NotIn", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 998 | if (!NotIn_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 999 | NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1000 | if (!NotIn_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1001 | comprehension_type = make_type("comprehension", &AST_type, |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1002 | comprehension_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1003 | if (!comprehension_type) return 0; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 1004 | excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1005 | if (!excepthandler_type) return 0; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 1006 | if (!add_attributes(excepthandler_type, excepthandler_attributes, 2)) |
| 1007 | return 0; |
| 1008 | ExceptHandler_type = make_type("ExceptHandler", excepthandler_type, |
| 1009 | ExceptHandler_fields, 3); |
| 1010 | if (!ExceptHandler_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1011 | arguments_type = make_type("arguments", &AST_type, arguments_fields, 8); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1012 | if (!arguments_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1013 | arg_type = make_type("arg", &AST_type, arg_fields, 2); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1014 | if (!arg_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1015 | keyword_type = make_type("keyword", &AST_type, keyword_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1016 | if (!keyword_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1017 | alias_type = make_type("alias", &AST_type, alias_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1018 | if (!alias_type) return 0; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1019 | withitem_type = make_type("withitem", &AST_type, withitem_fields, 2); |
| 1020 | if (!withitem_type) return 0; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1021 | initialized = 1; |
| 1022 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1023 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 1024 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1025 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 1026 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 1027 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 1028 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 1029 | arena); |
| 1030 | static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena); |
| 1031 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 1032 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 1033 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 1034 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 1035 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 1036 | arena); |
| 1037 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 1038 | arena); |
| 1039 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 1040 | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
| 1041 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 1042 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1043 | 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] | 1044 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1045 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1046 | Module(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1047 | { |
| 1048 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1049 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1050 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1051 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1052 | p->kind = Module_kind; |
| 1053 | p->v.Module.body = body; |
| 1054 | return p; |
| 1055 | } |
| 1056 | |
| 1057 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1058 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1059 | { |
| 1060 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1061 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1062 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1063 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1064 | p->kind = Interactive_kind; |
| 1065 | p->v.Interactive.body = body; |
| 1066 | return p; |
| 1067 | } |
| 1068 | |
| 1069 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1070 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1071 | { |
| 1072 | mod_ty p; |
| 1073 | if (!body) { |
| 1074 | PyErr_SetString(PyExc_ValueError, |
| 1075 | "field body is required for Expression"); |
| 1076 | return NULL; |
| 1077 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1078 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1079 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1080 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1081 | p->kind = Expression_kind; |
| 1082 | p->v.Expression.body = body; |
| 1083 | return p; |
| 1084 | } |
| 1085 | |
| 1086 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1087 | Suite(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1088 | { |
| 1089 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1090 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1091 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1092 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1093 | p->kind = Suite_kind; |
| 1094 | p->v.Suite.body = body; |
| 1095 | return p; |
| 1096 | } |
| 1097 | |
| 1098 | stmt_ty |
| 1099 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1100 | decorator_list, expr_ty returns, int lineno, int col_offset, |
| 1101 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1102 | { |
| 1103 | stmt_ty p; |
| 1104 | if (!name) { |
| 1105 | PyErr_SetString(PyExc_ValueError, |
| 1106 | "field name is required for FunctionDef"); |
| 1107 | return NULL; |
| 1108 | } |
| 1109 | if (!args) { |
| 1110 | PyErr_SetString(PyExc_ValueError, |
| 1111 | "field args is required for FunctionDef"); |
| 1112 | return NULL; |
| 1113 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1114 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1115 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1116 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1117 | p->kind = FunctionDef_kind; |
| 1118 | p->v.FunctionDef.name = name; |
| 1119 | p->v.FunctionDef.args = args; |
| 1120 | p->v.FunctionDef.body = body; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1121 | p->v.FunctionDef.decorator_list = decorator_list; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1122 | p->v.FunctionDef.returns = returns; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1123 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1124 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1125 | return p; |
| 1126 | } |
| 1127 | |
| 1128 | stmt_ty |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 1129 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, expr_ty |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1130 | starargs, expr_ty kwargs, asdl_seq * body, asdl_seq * decorator_list, |
| 1131 | int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1132 | { |
| 1133 | stmt_ty p; |
| 1134 | if (!name) { |
| 1135 | PyErr_SetString(PyExc_ValueError, |
| 1136 | "field name is required for ClassDef"); |
| 1137 | return NULL; |
| 1138 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1139 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1140 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1141 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1142 | p->kind = ClassDef_kind; |
| 1143 | p->v.ClassDef.name = name; |
| 1144 | p->v.ClassDef.bases = bases; |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 1145 | p->v.ClassDef.keywords = keywords; |
| 1146 | p->v.ClassDef.starargs = starargs; |
| 1147 | p->v.ClassDef.kwargs = kwargs; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1148 | p->v.ClassDef.body = body; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1149 | p->v.ClassDef.decorator_list = decorator_list; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1150 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1151 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1152 | return p; |
| 1153 | } |
| 1154 | |
| 1155 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1156 | Return(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1157 | { |
| 1158 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1159 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1160 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1161 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1162 | p->kind = Return_kind; |
| 1163 | p->v.Return.value = value; |
| 1164 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1165 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1166 | return p; |
| 1167 | } |
| 1168 | |
| 1169 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1170 | Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1171 | { |
| 1172 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1173 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1174 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1175 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1176 | p->kind = Delete_kind; |
| 1177 | p->v.Delete.targets = targets; |
| 1178 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1179 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1180 | return p; |
| 1181 | } |
| 1182 | |
| 1183 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1184 | Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena |
| 1185 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1186 | { |
| 1187 | stmt_ty p; |
| 1188 | if (!value) { |
| 1189 | PyErr_SetString(PyExc_ValueError, |
| 1190 | "field value is required for Assign"); |
| 1191 | return NULL; |
| 1192 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1193 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1194 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1195 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1196 | p->kind = Assign_kind; |
| 1197 | p->v.Assign.targets = targets; |
| 1198 | p->v.Assign.value = value; |
| 1199 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1200 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1201 | return p; |
| 1202 | } |
| 1203 | |
| 1204 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1205 | AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int |
| 1206 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1207 | { |
| 1208 | stmt_ty p; |
| 1209 | if (!target) { |
| 1210 | PyErr_SetString(PyExc_ValueError, |
| 1211 | "field target is required for AugAssign"); |
| 1212 | return NULL; |
| 1213 | } |
| 1214 | if (!op) { |
| 1215 | PyErr_SetString(PyExc_ValueError, |
| 1216 | "field op is required for AugAssign"); |
| 1217 | return NULL; |
| 1218 | } |
| 1219 | if (!value) { |
| 1220 | PyErr_SetString(PyExc_ValueError, |
| 1221 | "field value is required for AugAssign"); |
| 1222 | return NULL; |
| 1223 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1224 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1225 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1226 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1227 | p->kind = AugAssign_kind; |
| 1228 | p->v.AugAssign.target = target; |
| 1229 | p->v.AugAssign.op = op; |
| 1230 | p->v.AugAssign.value = value; |
| 1231 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1232 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1233 | return p; |
| 1234 | } |
| 1235 | |
| 1236 | stmt_ty |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1237 | 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] | 1238 | lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1239 | { |
| 1240 | stmt_ty p; |
| 1241 | if (!target) { |
| 1242 | PyErr_SetString(PyExc_ValueError, |
| 1243 | "field target is required for For"); |
| 1244 | return NULL; |
| 1245 | } |
| 1246 | if (!iter) { |
| 1247 | PyErr_SetString(PyExc_ValueError, |
| 1248 | "field iter is required for For"); |
| 1249 | return NULL; |
| 1250 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1251 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1252 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1253 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1254 | p->kind = For_kind; |
| 1255 | p->v.For.target = target; |
| 1256 | p->v.For.iter = iter; |
| 1257 | p->v.For.body = body; |
| 1258 | p->v.For.orelse = orelse; |
| 1259 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1260 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1261 | return p; |
| 1262 | } |
| 1263 | |
| 1264 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1265 | While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1266 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1267 | { |
| 1268 | stmt_ty p; |
| 1269 | if (!test) { |
| 1270 | PyErr_SetString(PyExc_ValueError, |
| 1271 | "field test is required for While"); |
| 1272 | return NULL; |
| 1273 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1274 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1275 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1276 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1277 | p->kind = While_kind; |
| 1278 | p->v.While.test = test; |
| 1279 | p->v.While.body = body; |
| 1280 | p->v.While.orelse = orelse; |
| 1281 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1282 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1283 | return p; |
| 1284 | } |
| 1285 | |
| 1286 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1287 | If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1288 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1289 | { |
| 1290 | stmt_ty p; |
| 1291 | if (!test) { |
| 1292 | PyErr_SetString(PyExc_ValueError, |
| 1293 | "field test is required for If"); |
| 1294 | return NULL; |
| 1295 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1296 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1297 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1298 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1299 | p->kind = If_kind; |
| 1300 | p->v.If.test = test; |
| 1301 | p->v.If.body = body; |
| 1302 | p->v.If.orelse = orelse; |
| 1303 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1304 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1305 | return p; |
| 1306 | } |
| 1307 | |
| 1308 | stmt_ty |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1309 | With(asdl_seq * items, asdl_seq * body, int lineno, int col_offset, PyArena |
| 1310 | *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1311 | { |
| 1312 | stmt_ty p; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1313 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1314 | if (!p) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1315 | return NULL; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1316 | p->kind = With_kind; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1317 | p->v.With.items = items; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1318 | p->v.With.body = body; |
| 1319 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1320 | p->col_offset = col_offset; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1321 | return p; |
| 1322 | } |
| 1323 | |
| 1324 | stmt_ty |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 1325 | 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] | 1326 | { |
| 1327 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1328 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1329 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1330 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1331 | p->kind = Raise_kind; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 1332 | p->v.Raise.exc = exc; |
| 1333 | p->v.Raise.cause = cause; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1334 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1335 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1336 | return p; |
| 1337 | } |
| 1338 | |
| 1339 | stmt_ty |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 1340 | Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * |
| 1341 | finalbody, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1342 | { |
| 1343 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1344 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1345 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1346 | return NULL; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 1347 | p->kind = Try_kind; |
| 1348 | p->v.Try.body = body; |
| 1349 | p->v.Try.handlers = handlers; |
| 1350 | p->v.Try.orelse = orelse; |
| 1351 | p->v.Try.finalbody = finalbody; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1352 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1353 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1354 | return p; |
| 1355 | } |
| 1356 | |
| 1357 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1358 | 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] | 1359 | { |
| 1360 | stmt_ty p; |
| 1361 | if (!test) { |
| 1362 | PyErr_SetString(PyExc_ValueError, |
| 1363 | "field test is required for Assert"); |
| 1364 | return NULL; |
| 1365 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1366 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1367 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1368 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1369 | p->kind = Assert_kind; |
| 1370 | p->v.Assert.test = test; |
| 1371 | p->v.Assert.msg = msg; |
| 1372 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1373 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1374 | return p; |
| 1375 | } |
| 1376 | |
| 1377 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1378 | Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1379 | { |
| 1380 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1381 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1382 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1383 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1384 | p->kind = Import_kind; |
| 1385 | p->v.Import.names = names; |
| 1386 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1387 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1388 | return p; |
| 1389 | } |
| 1390 | |
| 1391 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1392 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
| 1393 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1394 | { |
| 1395 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1396 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1397 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1398 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1399 | p->kind = ImportFrom_kind; |
| 1400 | p->v.ImportFrom.module = module; |
| 1401 | p->v.ImportFrom.names = names; |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 1402 | p->v.ImportFrom.level = level; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1403 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1404 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1405 | return p; |
| 1406 | } |
| 1407 | |
| 1408 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1409 | Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1410 | { |
| 1411 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1412 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1413 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1414 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1415 | p->kind = Global_kind; |
| 1416 | p->v.Global.names = names; |
| 1417 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1418 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1419 | return p; |
| 1420 | } |
| 1421 | |
| 1422 | stmt_ty |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 1423 | Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
| 1424 | { |
| 1425 | stmt_ty p; |
| 1426 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1427 | if (!p) |
| 1428 | return NULL; |
| 1429 | p->kind = Nonlocal_kind; |
| 1430 | p->v.Nonlocal.names = names; |
| 1431 | p->lineno = lineno; |
| 1432 | p->col_offset = col_offset; |
| 1433 | return p; |
| 1434 | } |
| 1435 | |
| 1436 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1437 | Expr(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1438 | { |
| 1439 | stmt_ty p; |
| 1440 | if (!value) { |
| 1441 | PyErr_SetString(PyExc_ValueError, |
| 1442 | "field value is required for Expr"); |
| 1443 | return NULL; |
| 1444 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1445 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1446 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1447 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1448 | p->kind = Expr_kind; |
| 1449 | p->v.Expr.value = value; |
| 1450 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1451 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1452 | return p; |
| 1453 | } |
| 1454 | |
| 1455 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1456 | Pass(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1457 | { |
| 1458 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1459 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1460 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1461 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1462 | p->kind = Pass_kind; |
| 1463 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1464 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1465 | return p; |
| 1466 | } |
| 1467 | |
| 1468 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1469 | Break(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1470 | { |
| 1471 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1472 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1473 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1474 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1475 | p->kind = Break_kind; |
| 1476 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1477 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1478 | return p; |
| 1479 | } |
| 1480 | |
| 1481 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1482 | Continue(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1483 | { |
| 1484 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1485 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1486 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1487 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1488 | p->kind = Continue_kind; |
| 1489 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1490 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1491 | return p; |
| 1492 | } |
| 1493 | |
| 1494 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1495 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1496 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1497 | { |
| 1498 | expr_ty p; |
| 1499 | if (!op) { |
| 1500 | PyErr_SetString(PyExc_ValueError, |
| 1501 | "field op is required for BoolOp"); |
| 1502 | return NULL; |
| 1503 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1504 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1505 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1506 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1507 | p->kind = BoolOp_kind; |
| 1508 | p->v.BoolOp.op = op; |
| 1509 | p->v.BoolOp.values = values; |
| 1510 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1511 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1512 | return p; |
| 1513 | } |
| 1514 | |
| 1515 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1516 | BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset, |
| 1517 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1518 | { |
| 1519 | expr_ty p; |
| 1520 | if (!left) { |
| 1521 | PyErr_SetString(PyExc_ValueError, |
| 1522 | "field left is required for BinOp"); |
| 1523 | return NULL; |
| 1524 | } |
| 1525 | if (!op) { |
| 1526 | PyErr_SetString(PyExc_ValueError, |
| 1527 | "field op is required for BinOp"); |
| 1528 | return NULL; |
| 1529 | } |
| 1530 | if (!right) { |
| 1531 | PyErr_SetString(PyExc_ValueError, |
| 1532 | "field right is required for BinOp"); |
| 1533 | return NULL; |
| 1534 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1535 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1536 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1537 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1538 | p->kind = BinOp_kind; |
| 1539 | p->v.BinOp.left = left; |
| 1540 | p->v.BinOp.op = op; |
| 1541 | p->v.BinOp.right = right; |
| 1542 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1543 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1544 | return p; |
| 1545 | } |
| 1546 | |
| 1547 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1548 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena |
| 1549 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1550 | { |
| 1551 | expr_ty p; |
| 1552 | if (!op) { |
| 1553 | PyErr_SetString(PyExc_ValueError, |
| 1554 | "field op is required for UnaryOp"); |
| 1555 | return NULL; |
| 1556 | } |
| 1557 | if (!operand) { |
| 1558 | PyErr_SetString(PyExc_ValueError, |
| 1559 | "field operand is required for UnaryOp"); |
| 1560 | return NULL; |
| 1561 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1562 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1563 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1564 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1565 | p->kind = UnaryOp_kind; |
| 1566 | p->v.UnaryOp.op = op; |
| 1567 | p->v.UnaryOp.operand = operand; |
| 1568 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1569 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1570 | return p; |
| 1571 | } |
| 1572 | |
| 1573 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1574 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena |
| 1575 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1576 | { |
| 1577 | expr_ty p; |
| 1578 | if (!args) { |
| 1579 | PyErr_SetString(PyExc_ValueError, |
| 1580 | "field args is required for Lambda"); |
| 1581 | return NULL; |
| 1582 | } |
| 1583 | if (!body) { |
| 1584 | PyErr_SetString(PyExc_ValueError, |
| 1585 | "field body is required for Lambda"); |
| 1586 | return NULL; |
| 1587 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1588 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1589 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1590 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1591 | p->kind = Lambda_kind; |
| 1592 | p->v.Lambda.args = args; |
| 1593 | p->v.Lambda.body = body; |
| 1594 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1595 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1596 | return p; |
| 1597 | } |
| 1598 | |
| 1599 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1600 | IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset, |
| 1601 | PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1602 | { |
| 1603 | expr_ty p; |
| 1604 | if (!test) { |
| 1605 | PyErr_SetString(PyExc_ValueError, |
| 1606 | "field test is required for IfExp"); |
| 1607 | return NULL; |
| 1608 | } |
| 1609 | if (!body) { |
| 1610 | PyErr_SetString(PyExc_ValueError, |
| 1611 | "field body is required for IfExp"); |
| 1612 | return NULL; |
| 1613 | } |
| 1614 | if (!orelse) { |
| 1615 | PyErr_SetString(PyExc_ValueError, |
| 1616 | "field orelse is required for IfExp"); |
| 1617 | return NULL; |
| 1618 | } |
| 1619 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1620 | if (!p) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1621 | return NULL; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1622 | p->kind = IfExp_kind; |
| 1623 | p->v.IfExp.test = test; |
| 1624 | p->v.IfExp.body = body; |
| 1625 | p->v.IfExp.orelse = orelse; |
| 1626 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1627 | p->col_offset = col_offset; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1628 | return p; |
| 1629 | } |
| 1630 | |
| 1631 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1632 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1633 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1634 | { |
| 1635 | expr_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1636 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1637 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1638 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1639 | p->kind = Dict_kind; |
| 1640 | p->v.Dict.keys = keys; |
| 1641 | p->v.Dict.values = values; |
| 1642 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1643 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1644 | return p; |
| 1645 | } |
| 1646 | |
| 1647 | expr_ty |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1648 | Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena) |
| 1649 | { |
| 1650 | expr_ty p; |
| 1651 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1652 | if (!p) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1653 | return NULL; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1654 | p->kind = Set_kind; |
| 1655 | p->v.Set.elts = elts; |
| 1656 | p->lineno = lineno; |
| 1657 | p->col_offset = col_offset; |
| 1658 | return p; |
| 1659 | } |
| 1660 | |
| 1661 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1662 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1663 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1664 | { |
| 1665 | expr_ty p; |
| 1666 | if (!elt) { |
| 1667 | PyErr_SetString(PyExc_ValueError, |
| 1668 | "field elt is required for ListComp"); |
| 1669 | return NULL; |
| 1670 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1671 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1672 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1673 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1674 | p->kind = ListComp_kind; |
| 1675 | p->v.ListComp.elt = elt; |
| 1676 | p->v.ListComp.generators = generators; |
| 1677 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1678 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1679 | return p; |
| 1680 | } |
| 1681 | |
| 1682 | expr_ty |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 1683 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena |
| 1684 | *arena) |
| 1685 | { |
| 1686 | expr_ty p; |
| 1687 | if (!elt) { |
| 1688 | PyErr_SetString(PyExc_ValueError, |
| 1689 | "field elt is required for SetComp"); |
| 1690 | return NULL; |
| 1691 | } |
| 1692 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1693 | if (!p) |
| 1694 | return NULL; |
| 1695 | p->kind = SetComp_kind; |
| 1696 | p->v.SetComp.elt = elt; |
| 1697 | p->v.SetComp.generators = generators; |
| 1698 | p->lineno = lineno; |
| 1699 | p->col_offset = col_offset; |
| 1700 | return p; |
| 1701 | } |
| 1702 | |
| 1703 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 1704 | DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int |
| 1705 | col_offset, PyArena *arena) |
| 1706 | { |
| 1707 | expr_ty p; |
| 1708 | if (!key) { |
| 1709 | PyErr_SetString(PyExc_ValueError, |
| 1710 | "field key is required for DictComp"); |
| 1711 | return NULL; |
| 1712 | } |
| 1713 | if (!value) { |
| 1714 | PyErr_SetString(PyExc_ValueError, |
| 1715 | "field value is required for DictComp"); |
| 1716 | return NULL; |
| 1717 | } |
| 1718 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1719 | if (!p) |
| 1720 | return NULL; |
| 1721 | p->kind = DictComp_kind; |
| 1722 | p->v.DictComp.key = key; |
| 1723 | p->v.DictComp.value = value; |
| 1724 | p->v.DictComp.generators = generators; |
| 1725 | p->lineno = lineno; |
| 1726 | p->col_offset = col_offset; |
| 1727 | return p; |
| 1728 | } |
| 1729 | |
| 1730 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1731 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1732 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1733 | { |
| 1734 | expr_ty p; |
| 1735 | if (!elt) { |
| 1736 | PyErr_SetString(PyExc_ValueError, |
| 1737 | "field elt is required for GeneratorExp"); |
| 1738 | return NULL; |
| 1739 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1740 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1741 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1742 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1743 | p->kind = GeneratorExp_kind; |
| 1744 | p->v.GeneratorExp.elt = elt; |
| 1745 | p->v.GeneratorExp.generators = generators; |
| 1746 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1747 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1748 | return p; |
| 1749 | } |
| 1750 | |
| 1751 | expr_ty |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame^] | 1752 | Yield(int is_from, expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1753 | { |
| 1754 | expr_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1755 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1756 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1757 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1758 | p->kind = Yield_kind; |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame^] | 1759 | p->v.Yield.is_from = is_from; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1760 | p->v.Yield.value = value; |
| 1761 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1762 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1763 | return p; |
| 1764 | } |
| 1765 | |
| 1766 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1767 | Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno, |
| 1768 | int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1769 | { |
| 1770 | expr_ty p; |
| 1771 | if (!left) { |
| 1772 | PyErr_SetString(PyExc_ValueError, |
| 1773 | "field left is required for Compare"); |
| 1774 | return NULL; |
| 1775 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1776 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1777 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1778 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1779 | p->kind = Compare_kind; |
| 1780 | p->v.Compare.left = left; |
| 1781 | p->v.Compare.ops = ops; |
| 1782 | p->v.Compare.comparators = comparators; |
| 1783 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1784 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1785 | return p; |
| 1786 | } |
| 1787 | |
| 1788 | expr_ty |
| 1789 | 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] | 1790 | expr_ty kwargs, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1791 | { |
| 1792 | expr_ty p; |
| 1793 | if (!func) { |
| 1794 | PyErr_SetString(PyExc_ValueError, |
| 1795 | "field func is required for Call"); |
| 1796 | return NULL; |
| 1797 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1798 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1799 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1800 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1801 | p->kind = Call_kind; |
| 1802 | p->v.Call.func = func; |
| 1803 | p->v.Call.args = args; |
| 1804 | p->v.Call.keywords = keywords; |
| 1805 | p->v.Call.starargs = starargs; |
| 1806 | p->v.Call.kwargs = kwargs; |
| 1807 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1808 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1809 | return p; |
| 1810 | } |
| 1811 | |
| 1812 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1813 | Num(object n, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1814 | { |
| 1815 | expr_ty p; |
| 1816 | if (!n) { |
| 1817 | PyErr_SetString(PyExc_ValueError, |
| 1818 | "field n is required for Num"); |
| 1819 | return NULL; |
| 1820 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1821 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1822 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1823 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1824 | p->kind = Num_kind; |
| 1825 | p->v.Num.n = n; |
| 1826 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1827 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1828 | return p; |
| 1829 | } |
| 1830 | |
| 1831 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1832 | Str(string s, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1833 | { |
| 1834 | expr_ty p; |
| 1835 | if (!s) { |
| 1836 | PyErr_SetString(PyExc_ValueError, |
| 1837 | "field s is required for Str"); |
| 1838 | return NULL; |
| 1839 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1840 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1841 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1842 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1843 | p->kind = Str_kind; |
| 1844 | p->v.Str.s = s; |
| 1845 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1846 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1847 | return p; |
| 1848 | } |
| 1849 | |
| 1850 | expr_ty |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 1851 | Bytes(bytes s, int lineno, int col_offset, PyArena *arena) |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1852 | { |
| 1853 | expr_ty p; |
| 1854 | if (!s) { |
| 1855 | PyErr_SetString(PyExc_ValueError, |
| 1856 | "field s is required for Bytes"); |
| 1857 | return NULL; |
| 1858 | } |
| 1859 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1860 | if (!p) |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1861 | return NULL; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1862 | p->kind = Bytes_kind; |
| 1863 | p->v.Bytes.s = s; |
| 1864 | p->lineno = lineno; |
| 1865 | p->col_offset = col_offset; |
| 1866 | return p; |
| 1867 | } |
| 1868 | |
| 1869 | expr_ty |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1870 | Ellipsis(int lineno, int col_offset, PyArena *arena) |
| 1871 | { |
| 1872 | expr_ty p; |
| 1873 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1874 | if (!p) |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1875 | return NULL; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1876 | p->kind = Ellipsis_kind; |
| 1877 | p->lineno = lineno; |
| 1878 | p->col_offset = col_offset; |
| 1879 | return p; |
| 1880 | } |
| 1881 | |
| 1882 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1883 | Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int |
| 1884 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1885 | { |
| 1886 | expr_ty p; |
| 1887 | if (!value) { |
| 1888 | PyErr_SetString(PyExc_ValueError, |
| 1889 | "field value is required for Attribute"); |
| 1890 | return NULL; |
| 1891 | } |
| 1892 | if (!attr) { |
| 1893 | PyErr_SetString(PyExc_ValueError, |
| 1894 | "field attr is required for Attribute"); |
| 1895 | return NULL; |
| 1896 | } |
| 1897 | if (!ctx) { |
| 1898 | PyErr_SetString(PyExc_ValueError, |
| 1899 | "field ctx is required for Attribute"); |
| 1900 | return NULL; |
| 1901 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1902 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1903 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1904 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1905 | p->kind = Attribute_kind; |
| 1906 | p->v.Attribute.value = value; |
| 1907 | p->v.Attribute.attr = attr; |
| 1908 | p->v.Attribute.ctx = ctx; |
| 1909 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1910 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1911 | return p; |
| 1912 | } |
| 1913 | |
| 1914 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1915 | Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int |
| 1916 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1917 | { |
| 1918 | expr_ty p; |
| 1919 | if (!value) { |
| 1920 | PyErr_SetString(PyExc_ValueError, |
| 1921 | "field value is required for Subscript"); |
| 1922 | return NULL; |
| 1923 | } |
| 1924 | if (!slice) { |
| 1925 | PyErr_SetString(PyExc_ValueError, |
| 1926 | "field slice is required for Subscript"); |
| 1927 | return NULL; |
| 1928 | } |
| 1929 | if (!ctx) { |
| 1930 | PyErr_SetString(PyExc_ValueError, |
| 1931 | "field ctx is required for Subscript"); |
| 1932 | return NULL; |
| 1933 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1934 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1935 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1936 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1937 | p->kind = Subscript_kind; |
| 1938 | p->v.Subscript.value = value; |
| 1939 | p->v.Subscript.slice = slice; |
| 1940 | p->v.Subscript.ctx = ctx; |
| 1941 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1942 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1943 | return p; |
| 1944 | } |
| 1945 | |
| 1946 | expr_ty |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 1947 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1948 | *arena) |
| 1949 | { |
| 1950 | expr_ty p; |
| 1951 | if (!value) { |
| 1952 | PyErr_SetString(PyExc_ValueError, |
| 1953 | "field value is required for Starred"); |
| 1954 | return NULL; |
| 1955 | } |
| 1956 | if (!ctx) { |
| 1957 | PyErr_SetString(PyExc_ValueError, |
| 1958 | "field ctx is required for Starred"); |
| 1959 | return NULL; |
| 1960 | } |
| 1961 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1962 | if (!p) |
| 1963 | return NULL; |
| 1964 | p->kind = Starred_kind; |
| 1965 | p->v.Starred.value = value; |
| 1966 | p->v.Starred.ctx = ctx; |
| 1967 | p->lineno = lineno; |
| 1968 | p->col_offset = col_offset; |
| 1969 | return p; |
| 1970 | } |
| 1971 | |
| 1972 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1973 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1974 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1975 | { |
| 1976 | expr_ty p; |
| 1977 | if (!id) { |
| 1978 | PyErr_SetString(PyExc_ValueError, |
| 1979 | "field id is required for Name"); |
| 1980 | return NULL; |
| 1981 | } |
| 1982 | if (!ctx) { |
| 1983 | PyErr_SetString(PyExc_ValueError, |
| 1984 | "field ctx is required for Name"); |
| 1985 | return NULL; |
| 1986 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1987 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1988 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1989 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1990 | p->kind = Name_kind; |
| 1991 | p->v.Name.id = id; |
| 1992 | p->v.Name.ctx = ctx; |
| 1993 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1994 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1995 | return p; |
| 1996 | } |
| 1997 | |
| 1998 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1999 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 2000 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2001 | { |
| 2002 | expr_ty p; |
| 2003 | if (!ctx) { |
| 2004 | PyErr_SetString(PyExc_ValueError, |
| 2005 | "field ctx is required for List"); |
| 2006 | return NULL; |
| 2007 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2008 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2009 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2010 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2011 | p->kind = List_kind; |
| 2012 | p->v.List.elts = elts; |
| 2013 | p->v.List.ctx = ctx; |
| 2014 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2015 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2016 | return p; |
| 2017 | } |
| 2018 | |
| 2019 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2020 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 2021 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2022 | { |
| 2023 | expr_ty p; |
| 2024 | if (!ctx) { |
| 2025 | PyErr_SetString(PyExc_ValueError, |
| 2026 | "field ctx is required for Tuple"); |
| 2027 | return NULL; |
| 2028 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2029 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2030 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2031 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2032 | p->kind = Tuple_kind; |
| 2033 | p->v.Tuple.elts = elts; |
| 2034 | p->v.Tuple.ctx = ctx; |
| 2035 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2036 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2037 | return p; |
| 2038 | } |
| 2039 | |
| 2040 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2041 | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2042 | { |
| 2043 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2044 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2045 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2046 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2047 | p->kind = Slice_kind; |
| 2048 | p->v.Slice.lower = lower; |
| 2049 | p->v.Slice.upper = upper; |
| 2050 | p->v.Slice.step = step; |
| 2051 | return p; |
| 2052 | } |
| 2053 | |
| 2054 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2055 | ExtSlice(asdl_seq * dims, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2056 | { |
| 2057 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2058 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2059 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2060 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2061 | p->kind = ExtSlice_kind; |
| 2062 | p->v.ExtSlice.dims = dims; |
| 2063 | return p; |
| 2064 | } |
| 2065 | |
| 2066 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2067 | Index(expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2068 | { |
| 2069 | slice_ty p; |
| 2070 | if (!value) { |
| 2071 | PyErr_SetString(PyExc_ValueError, |
| 2072 | "field value is required for Index"); |
| 2073 | return NULL; |
| 2074 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2075 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2076 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2077 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2078 | p->kind = Index_kind; |
| 2079 | p->v.Index.value = value; |
| 2080 | return p; |
| 2081 | } |
| 2082 | |
| 2083 | comprehension_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2084 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2085 | { |
| 2086 | comprehension_ty p; |
| 2087 | if (!target) { |
| 2088 | PyErr_SetString(PyExc_ValueError, |
| 2089 | "field target is required for comprehension"); |
| 2090 | return NULL; |
| 2091 | } |
| 2092 | if (!iter) { |
| 2093 | PyErr_SetString(PyExc_ValueError, |
| 2094 | "field iter is required for comprehension"); |
| 2095 | return NULL; |
| 2096 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2097 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2098 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2099 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2100 | p->target = target; |
| 2101 | p->iter = iter; |
| 2102 | p->ifs = ifs; |
| 2103 | return p; |
| 2104 | } |
| 2105 | |
| 2106 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 2107 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2108 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2109 | { |
| 2110 | excepthandler_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2111 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2112 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2113 | return NULL; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 2114 | p->kind = ExceptHandler_kind; |
| 2115 | p->v.ExceptHandler.type = type; |
| 2116 | p->v.ExceptHandler.name = name; |
| 2117 | p->v.ExceptHandler.body = body; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2118 | p->lineno = lineno; |
| 2119 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2120 | return p; |
| 2121 | } |
| 2122 | |
| 2123 | arguments_ty |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2124 | arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation, |
| 2125 | asdl_seq * kwonlyargs, identifier kwarg, expr_ty kwargannotation, |
| 2126 | asdl_seq * defaults, asdl_seq * kw_defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2127 | { |
| 2128 | arguments_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2129 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2130 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2131 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2132 | p->args = args; |
| 2133 | p->vararg = vararg; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2134 | p->varargannotation = varargannotation; |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 2135 | p->kwonlyargs = kwonlyargs; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2136 | p->kwarg = kwarg; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2137 | p->kwargannotation = kwargannotation; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2138 | p->defaults = defaults; |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 2139 | p->kw_defaults = kw_defaults; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2140 | return p; |
| 2141 | } |
| 2142 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2143 | arg_ty |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2144 | arg(identifier arg, expr_ty annotation, PyArena *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2145 | { |
| 2146 | arg_ty p; |
| 2147 | if (!arg) { |
| 2148 | PyErr_SetString(PyExc_ValueError, |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2149 | "field arg is required for arg"); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2150 | return NULL; |
| 2151 | } |
| 2152 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2153 | if (!p) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2154 | return NULL; |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2155 | p->arg = arg; |
| 2156 | p->annotation = annotation; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2157 | return p; |
| 2158 | } |
| 2159 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2160 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2161 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2162 | { |
| 2163 | keyword_ty p; |
| 2164 | if (!arg) { |
| 2165 | PyErr_SetString(PyExc_ValueError, |
| 2166 | "field arg is required for keyword"); |
| 2167 | return NULL; |
| 2168 | } |
| 2169 | if (!value) { |
| 2170 | PyErr_SetString(PyExc_ValueError, |
| 2171 | "field value is required for keyword"); |
| 2172 | return NULL; |
| 2173 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2174 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2175 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2176 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2177 | p->arg = arg; |
| 2178 | p->value = value; |
| 2179 | return p; |
| 2180 | } |
| 2181 | |
| 2182 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2183 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2184 | { |
| 2185 | alias_ty p; |
| 2186 | if (!name) { |
| 2187 | PyErr_SetString(PyExc_ValueError, |
| 2188 | "field name is required for alias"); |
| 2189 | return NULL; |
| 2190 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2191 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2192 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2193 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2194 | p->name = name; |
| 2195 | p->asname = asname; |
| 2196 | return p; |
| 2197 | } |
| 2198 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2199 | withitem_ty |
| 2200 | withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) |
| 2201 | { |
| 2202 | withitem_ty p; |
| 2203 | if (!context_expr) { |
| 2204 | PyErr_SetString(PyExc_ValueError, |
| 2205 | "field context_expr is required for withitem"); |
| 2206 | return NULL; |
| 2207 | } |
| 2208 | p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2209 | if (!p) |
| 2210 | return NULL; |
| 2211 | p->context_expr = context_expr; |
| 2212 | p->optional_vars = optional_vars; |
| 2213 | return p; |
| 2214 | } |
| 2215 | |
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 | PyObject* |
| 2218 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2219 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2220 | mod_ty o = (mod_ty)_o; |
| 2221 | PyObject *result = NULL, *value = NULL; |
| 2222 | if (!o) { |
| 2223 | Py_INCREF(Py_None); |
| 2224 | return Py_None; |
| 2225 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2226 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2227 | switch (o->kind) { |
| 2228 | case Module_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2229 | result = PyType_GenericNew(Module_type, NULL, NULL); |
| 2230 | if (!result) goto failed; |
| 2231 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 2232 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2233 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2234 | goto failed; |
| 2235 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2236 | break; |
| 2237 | case Interactive_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2238 | result = PyType_GenericNew(Interactive_type, NULL, NULL); |
| 2239 | if (!result) goto failed; |
| 2240 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 2241 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2242 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2243 | goto failed; |
| 2244 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2245 | break; |
| 2246 | case Expression_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2247 | result = PyType_GenericNew(Expression_type, NULL, NULL); |
| 2248 | if (!result) goto failed; |
| 2249 | value = ast2obj_expr(o->v.Expression.body); |
| 2250 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2251 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2252 | goto failed; |
| 2253 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2254 | break; |
| 2255 | case Suite_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2256 | result = PyType_GenericNew(Suite_type, NULL, NULL); |
| 2257 | if (!result) goto failed; |
| 2258 | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
| 2259 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2260 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2261 | goto failed; |
| 2262 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2263 | break; |
| 2264 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2265 | return result; |
| 2266 | failed: |
| 2267 | Py_XDECREF(value); |
| 2268 | Py_XDECREF(result); |
| 2269 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2270 | } |
| 2271 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2272 | PyObject* |
| 2273 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2274 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2275 | stmt_ty o = (stmt_ty)_o; |
| 2276 | PyObject *result = NULL, *value = NULL; |
| 2277 | if (!o) { |
| 2278 | Py_INCREF(Py_None); |
| 2279 | return Py_None; |
| 2280 | } |
| 2281 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2282 | switch (o->kind) { |
| 2283 | case FunctionDef_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2284 | result = PyType_GenericNew(FunctionDef_type, NULL, NULL); |
| 2285 | if (!result) goto failed; |
| 2286 | value = ast2obj_identifier(o->v.FunctionDef.name); |
| 2287 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2288 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2289 | goto failed; |
| 2290 | Py_DECREF(value); |
| 2291 | value = ast2obj_arguments(o->v.FunctionDef.args); |
| 2292 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2293 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2294 | goto failed; |
| 2295 | Py_DECREF(value); |
| 2296 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 2297 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2298 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2299 | goto failed; |
| 2300 | Py_DECREF(value); |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2301 | value = ast2obj_list(o->v.FunctionDef.decorator_list, |
| 2302 | ast2obj_expr); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2303 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2304 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2305 | -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2306 | goto failed; |
| 2307 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2308 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 2309 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2310 | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2311 | goto failed; |
| 2312 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2313 | break; |
| 2314 | case ClassDef_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2315 | result = PyType_GenericNew(ClassDef_type, NULL, NULL); |
| 2316 | if (!result) goto failed; |
| 2317 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 2318 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2319 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2320 | goto failed; |
| 2321 | Py_DECREF(value); |
| 2322 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 2323 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2324 | if (_PyObject_SetAttrId(result, &PyId_bases, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2325 | goto failed; |
| 2326 | Py_DECREF(value); |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 2327 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 2328 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2329 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 2330 | goto failed; |
| 2331 | Py_DECREF(value); |
| 2332 | value = ast2obj_expr(o->v.ClassDef.starargs); |
| 2333 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2334 | if (_PyObject_SetAttrId(result, &PyId_starargs, value) == -1) |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 2335 | goto failed; |
| 2336 | Py_DECREF(value); |
| 2337 | value = ast2obj_expr(o->v.ClassDef.kwargs); |
| 2338 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2339 | if (_PyObject_SetAttrId(result, &PyId_kwargs, value) == -1) |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 2340 | goto failed; |
| 2341 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2342 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 2343 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2344 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2345 | goto failed; |
| 2346 | Py_DECREF(value); |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2347 | value = ast2obj_list(o->v.ClassDef.decorator_list, |
| 2348 | ast2obj_expr); |
| 2349 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2350 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2351 | -1) |
| 2352 | goto failed; |
| 2353 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2354 | break; |
| 2355 | case Return_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2356 | result = PyType_GenericNew(Return_type, NULL, NULL); |
| 2357 | if (!result) goto failed; |
| 2358 | value = ast2obj_expr(o->v.Return.value); |
| 2359 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2360 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2361 | goto failed; |
| 2362 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2363 | break; |
| 2364 | case Delete_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2365 | result = PyType_GenericNew(Delete_type, NULL, NULL); |
| 2366 | if (!result) goto failed; |
| 2367 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 2368 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2369 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2370 | goto failed; |
| 2371 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2372 | break; |
| 2373 | case Assign_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2374 | result = PyType_GenericNew(Assign_type, NULL, NULL); |
| 2375 | if (!result) goto failed; |
| 2376 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 2377 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2378 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2379 | goto failed; |
| 2380 | Py_DECREF(value); |
| 2381 | value = ast2obj_expr(o->v.Assign.value); |
| 2382 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2383 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2384 | goto failed; |
| 2385 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2386 | break; |
| 2387 | case AugAssign_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2388 | result = PyType_GenericNew(AugAssign_type, NULL, NULL); |
| 2389 | if (!result) goto failed; |
| 2390 | value = ast2obj_expr(o->v.AugAssign.target); |
| 2391 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2392 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2393 | goto failed; |
| 2394 | Py_DECREF(value); |
| 2395 | value = ast2obj_operator(o->v.AugAssign.op); |
| 2396 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2397 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2398 | goto failed; |
| 2399 | Py_DECREF(value); |
| 2400 | value = ast2obj_expr(o->v.AugAssign.value); |
| 2401 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2402 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2403 | goto failed; |
| 2404 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2405 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2406 | case For_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2407 | result = PyType_GenericNew(For_type, NULL, NULL); |
| 2408 | if (!result) goto failed; |
| 2409 | value = ast2obj_expr(o->v.For.target); |
| 2410 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2411 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2412 | goto failed; |
| 2413 | Py_DECREF(value); |
| 2414 | value = ast2obj_expr(o->v.For.iter); |
| 2415 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2416 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2417 | goto failed; |
| 2418 | Py_DECREF(value); |
| 2419 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 2420 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2421 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2422 | goto failed; |
| 2423 | Py_DECREF(value); |
| 2424 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 2425 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2426 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2427 | goto failed; |
| 2428 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2429 | break; |
| 2430 | case While_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2431 | result = PyType_GenericNew(While_type, NULL, NULL); |
| 2432 | if (!result) goto failed; |
| 2433 | value = ast2obj_expr(o->v.While.test); |
| 2434 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2435 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2436 | goto failed; |
| 2437 | Py_DECREF(value); |
| 2438 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 2439 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2440 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2441 | goto failed; |
| 2442 | Py_DECREF(value); |
| 2443 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 2444 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2445 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2446 | goto failed; |
| 2447 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2448 | break; |
| 2449 | case If_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2450 | result = PyType_GenericNew(If_type, NULL, NULL); |
| 2451 | if (!result) goto failed; |
| 2452 | value = ast2obj_expr(o->v.If.test); |
| 2453 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2454 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2455 | goto failed; |
| 2456 | Py_DECREF(value); |
| 2457 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 2458 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2459 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2460 | goto failed; |
| 2461 | Py_DECREF(value); |
| 2462 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 2463 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2464 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2465 | goto failed; |
| 2466 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2467 | break; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2468 | case With_kind: |
| 2469 | result = PyType_GenericNew(With_type, NULL, NULL); |
| 2470 | if (!result) goto failed; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2471 | value = ast2obj_list(o->v.With.items, ast2obj_withitem); |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2472 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2473 | if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2474 | goto failed; |
| 2475 | Py_DECREF(value); |
| 2476 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 2477 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2478 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2479 | goto failed; |
| 2480 | Py_DECREF(value); |
| 2481 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2482 | case Raise_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2483 | result = PyType_GenericNew(Raise_type, NULL, NULL); |
| 2484 | if (!result) goto failed; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2485 | value = ast2obj_expr(o->v.Raise.exc); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2486 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2487 | if (_PyObject_SetAttrId(result, &PyId_exc, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2488 | goto failed; |
| 2489 | Py_DECREF(value); |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2490 | value = ast2obj_expr(o->v.Raise.cause); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2491 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2492 | if (_PyObject_SetAttrId(result, &PyId_cause, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2493 | goto failed; |
| 2494 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2495 | break; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2496 | case Try_kind: |
| 2497 | result = PyType_GenericNew(Try_type, NULL, NULL); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2498 | if (!result) goto failed; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2499 | value = ast2obj_list(o->v.Try.body, ast2obj_stmt); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2500 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2501 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2502 | goto failed; |
| 2503 | Py_DECREF(value); |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2504 | value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2505 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2506 | if (_PyObject_SetAttrId(result, &PyId_handlers, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2507 | goto failed; |
| 2508 | Py_DECREF(value); |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2509 | value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2510 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2511 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2512 | goto failed; |
| 2513 | Py_DECREF(value); |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2514 | value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2515 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2516 | if (_PyObject_SetAttrId(result, &PyId_finalbody, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2517 | goto failed; |
| 2518 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2519 | break; |
| 2520 | case Assert_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2521 | result = PyType_GenericNew(Assert_type, NULL, NULL); |
| 2522 | if (!result) goto failed; |
| 2523 | value = ast2obj_expr(o->v.Assert.test); |
| 2524 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2525 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2526 | goto failed; |
| 2527 | Py_DECREF(value); |
| 2528 | value = ast2obj_expr(o->v.Assert.msg); |
| 2529 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2530 | if (_PyObject_SetAttrId(result, &PyId_msg, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2531 | goto failed; |
| 2532 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2533 | break; |
| 2534 | case Import_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2535 | result = PyType_GenericNew(Import_type, NULL, NULL); |
| 2536 | if (!result) goto failed; |
| 2537 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 2538 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2539 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2540 | goto failed; |
| 2541 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2542 | break; |
| 2543 | case ImportFrom_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2544 | result = PyType_GenericNew(ImportFrom_type, NULL, NULL); |
| 2545 | if (!result) goto failed; |
| 2546 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 2547 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2548 | if (_PyObject_SetAttrId(result, &PyId_module, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2549 | goto failed; |
| 2550 | Py_DECREF(value); |
| 2551 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 2552 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2553 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2554 | goto failed; |
| 2555 | Py_DECREF(value); |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 2556 | value = ast2obj_int(o->v.ImportFrom.level); |
| 2557 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2558 | if (_PyObject_SetAttrId(result, &PyId_level, value) == -1) |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 2559 | goto failed; |
| 2560 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2561 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2562 | case Global_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2563 | result = PyType_GenericNew(Global_type, NULL, NULL); |
| 2564 | if (!result) goto failed; |
| 2565 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 2566 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2567 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2568 | goto failed; |
| 2569 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2570 | break; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2571 | case Nonlocal_kind: |
| 2572 | result = PyType_GenericNew(Nonlocal_type, NULL, NULL); |
| 2573 | if (!result) goto failed; |
| 2574 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 2575 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2576 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2577 | goto failed; |
| 2578 | Py_DECREF(value); |
| 2579 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2580 | case Expr_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2581 | result = PyType_GenericNew(Expr_type, NULL, NULL); |
| 2582 | if (!result) goto failed; |
| 2583 | value = ast2obj_expr(o->v.Expr.value); |
| 2584 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2585 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2586 | goto failed; |
| 2587 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2588 | break; |
| 2589 | case Pass_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2590 | result = PyType_GenericNew(Pass_type, NULL, NULL); |
| 2591 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2592 | break; |
| 2593 | case Break_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2594 | result = PyType_GenericNew(Break_type, NULL, NULL); |
| 2595 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2596 | break; |
| 2597 | case Continue_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2598 | result = PyType_GenericNew(Continue_type, NULL, NULL); |
| 2599 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2600 | break; |
| 2601 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2602 | value = ast2obj_int(o->lineno); |
| 2603 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2604 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2605 | goto failed; |
| 2606 | Py_DECREF(value); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2607 | value = ast2obj_int(o->col_offset); |
| 2608 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2609 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2610 | goto failed; |
| 2611 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2612 | return result; |
| 2613 | failed: |
| 2614 | Py_XDECREF(value); |
| 2615 | Py_XDECREF(result); |
| 2616 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2617 | } |
| 2618 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2619 | PyObject* |
| 2620 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2621 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2622 | expr_ty o = (expr_ty)_o; |
| 2623 | PyObject *result = NULL, *value = NULL; |
| 2624 | if (!o) { |
| 2625 | Py_INCREF(Py_None); |
| 2626 | return Py_None; |
| 2627 | } |
| 2628 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2629 | switch (o->kind) { |
| 2630 | case BoolOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2631 | result = PyType_GenericNew(BoolOp_type, NULL, NULL); |
| 2632 | if (!result) goto failed; |
| 2633 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 2634 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2635 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2636 | goto failed; |
| 2637 | Py_DECREF(value); |
| 2638 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 2639 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2640 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2641 | goto failed; |
| 2642 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2643 | break; |
| 2644 | case BinOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2645 | result = PyType_GenericNew(BinOp_type, NULL, NULL); |
| 2646 | if (!result) goto failed; |
| 2647 | value = ast2obj_expr(o->v.BinOp.left); |
| 2648 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2649 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2650 | goto failed; |
| 2651 | Py_DECREF(value); |
| 2652 | value = ast2obj_operator(o->v.BinOp.op); |
| 2653 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2654 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2655 | goto failed; |
| 2656 | Py_DECREF(value); |
| 2657 | value = ast2obj_expr(o->v.BinOp.right); |
| 2658 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2659 | if (_PyObject_SetAttrId(result, &PyId_right, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2660 | goto failed; |
| 2661 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2662 | break; |
| 2663 | case UnaryOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2664 | result = PyType_GenericNew(UnaryOp_type, NULL, NULL); |
| 2665 | if (!result) goto failed; |
| 2666 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 2667 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2668 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2669 | goto failed; |
| 2670 | Py_DECREF(value); |
| 2671 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 2672 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2673 | if (_PyObject_SetAttrId(result, &PyId_operand, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2674 | goto failed; |
| 2675 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2676 | break; |
| 2677 | case Lambda_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2678 | result = PyType_GenericNew(Lambda_type, NULL, NULL); |
| 2679 | if (!result) goto failed; |
| 2680 | value = ast2obj_arguments(o->v.Lambda.args); |
| 2681 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2682 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2683 | goto failed; |
| 2684 | Py_DECREF(value); |
| 2685 | value = ast2obj_expr(o->v.Lambda.body); |
| 2686 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2687 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2688 | goto failed; |
| 2689 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2690 | break; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2691 | case IfExp_kind: |
| 2692 | result = PyType_GenericNew(IfExp_type, NULL, NULL); |
| 2693 | if (!result) goto failed; |
| 2694 | value = ast2obj_expr(o->v.IfExp.test); |
| 2695 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2696 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2697 | goto failed; |
| 2698 | Py_DECREF(value); |
| 2699 | value = ast2obj_expr(o->v.IfExp.body); |
| 2700 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2701 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2702 | goto failed; |
| 2703 | Py_DECREF(value); |
| 2704 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 2705 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2706 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2707 | goto failed; |
| 2708 | Py_DECREF(value); |
| 2709 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2710 | case Dict_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2711 | result = PyType_GenericNew(Dict_type, NULL, NULL); |
| 2712 | if (!result) goto failed; |
| 2713 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 2714 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2715 | if (_PyObject_SetAttrId(result, &PyId_keys, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2716 | goto failed; |
| 2717 | Py_DECREF(value); |
| 2718 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 2719 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2720 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2721 | goto failed; |
| 2722 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2723 | break; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2724 | case Set_kind: |
| 2725 | result = PyType_GenericNew(Set_type, NULL, NULL); |
| 2726 | if (!result) goto failed; |
| 2727 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 2728 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2729 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2730 | goto failed; |
| 2731 | Py_DECREF(value); |
| 2732 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2733 | case ListComp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2734 | result = PyType_GenericNew(ListComp_type, NULL, NULL); |
| 2735 | if (!result) goto failed; |
| 2736 | value = ast2obj_expr(o->v.ListComp.elt); |
| 2737 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2738 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2739 | goto failed; |
| 2740 | Py_DECREF(value); |
| 2741 | value = ast2obj_list(o->v.ListComp.generators, |
| 2742 | ast2obj_comprehension); |
| 2743 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2744 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2745 | goto failed; |
| 2746 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2747 | break; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2748 | case SetComp_kind: |
| 2749 | result = PyType_GenericNew(SetComp_type, NULL, NULL); |
| 2750 | if (!result) goto failed; |
| 2751 | value = ast2obj_expr(o->v.SetComp.elt); |
| 2752 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2753 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2754 | goto failed; |
| 2755 | Py_DECREF(value); |
| 2756 | value = ast2obj_list(o->v.SetComp.generators, |
| 2757 | ast2obj_comprehension); |
| 2758 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2759 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2760 | goto failed; |
| 2761 | Py_DECREF(value); |
| 2762 | break; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2763 | case DictComp_kind: |
| 2764 | result = PyType_GenericNew(DictComp_type, NULL, NULL); |
| 2765 | if (!result) goto failed; |
| 2766 | value = ast2obj_expr(o->v.DictComp.key); |
| 2767 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2768 | if (_PyObject_SetAttrId(result, &PyId_key, value) == -1) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2769 | goto failed; |
| 2770 | Py_DECREF(value); |
| 2771 | value = ast2obj_expr(o->v.DictComp.value); |
| 2772 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2773 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2774 | goto failed; |
| 2775 | Py_DECREF(value); |
| 2776 | value = ast2obj_list(o->v.DictComp.generators, |
| 2777 | ast2obj_comprehension); |
| 2778 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2779 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2780 | goto failed; |
| 2781 | Py_DECREF(value); |
| 2782 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2783 | case GeneratorExp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2784 | result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); |
| 2785 | if (!result) goto failed; |
| 2786 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 2787 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2788 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2789 | goto failed; |
| 2790 | Py_DECREF(value); |
| 2791 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 2792 | ast2obj_comprehension); |
| 2793 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2794 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2795 | goto failed; |
| 2796 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2797 | break; |
| 2798 | case Yield_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2799 | result = PyType_GenericNew(Yield_type, NULL, NULL); |
| 2800 | if (!result) goto failed; |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame^] | 2801 | value = ast2obj_int(o->v.Yield.is_from); |
| 2802 | if (!value) goto failed; |
| 2803 | if (PyObject_SetAttrString(result, "is_from", value) == -1) |
| 2804 | goto failed; |
| 2805 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2806 | value = ast2obj_expr(o->v.Yield.value); |
| 2807 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2808 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2809 | goto failed; |
| 2810 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2811 | break; |
| 2812 | case Compare_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2813 | result = PyType_GenericNew(Compare_type, NULL, NULL); |
| 2814 | if (!result) goto failed; |
| 2815 | value = ast2obj_expr(o->v.Compare.left); |
| 2816 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2817 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2818 | goto failed; |
| 2819 | Py_DECREF(value); |
Martin v. Löwis | ce1d5d2 | 2006-02-26 20:51:25 +0000 | [diff] [blame] | 2820 | { |
| 2821 | int i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 2822 | value = PyList_New(n); |
| 2823 | if (!value) goto failed; |
| 2824 | for(i = 0; i < n; i++) |
| 2825 | PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i))); |
| 2826 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2827 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2828 | if (_PyObject_SetAttrId(result, &PyId_ops, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2829 | goto failed; |
| 2830 | Py_DECREF(value); |
| 2831 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
| 2832 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2833 | if (_PyObject_SetAttrId(result, &PyId_comparators, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2834 | goto failed; |
| 2835 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2836 | break; |
| 2837 | case Call_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2838 | result = PyType_GenericNew(Call_type, NULL, NULL); |
| 2839 | if (!result) goto failed; |
| 2840 | value = ast2obj_expr(o->v.Call.func); |
| 2841 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2842 | if (_PyObject_SetAttrId(result, &PyId_func, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2843 | goto failed; |
| 2844 | Py_DECREF(value); |
| 2845 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 2846 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2847 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2848 | goto failed; |
| 2849 | Py_DECREF(value); |
| 2850 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 2851 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2852 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2853 | goto failed; |
| 2854 | Py_DECREF(value); |
| 2855 | value = ast2obj_expr(o->v.Call.starargs); |
| 2856 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2857 | if (_PyObject_SetAttrId(result, &PyId_starargs, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2858 | goto failed; |
| 2859 | Py_DECREF(value); |
| 2860 | value = ast2obj_expr(o->v.Call.kwargs); |
| 2861 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2862 | if (_PyObject_SetAttrId(result, &PyId_kwargs, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2863 | goto failed; |
| 2864 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2865 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2866 | case Num_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2867 | result = PyType_GenericNew(Num_type, NULL, NULL); |
| 2868 | if (!result) goto failed; |
| 2869 | value = ast2obj_object(o->v.Num.n); |
| 2870 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2871 | if (_PyObject_SetAttrId(result, &PyId_n, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2872 | goto failed; |
| 2873 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2874 | break; |
| 2875 | case Str_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2876 | result = PyType_GenericNew(Str_type, NULL, NULL); |
| 2877 | if (!result) goto failed; |
| 2878 | value = ast2obj_string(o->v.Str.s); |
| 2879 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2880 | if (_PyObject_SetAttrId(result, &PyId_s, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2881 | goto failed; |
| 2882 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2883 | break; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 2884 | case Bytes_kind: |
| 2885 | result = PyType_GenericNew(Bytes_type, NULL, NULL); |
| 2886 | if (!result) goto failed; |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 2887 | value = ast2obj_bytes(o->v.Bytes.s); |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 2888 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2889 | if (_PyObject_SetAttrId(result, &PyId_s, value) == -1) |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 2890 | goto failed; |
| 2891 | Py_DECREF(value); |
| 2892 | break; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 2893 | case Ellipsis_kind: |
| 2894 | result = PyType_GenericNew(Ellipsis_type, NULL, NULL); |
| 2895 | if (!result) goto failed; |
| 2896 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2897 | case Attribute_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2898 | result = PyType_GenericNew(Attribute_type, NULL, NULL); |
| 2899 | if (!result) goto failed; |
| 2900 | value = ast2obj_expr(o->v.Attribute.value); |
| 2901 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2902 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2903 | goto failed; |
| 2904 | Py_DECREF(value); |
| 2905 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 2906 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2907 | if (_PyObject_SetAttrId(result, &PyId_attr, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2908 | goto failed; |
| 2909 | Py_DECREF(value); |
| 2910 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 2911 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2912 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2913 | goto failed; |
| 2914 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2915 | break; |
| 2916 | case Subscript_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2917 | result = PyType_GenericNew(Subscript_type, NULL, NULL); |
| 2918 | if (!result) goto failed; |
| 2919 | value = ast2obj_expr(o->v.Subscript.value); |
| 2920 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2921 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2922 | goto failed; |
| 2923 | Py_DECREF(value); |
| 2924 | value = ast2obj_slice(o->v.Subscript.slice); |
| 2925 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2926 | if (_PyObject_SetAttrId(result, &PyId_slice, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2927 | goto failed; |
| 2928 | Py_DECREF(value); |
| 2929 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 2930 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2931 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2932 | goto failed; |
| 2933 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2934 | break; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2935 | case Starred_kind: |
| 2936 | result = PyType_GenericNew(Starred_type, NULL, NULL); |
| 2937 | if (!result) goto failed; |
| 2938 | value = ast2obj_expr(o->v.Starred.value); |
| 2939 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2940 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2941 | goto failed; |
| 2942 | Py_DECREF(value); |
| 2943 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 2944 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2945 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2946 | goto failed; |
| 2947 | Py_DECREF(value); |
| 2948 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2949 | case Name_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2950 | result = PyType_GenericNew(Name_type, NULL, NULL); |
| 2951 | if (!result) goto failed; |
| 2952 | value = ast2obj_identifier(o->v.Name.id); |
| 2953 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2954 | if (_PyObject_SetAttrId(result, &PyId_id, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2955 | goto failed; |
| 2956 | Py_DECREF(value); |
| 2957 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 2958 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2959 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2960 | goto failed; |
| 2961 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2962 | break; |
| 2963 | case List_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2964 | result = PyType_GenericNew(List_type, NULL, NULL); |
| 2965 | if (!result) goto failed; |
| 2966 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 2967 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2968 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2969 | goto failed; |
| 2970 | Py_DECREF(value); |
| 2971 | value = ast2obj_expr_context(o->v.List.ctx); |
| 2972 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2973 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2974 | goto failed; |
| 2975 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2976 | break; |
| 2977 | case Tuple_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2978 | result = PyType_GenericNew(Tuple_type, NULL, NULL); |
| 2979 | if (!result) goto failed; |
| 2980 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 2981 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2982 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2983 | goto failed; |
| 2984 | Py_DECREF(value); |
| 2985 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 2986 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2987 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2988 | goto failed; |
| 2989 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2990 | break; |
| 2991 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2992 | value = ast2obj_int(o->lineno); |
| 2993 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2994 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2995 | goto failed; |
| 2996 | Py_DECREF(value); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2997 | value = ast2obj_int(o->col_offset); |
| 2998 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2999 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3000 | goto failed; |
| 3001 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3002 | return result; |
| 3003 | failed: |
| 3004 | Py_XDECREF(value); |
| 3005 | Py_XDECREF(result); |
| 3006 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3007 | } |
| 3008 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3009 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3010 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3011 | switch(o) { |
| 3012 | case Load: |
| 3013 | Py_INCREF(Load_singleton); |
| 3014 | return Load_singleton; |
| 3015 | case Store: |
| 3016 | Py_INCREF(Store_singleton); |
| 3017 | return Store_singleton; |
| 3018 | case Del: |
| 3019 | Py_INCREF(Del_singleton); |
| 3020 | return Del_singleton; |
| 3021 | case AugLoad: |
| 3022 | Py_INCREF(AugLoad_singleton); |
| 3023 | return AugLoad_singleton; |
| 3024 | case AugStore: |
| 3025 | Py_INCREF(AugStore_singleton); |
| 3026 | return AugStore_singleton; |
| 3027 | case Param: |
| 3028 | Py_INCREF(Param_singleton); |
| 3029 | return Param_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3030 | default: |
| 3031 | /* should never happen, but just in case ... */ |
| 3032 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 3033 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3034 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3035 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3036 | PyObject* |
| 3037 | ast2obj_slice(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3038 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3039 | slice_ty o = (slice_ty)_o; |
| 3040 | PyObject *result = NULL, *value = NULL; |
| 3041 | if (!o) { |
| 3042 | Py_INCREF(Py_None); |
| 3043 | return Py_None; |
| 3044 | } |
| 3045 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3046 | switch (o->kind) { |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3047 | case Slice_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3048 | result = PyType_GenericNew(Slice_type, NULL, NULL); |
| 3049 | if (!result) goto failed; |
| 3050 | value = ast2obj_expr(o->v.Slice.lower); |
| 3051 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3052 | if (_PyObject_SetAttrId(result, &PyId_lower, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3053 | goto failed; |
| 3054 | Py_DECREF(value); |
| 3055 | value = ast2obj_expr(o->v.Slice.upper); |
| 3056 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3057 | if (_PyObject_SetAttrId(result, &PyId_upper, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3058 | goto failed; |
| 3059 | Py_DECREF(value); |
| 3060 | value = ast2obj_expr(o->v.Slice.step); |
| 3061 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3062 | if (_PyObject_SetAttrId(result, &PyId_step, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3063 | goto failed; |
| 3064 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3065 | break; |
| 3066 | case ExtSlice_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3067 | result = PyType_GenericNew(ExtSlice_type, NULL, NULL); |
| 3068 | if (!result) goto failed; |
| 3069 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 3070 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3071 | if (_PyObject_SetAttrId(result, &PyId_dims, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3072 | goto failed; |
| 3073 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3074 | break; |
| 3075 | case Index_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3076 | result = PyType_GenericNew(Index_type, NULL, NULL); |
| 3077 | if (!result) goto failed; |
| 3078 | value = ast2obj_expr(o->v.Index.value); |
| 3079 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3080 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3081 | goto failed; |
| 3082 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3083 | break; |
| 3084 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3085 | return result; |
| 3086 | failed: |
| 3087 | Py_XDECREF(value); |
| 3088 | Py_XDECREF(result); |
| 3089 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3090 | } |
| 3091 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3092 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3093 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3094 | switch(o) { |
| 3095 | case And: |
| 3096 | Py_INCREF(And_singleton); |
| 3097 | return And_singleton; |
| 3098 | case Or: |
| 3099 | Py_INCREF(Or_singleton); |
| 3100 | return Or_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3101 | default: |
| 3102 | /* should never happen, but just in case ... */ |
| 3103 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 3104 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3105 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3106 | } |
| 3107 | PyObject* ast2obj_operator(operator_ty o) |
| 3108 | { |
| 3109 | switch(o) { |
| 3110 | case Add: |
| 3111 | Py_INCREF(Add_singleton); |
| 3112 | return Add_singleton; |
| 3113 | case Sub: |
| 3114 | Py_INCREF(Sub_singleton); |
| 3115 | return Sub_singleton; |
| 3116 | case Mult: |
| 3117 | Py_INCREF(Mult_singleton); |
| 3118 | return Mult_singleton; |
| 3119 | case Div: |
| 3120 | Py_INCREF(Div_singleton); |
| 3121 | return Div_singleton; |
| 3122 | case Mod: |
| 3123 | Py_INCREF(Mod_singleton); |
| 3124 | return Mod_singleton; |
| 3125 | case Pow: |
| 3126 | Py_INCREF(Pow_singleton); |
| 3127 | return Pow_singleton; |
| 3128 | case LShift: |
| 3129 | Py_INCREF(LShift_singleton); |
| 3130 | return LShift_singleton; |
| 3131 | case RShift: |
| 3132 | Py_INCREF(RShift_singleton); |
| 3133 | return RShift_singleton; |
| 3134 | case BitOr: |
| 3135 | Py_INCREF(BitOr_singleton); |
| 3136 | return BitOr_singleton; |
| 3137 | case BitXor: |
| 3138 | Py_INCREF(BitXor_singleton); |
| 3139 | return BitXor_singleton; |
| 3140 | case BitAnd: |
| 3141 | Py_INCREF(BitAnd_singleton); |
| 3142 | return BitAnd_singleton; |
| 3143 | case FloorDiv: |
| 3144 | Py_INCREF(FloorDiv_singleton); |
| 3145 | return FloorDiv_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3146 | default: |
| 3147 | /* should never happen, but just in case ... */ |
| 3148 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 3149 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3150 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3151 | } |
| 3152 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 3153 | { |
| 3154 | switch(o) { |
| 3155 | case Invert: |
| 3156 | Py_INCREF(Invert_singleton); |
| 3157 | return Invert_singleton; |
| 3158 | case Not: |
| 3159 | Py_INCREF(Not_singleton); |
| 3160 | return Not_singleton; |
| 3161 | case UAdd: |
| 3162 | Py_INCREF(UAdd_singleton); |
| 3163 | return UAdd_singleton; |
| 3164 | case USub: |
| 3165 | Py_INCREF(USub_singleton); |
| 3166 | return USub_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3167 | default: |
| 3168 | /* should never happen, but just in case ... */ |
| 3169 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 3170 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3171 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3172 | } |
| 3173 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 3174 | { |
| 3175 | switch(o) { |
| 3176 | case Eq: |
| 3177 | Py_INCREF(Eq_singleton); |
| 3178 | return Eq_singleton; |
| 3179 | case NotEq: |
| 3180 | Py_INCREF(NotEq_singleton); |
| 3181 | return NotEq_singleton; |
| 3182 | case Lt: |
| 3183 | Py_INCREF(Lt_singleton); |
| 3184 | return Lt_singleton; |
| 3185 | case LtE: |
| 3186 | Py_INCREF(LtE_singleton); |
| 3187 | return LtE_singleton; |
| 3188 | case Gt: |
| 3189 | Py_INCREF(Gt_singleton); |
| 3190 | return Gt_singleton; |
| 3191 | case GtE: |
| 3192 | Py_INCREF(GtE_singleton); |
| 3193 | return GtE_singleton; |
| 3194 | case Is: |
| 3195 | Py_INCREF(Is_singleton); |
| 3196 | return Is_singleton; |
| 3197 | case IsNot: |
| 3198 | Py_INCREF(IsNot_singleton); |
| 3199 | return IsNot_singleton; |
| 3200 | case In: |
| 3201 | Py_INCREF(In_singleton); |
| 3202 | return In_singleton; |
| 3203 | case NotIn: |
| 3204 | Py_INCREF(NotIn_singleton); |
| 3205 | return NotIn_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3206 | default: |
| 3207 | /* should never happen, but just in case ... */ |
| 3208 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 3209 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3210 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3211 | } |
| 3212 | PyObject* |
| 3213 | ast2obj_comprehension(void* _o) |
| 3214 | { |
| 3215 | comprehension_ty o = (comprehension_ty)_o; |
| 3216 | PyObject *result = NULL, *value = NULL; |
| 3217 | if (!o) { |
| 3218 | Py_INCREF(Py_None); |
| 3219 | return Py_None; |
| 3220 | } |
| 3221 | |
| 3222 | result = PyType_GenericNew(comprehension_type, NULL, NULL); |
| 3223 | if (!result) return NULL; |
| 3224 | value = ast2obj_expr(o->target); |
| 3225 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3226 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3227 | goto failed; |
| 3228 | Py_DECREF(value); |
| 3229 | value = ast2obj_expr(o->iter); |
| 3230 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3231 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3232 | goto failed; |
| 3233 | Py_DECREF(value); |
| 3234 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 3235 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3236 | if (_PyObject_SetAttrId(result, &PyId_ifs, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3237 | goto failed; |
| 3238 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3239 | return result; |
| 3240 | failed: |
| 3241 | Py_XDECREF(value); |
| 3242 | Py_XDECREF(result); |
| 3243 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3244 | } |
| 3245 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3246 | PyObject* |
| 3247 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3248 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3249 | excepthandler_ty o = (excepthandler_ty)_o; |
| 3250 | PyObject *result = NULL, *value = NULL; |
| 3251 | if (!o) { |
| 3252 | Py_INCREF(Py_None); |
| 3253 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3254 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3255 | |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3256 | switch (o->kind) { |
| 3257 | case ExceptHandler_kind: |
| 3258 | result = PyType_GenericNew(ExceptHandler_type, NULL, NULL); |
| 3259 | if (!result) goto failed; |
| 3260 | value = ast2obj_expr(o->v.ExceptHandler.type); |
| 3261 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3262 | if (_PyObject_SetAttrId(result, &PyId_type, value) == -1) |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3263 | goto failed; |
| 3264 | Py_DECREF(value); |
| 3265 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
| 3266 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3267 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3268 | goto failed; |
| 3269 | Py_DECREF(value); |
| 3270 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 3271 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3272 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3273 | goto failed; |
| 3274 | Py_DECREF(value); |
| 3275 | break; |
| 3276 | } |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3277 | value = ast2obj_int(o->lineno); |
| 3278 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3279 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3280 | goto failed; |
| 3281 | Py_DECREF(value); |
| 3282 | value = ast2obj_int(o->col_offset); |
| 3283 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3284 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3285 | goto failed; |
| 3286 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3287 | return result; |
| 3288 | failed: |
| 3289 | Py_XDECREF(value); |
| 3290 | Py_XDECREF(result); |
| 3291 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3292 | } |
| 3293 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3294 | PyObject* |
| 3295 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3296 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3297 | arguments_ty o = (arguments_ty)_o; |
| 3298 | PyObject *result = NULL, *value = NULL; |
| 3299 | if (!o) { |
| 3300 | Py_INCREF(Py_None); |
| 3301 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3302 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3303 | |
| 3304 | result = PyType_GenericNew(arguments_type, NULL, NULL); |
| 3305 | if (!result) return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3306 | value = ast2obj_list(o->args, ast2obj_arg); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3307 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3308 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3309 | goto failed; |
| 3310 | Py_DECREF(value); |
| 3311 | value = ast2obj_identifier(o->vararg); |
| 3312 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3313 | if (_PyObject_SetAttrId(result, &PyId_vararg, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3314 | goto failed; |
| 3315 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3316 | value = ast2obj_expr(o->varargannotation); |
| 3317 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3318 | if (_PyObject_SetAttrId(result, &PyId_varargannotation, value) == -1) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3319 | goto failed; |
| 3320 | Py_DECREF(value); |
| 3321 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 3322 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3323 | if (_PyObject_SetAttrId(result, &PyId_kwonlyargs, value) == -1) |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 3324 | goto failed; |
| 3325 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3326 | value = ast2obj_identifier(o->kwarg); |
| 3327 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3328 | if (_PyObject_SetAttrId(result, &PyId_kwarg, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3329 | goto failed; |
| 3330 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3331 | value = ast2obj_expr(o->kwargannotation); |
| 3332 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3333 | if (_PyObject_SetAttrId(result, &PyId_kwargannotation, value) == -1) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3334 | goto failed; |
| 3335 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3336 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 3337 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3338 | if (_PyObject_SetAttrId(result, &PyId_defaults, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3339 | goto failed; |
| 3340 | Py_DECREF(value); |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 3341 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
| 3342 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3343 | if (_PyObject_SetAttrId(result, &PyId_kw_defaults, value) == -1) |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 3344 | goto failed; |
| 3345 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3346 | return result; |
| 3347 | failed: |
| 3348 | Py_XDECREF(value); |
| 3349 | Py_XDECREF(result); |
| 3350 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3351 | } |
| 3352 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3353 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3354 | ast2obj_arg(void* _o) |
| 3355 | { |
| 3356 | arg_ty o = (arg_ty)_o; |
| 3357 | PyObject *result = NULL, *value = NULL; |
| 3358 | if (!o) { |
| 3359 | Py_INCREF(Py_None); |
| 3360 | return Py_None; |
| 3361 | } |
| 3362 | |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 3363 | result = PyType_GenericNew(arg_type, NULL, NULL); |
| 3364 | if (!result) return NULL; |
| 3365 | value = ast2obj_identifier(o->arg); |
| 3366 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3367 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 3368 | goto failed; |
| 3369 | Py_DECREF(value); |
| 3370 | value = ast2obj_expr(o->annotation); |
| 3371 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3372 | if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 3373 | goto failed; |
| 3374 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3375 | return result; |
| 3376 | failed: |
| 3377 | Py_XDECREF(value); |
| 3378 | Py_XDECREF(result); |
| 3379 | return NULL; |
| 3380 | } |
| 3381 | |
| 3382 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3383 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3384 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3385 | keyword_ty o = (keyword_ty)_o; |
| 3386 | PyObject *result = NULL, *value = NULL; |
| 3387 | if (!o) { |
| 3388 | Py_INCREF(Py_None); |
| 3389 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3390 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3391 | |
| 3392 | result = PyType_GenericNew(keyword_type, NULL, NULL); |
| 3393 | if (!result) return NULL; |
| 3394 | value = ast2obj_identifier(o->arg); |
| 3395 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3396 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3397 | goto failed; |
| 3398 | Py_DECREF(value); |
| 3399 | value = ast2obj_expr(o->value); |
| 3400 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3401 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3402 | goto failed; |
| 3403 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3404 | return result; |
| 3405 | failed: |
| 3406 | Py_XDECREF(value); |
| 3407 | Py_XDECREF(result); |
| 3408 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3409 | } |
| 3410 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3411 | PyObject* |
| 3412 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3413 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3414 | alias_ty o = (alias_ty)_o; |
| 3415 | PyObject *result = NULL, *value = NULL; |
| 3416 | if (!o) { |
| 3417 | Py_INCREF(Py_None); |
| 3418 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3419 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3420 | |
| 3421 | result = PyType_GenericNew(alias_type, NULL, NULL); |
| 3422 | if (!result) return NULL; |
| 3423 | value = ast2obj_identifier(o->name); |
| 3424 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3425 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3426 | goto failed; |
| 3427 | Py_DECREF(value); |
| 3428 | value = ast2obj_identifier(o->asname); |
| 3429 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3430 | if (_PyObject_SetAttrId(result, &PyId_asname, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3431 | goto failed; |
| 3432 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3433 | return result; |
| 3434 | failed: |
| 3435 | Py_XDECREF(value); |
| 3436 | Py_XDECREF(result); |
| 3437 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3438 | } |
| 3439 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3440 | PyObject* |
| 3441 | ast2obj_withitem(void* _o) |
| 3442 | { |
| 3443 | withitem_ty o = (withitem_ty)_o; |
| 3444 | PyObject *result = NULL, *value = NULL; |
| 3445 | if (!o) { |
| 3446 | Py_INCREF(Py_None); |
| 3447 | return Py_None; |
| 3448 | } |
| 3449 | |
| 3450 | result = PyType_GenericNew(withitem_type, NULL, NULL); |
| 3451 | if (!result) return NULL; |
| 3452 | value = ast2obj_expr(o->context_expr); |
| 3453 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3454 | if (_PyObject_SetAttrId(result, &PyId_context_expr, value) == -1) |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3455 | goto failed; |
| 3456 | Py_DECREF(value); |
| 3457 | value = ast2obj_expr(o->optional_vars); |
| 3458 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3459 | if (_PyObject_SetAttrId(result, &PyId_optional_vars, value) == -1) |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3460 | goto failed; |
| 3461 | Py_DECREF(value); |
| 3462 | return result; |
| 3463 | failed: |
| 3464 | Py_XDECREF(value); |
| 3465 | Py_XDECREF(result); |
| 3466 | return NULL; |
| 3467 | } |
| 3468 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3469 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3470 | int |
| 3471 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 3472 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3473 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3474 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 3475 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3476 | |
| 3477 | if (obj == Py_None) { |
| 3478 | *out = NULL; |
| 3479 | return 0; |
| 3480 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3481 | isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type); |
| 3482 | if (isinstance == -1) { |
| 3483 | return 1; |
| 3484 | } |
| 3485 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3486 | asdl_seq* body; |
| 3487 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3488 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3489 | int res; |
| 3490 | Py_ssize_t len; |
| 3491 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3492 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3493 | if (tmp == NULL) goto failed; |
| 3494 | if (!PyList_Check(tmp)) { |
| 3495 | PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3496 | goto failed; |
| 3497 | } |
| 3498 | len = PyList_GET_SIZE(tmp); |
| 3499 | body = asdl_seq_new(len, arena); |
| 3500 | if (body == NULL) goto failed; |
| 3501 | for (i = 0; i < len; i++) { |
| 3502 | stmt_ty value; |
| 3503 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3504 | if (res != 0) goto failed; |
| 3505 | asdl_seq_SET(body, i, value); |
| 3506 | } |
| 3507 | Py_XDECREF(tmp); |
| 3508 | tmp = NULL; |
| 3509 | } else { |
| 3510 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 3511 | return 1; |
| 3512 | } |
| 3513 | *out = Module(body, arena); |
| 3514 | if (*out == NULL) goto failed; |
| 3515 | return 0; |
| 3516 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3517 | isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type); |
| 3518 | if (isinstance == -1) { |
| 3519 | return 1; |
| 3520 | } |
| 3521 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3522 | asdl_seq* body; |
| 3523 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3524 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3525 | int res; |
| 3526 | Py_ssize_t len; |
| 3527 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3528 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3529 | if (tmp == NULL) goto failed; |
| 3530 | if (!PyList_Check(tmp)) { |
| 3531 | PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3532 | goto failed; |
| 3533 | } |
| 3534 | len = PyList_GET_SIZE(tmp); |
| 3535 | body = asdl_seq_new(len, arena); |
| 3536 | if (body == NULL) goto failed; |
| 3537 | for (i = 0; i < len; i++) { |
| 3538 | stmt_ty value; |
| 3539 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3540 | if (res != 0) goto failed; |
| 3541 | asdl_seq_SET(body, i, value); |
| 3542 | } |
| 3543 | Py_XDECREF(tmp); |
| 3544 | tmp = NULL; |
| 3545 | } else { |
| 3546 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 3547 | return 1; |
| 3548 | } |
| 3549 | *out = Interactive(body, arena); |
| 3550 | if (*out == NULL) goto failed; |
| 3551 | return 0; |
| 3552 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3553 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type); |
| 3554 | if (isinstance == -1) { |
| 3555 | return 1; |
| 3556 | } |
| 3557 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3558 | expr_ty body; |
| 3559 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3560 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3561 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3562 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3563 | if (tmp == NULL) goto failed; |
| 3564 | res = obj2ast_expr(tmp, &body, arena); |
| 3565 | if (res != 0) goto failed; |
| 3566 | Py_XDECREF(tmp); |
| 3567 | tmp = NULL; |
| 3568 | } else { |
| 3569 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 3570 | return 1; |
| 3571 | } |
| 3572 | *out = Expression(body, arena); |
| 3573 | if (*out == NULL) goto failed; |
| 3574 | return 0; |
| 3575 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3576 | isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type); |
| 3577 | if (isinstance == -1) { |
| 3578 | return 1; |
| 3579 | } |
| 3580 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3581 | asdl_seq* body; |
| 3582 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3583 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3584 | int res; |
| 3585 | Py_ssize_t len; |
| 3586 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3587 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3588 | if (tmp == NULL) goto failed; |
| 3589 | if (!PyList_Check(tmp)) { |
| 3590 | PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3591 | goto failed; |
| 3592 | } |
| 3593 | len = PyList_GET_SIZE(tmp); |
| 3594 | body = asdl_seq_new(len, arena); |
| 3595 | if (body == NULL) goto failed; |
| 3596 | for (i = 0; i < len; i++) { |
| 3597 | stmt_ty value; |
| 3598 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3599 | if (res != 0) goto failed; |
| 3600 | asdl_seq_SET(body, i, value); |
| 3601 | } |
| 3602 | Py_XDECREF(tmp); |
| 3603 | tmp = NULL; |
| 3604 | } else { |
| 3605 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite"); |
| 3606 | return 1; |
| 3607 | } |
| 3608 | *out = Suite(body, arena); |
| 3609 | if (*out == NULL) goto failed; |
| 3610 | return 0; |
| 3611 | } |
| 3612 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 3613 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
| 3614 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 3615 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3616 | return 1; |
| 3617 | } |
| 3618 | |
| 3619 | int |
| 3620 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 3621 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3622 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3623 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 3624 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3625 | int lineno; |
| 3626 | int col_offset; |
| 3627 | |
| 3628 | if (obj == Py_None) { |
| 3629 | *out = NULL; |
| 3630 | return 0; |
| 3631 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3632 | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3633 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3634 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3635 | if (tmp == NULL) goto failed; |
| 3636 | res = obj2ast_int(tmp, &lineno, arena); |
| 3637 | if (res != 0) goto failed; |
| 3638 | Py_XDECREF(tmp); |
| 3639 | tmp = NULL; |
| 3640 | } else { |
| 3641 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 3642 | return 1; |
| 3643 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3644 | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3645 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3646 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3647 | if (tmp == NULL) goto failed; |
| 3648 | res = obj2ast_int(tmp, &col_offset, arena); |
| 3649 | if (res != 0) goto failed; |
| 3650 | Py_XDECREF(tmp); |
| 3651 | tmp = NULL; |
| 3652 | } else { |
| 3653 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 3654 | return 1; |
| 3655 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3656 | isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type); |
| 3657 | if (isinstance == -1) { |
| 3658 | return 1; |
| 3659 | } |
| 3660 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3661 | identifier name; |
| 3662 | arguments_ty args; |
| 3663 | asdl_seq* body; |
| 3664 | asdl_seq* decorator_list; |
| 3665 | expr_ty returns; |
| 3666 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3667 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3668 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3669 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3670 | if (tmp == NULL) goto failed; |
| 3671 | res = obj2ast_identifier(tmp, &name, arena); |
| 3672 | if (res != 0) goto failed; |
| 3673 | Py_XDECREF(tmp); |
| 3674 | tmp = NULL; |
| 3675 | } else { |
| 3676 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 3677 | return 1; |
| 3678 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3679 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3680 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3681 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3682 | if (tmp == NULL) goto failed; |
| 3683 | res = obj2ast_arguments(tmp, &args, arena); |
| 3684 | if (res != 0) goto failed; |
| 3685 | Py_XDECREF(tmp); |
| 3686 | tmp = NULL; |
| 3687 | } else { |
| 3688 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 3689 | return 1; |
| 3690 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3691 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3692 | int res; |
| 3693 | Py_ssize_t len; |
| 3694 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3695 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3696 | if (tmp == NULL) goto failed; |
| 3697 | if (!PyList_Check(tmp)) { |
| 3698 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3699 | goto failed; |
| 3700 | } |
| 3701 | len = PyList_GET_SIZE(tmp); |
| 3702 | body = asdl_seq_new(len, arena); |
| 3703 | if (body == NULL) goto failed; |
| 3704 | for (i = 0; i < len; i++) { |
| 3705 | stmt_ty value; |
| 3706 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3707 | if (res != 0) goto failed; |
| 3708 | asdl_seq_SET(body, i, value); |
| 3709 | } |
| 3710 | Py_XDECREF(tmp); |
| 3711 | tmp = NULL; |
| 3712 | } else { |
| 3713 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 3714 | return 1; |
| 3715 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3716 | if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3717 | int res; |
| 3718 | Py_ssize_t len; |
| 3719 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3720 | tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3721 | if (tmp == NULL) goto failed; |
| 3722 | if (!PyList_Check(tmp)) { |
| 3723 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3724 | goto failed; |
| 3725 | } |
| 3726 | len = PyList_GET_SIZE(tmp); |
| 3727 | decorator_list = asdl_seq_new(len, arena); |
| 3728 | if (decorator_list == NULL) goto failed; |
| 3729 | for (i = 0; i < len; i++) { |
| 3730 | expr_ty value; |
| 3731 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3732 | if (res != 0) goto failed; |
| 3733 | asdl_seq_SET(decorator_list, i, value); |
| 3734 | } |
| 3735 | Py_XDECREF(tmp); |
| 3736 | tmp = NULL; |
| 3737 | } else { |
| 3738 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 3739 | return 1; |
| 3740 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3741 | if (_PyObject_HasAttrId(obj, &PyId_returns)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3742 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3743 | tmp = _PyObject_GetAttrId(obj, &PyId_returns); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3744 | if (tmp == NULL) goto failed; |
| 3745 | res = obj2ast_expr(tmp, &returns, arena); |
| 3746 | if (res != 0) goto failed; |
| 3747 | Py_XDECREF(tmp); |
| 3748 | tmp = NULL; |
| 3749 | } else { |
| 3750 | returns = NULL; |
| 3751 | } |
| 3752 | *out = FunctionDef(name, args, body, decorator_list, returns, |
| 3753 | lineno, col_offset, arena); |
| 3754 | if (*out == NULL) goto failed; |
| 3755 | return 0; |
| 3756 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3757 | isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type); |
| 3758 | if (isinstance == -1) { |
| 3759 | return 1; |
| 3760 | } |
| 3761 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3762 | identifier name; |
| 3763 | asdl_seq* bases; |
| 3764 | asdl_seq* keywords; |
| 3765 | expr_ty starargs; |
| 3766 | expr_ty kwargs; |
| 3767 | asdl_seq* body; |
| 3768 | asdl_seq* decorator_list; |
| 3769 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3770 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3771 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3772 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3773 | if (tmp == NULL) goto failed; |
| 3774 | res = obj2ast_identifier(tmp, &name, arena); |
| 3775 | if (res != 0) goto failed; |
| 3776 | Py_XDECREF(tmp); |
| 3777 | tmp = NULL; |
| 3778 | } else { |
| 3779 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 3780 | return 1; |
| 3781 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3782 | if (_PyObject_HasAttrId(obj, &PyId_bases)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3783 | int res; |
| 3784 | Py_ssize_t len; |
| 3785 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3786 | tmp = _PyObject_GetAttrId(obj, &PyId_bases); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3787 | if (tmp == NULL) goto failed; |
| 3788 | if (!PyList_Check(tmp)) { |
| 3789 | PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3790 | goto failed; |
| 3791 | } |
| 3792 | len = PyList_GET_SIZE(tmp); |
| 3793 | bases = asdl_seq_new(len, arena); |
| 3794 | if (bases == NULL) goto failed; |
| 3795 | for (i = 0; i < len; i++) { |
| 3796 | expr_ty value; |
| 3797 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3798 | if (res != 0) goto failed; |
| 3799 | asdl_seq_SET(bases, i, value); |
| 3800 | } |
| 3801 | Py_XDECREF(tmp); |
| 3802 | tmp = NULL; |
| 3803 | } else { |
| 3804 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 3805 | return 1; |
| 3806 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3807 | if (_PyObject_HasAttrId(obj, &PyId_keywords)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3808 | int res; |
| 3809 | Py_ssize_t len; |
| 3810 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3811 | tmp = _PyObject_GetAttrId(obj, &PyId_keywords); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3812 | if (tmp == NULL) goto failed; |
| 3813 | if (!PyList_Check(tmp)) { |
| 3814 | PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3815 | goto failed; |
| 3816 | } |
| 3817 | len = PyList_GET_SIZE(tmp); |
| 3818 | keywords = asdl_seq_new(len, arena); |
| 3819 | if (keywords == NULL) goto failed; |
| 3820 | for (i = 0; i < len; i++) { |
| 3821 | keyword_ty value; |
| 3822 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3823 | if (res != 0) goto failed; |
| 3824 | asdl_seq_SET(keywords, i, value); |
| 3825 | } |
| 3826 | Py_XDECREF(tmp); |
| 3827 | tmp = NULL; |
| 3828 | } else { |
| 3829 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 3830 | return 1; |
| 3831 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3832 | if (_PyObject_HasAttrId(obj, &PyId_starargs)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3833 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3834 | tmp = _PyObject_GetAttrId(obj, &PyId_starargs); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3835 | if (tmp == NULL) goto failed; |
| 3836 | res = obj2ast_expr(tmp, &starargs, arena); |
| 3837 | if (res != 0) goto failed; |
| 3838 | Py_XDECREF(tmp); |
| 3839 | tmp = NULL; |
| 3840 | } else { |
| 3841 | starargs = NULL; |
| 3842 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3843 | if (_PyObject_HasAttrId(obj, &PyId_kwargs)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3844 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3845 | tmp = _PyObject_GetAttrId(obj, &PyId_kwargs); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3846 | if (tmp == NULL) goto failed; |
| 3847 | res = obj2ast_expr(tmp, &kwargs, arena); |
| 3848 | if (res != 0) goto failed; |
| 3849 | Py_XDECREF(tmp); |
| 3850 | tmp = NULL; |
| 3851 | } else { |
| 3852 | kwargs = NULL; |
| 3853 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3854 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3855 | int res; |
| 3856 | Py_ssize_t len; |
| 3857 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3858 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3859 | if (tmp == NULL) goto failed; |
| 3860 | if (!PyList_Check(tmp)) { |
| 3861 | PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3862 | goto failed; |
| 3863 | } |
| 3864 | len = PyList_GET_SIZE(tmp); |
| 3865 | body = asdl_seq_new(len, arena); |
| 3866 | if (body == NULL) goto failed; |
| 3867 | for (i = 0; i < len; i++) { |
| 3868 | stmt_ty value; |
| 3869 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3870 | if (res != 0) goto failed; |
| 3871 | asdl_seq_SET(body, i, value); |
| 3872 | } |
| 3873 | Py_XDECREF(tmp); |
| 3874 | tmp = NULL; |
| 3875 | } else { |
| 3876 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 3877 | return 1; |
| 3878 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3879 | if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3880 | int res; |
| 3881 | Py_ssize_t len; |
| 3882 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3883 | tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3884 | if (tmp == NULL) goto failed; |
| 3885 | if (!PyList_Check(tmp)) { |
| 3886 | PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3887 | goto failed; |
| 3888 | } |
| 3889 | len = PyList_GET_SIZE(tmp); |
| 3890 | decorator_list = asdl_seq_new(len, arena); |
| 3891 | if (decorator_list == NULL) goto failed; |
| 3892 | for (i = 0; i < len; i++) { |
| 3893 | expr_ty value; |
| 3894 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3895 | if (res != 0) goto failed; |
| 3896 | asdl_seq_SET(decorator_list, i, value); |
| 3897 | } |
| 3898 | Py_XDECREF(tmp); |
| 3899 | tmp = NULL; |
| 3900 | } else { |
| 3901 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 3902 | return 1; |
| 3903 | } |
| 3904 | *out = ClassDef(name, bases, keywords, starargs, kwargs, body, |
| 3905 | decorator_list, lineno, col_offset, arena); |
| 3906 | if (*out == NULL) goto failed; |
| 3907 | return 0; |
| 3908 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3909 | isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type); |
| 3910 | if (isinstance == -1) { |
| 3911 | return 1; |
| 3912 | } |
| 3913 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3914 | expr_ty value; |
| 3915 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3916 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3917 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3918 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3919 | if (tmp == NULL) goto failed; |
| 3920 | res = obj2ast_expr(tmp, &value, arena); |
| 3921 | if (res != 0) goto failed; |
| 3922 | Py_XDECREF(tmp); |
| 3923 | tmp = NULL; |
| 3924 | } else { |
| 3925 | value = NULL; |
| 3926 | } |
| 3927 | *out = Return(value, lineno, col_offset, arena); |
| 3928 | if (*out == NULL) goto failed; |
| 3929 | return 0; |
| 3930 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3931 | isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type); |
| 3932 | if (isinstance == -1) { |
| 3933 | return 1; |
| 3934 | } |
| 3935 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3936 | asdl_seq* targets; |
| 3937 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3938 | if (_PyObject_HasAttrId(obj, &PyId_targets)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3939 | int res; |
| 3940 | Py_ssize_t len; |
| 3941 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3942 | tmp = _PyObject_GetAttrId(obj, &PyId_targets); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3943 | if (tmp == NULL) goto failed; |
| 3944 | if (!PyList_Check(tmp)) { |
| 3945 | PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3946 | goto failed; |
| 3947 | } |
| 3948 | len = PyList_GET_SIZE(tmp); |
| 3949 | targets = asdl_seq_new(len, arena); |
| 3950 | if (targets == NULL) goto failed; |
| 3951 | for (i = 0; i < len; i++) { |
| 3952 | expr_ty value; |
| 3953 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3954 | if (res != 0) goto failed; |
| 3955 | asdl_seq_SET(targets, i, value); |
| 3956 | } |
| 3957 | Py_XDECREF(tmp); |
| 3958 | tmp = NULL; |
| 3959 | } else { |
| 3960 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 3961 | return 1; |
| 3962 | } |
| 3963 | *out = Delete(targets, lineno, col_offset, arena); |
| 3964 | if (*out == NULL) goto failed; |
| 3965 | return 0; |
| 3966 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3967 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type); |
| 3968 | if (isinstance == -1) { |
| 3969 | return 1; |
| 3970 | } |
| 3971 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3972 | asdl_seq* targets; |
| 3973 | expr_ty value; |
| 3974 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3975 | if (_PyObject_HasAttrId(obj, &PyId_targets)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3976 | int res; |
| 3977 | Py_ssize_t len; |
| 3978 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3979 | tmp = _PyObject_GetAttrId(obj, &PyId_targets); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3980 | if (tmp == NULL) goto failed; |
| 3981 | if (!PyList_Check(tmp)) { |
| 3982 | PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3983 | goto failed; |
| 3984 | } |
| 3985 | len = PyList_GET_SIZE(tmp); |
| 3986 | targets = asdl_seq_new(len, arena); |
| 3987 | if (targets == NULL) goto failed; |
| 3988 | for (i = 0; i < len; i++) { |
| 3989 | expr_ty value; |
| 3990 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3991 | if (res != 0) goto failed; |
| 3992 | asdl_seq_SET(targets, i, value); |
| 3993 | } |
| 3994 | Py_XDECREF(tmp); |
| 3995 | tmp = NULL; |
| 3996 | } else { |
| 3997 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 3998 | return 1; |
| 3999 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4000 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4001 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4002 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4003 | if (tmp == NULL) goto failed; |
| 4004 | res = obj2ast_expr(tmp, &value, arena); |
| 4005 | if (res != 0) goto failed; |
| 4006 | Py_XDECREF(tmp); |
| 4007 | tmp = NULL; |
| 4008 | } else { |
| 4009 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 4010 | return 1; |
| 4011 | } |
| 4012 | *out = Assign(targets, value, lineno, col_offset, arena); |
| 4013 | if (*out == NULL) goto failed; |
| 4014 | return 0; |
| 4015 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4016 | isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type); |
| 4017 | if (isinstance == -1) { |
| 4018 | return 1; |
| 4019 | } |
| 4020 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4021 | expr_ty target; |
| 4022 | operator_ty op; |
| 4023 | expr_ty value; |
| 4024 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4025 | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4026 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4027 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4028 | if (tmp == NULL) goto failed; |
| 4029 | res = obj2ast_expr(tmp, &target, arena); |
| 4030 | if (res != 0) goto failed; |
| 4031 | Py_XDECREF(tmp); |
| 4032 | tmp = NULL; |
| 4033 | } else { |
| 4034 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 4035 | return 1; |
| 4036 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4037 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4038 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4039 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4040 | if (tmp == NULL) goto failed; |
| 4041 | res = obj2ast_operator(tmp, &op, arena); |
| 4042 | if (res != 0) goto failed; |
| 4043 | Py_XDECREF(tmp); |
| 4044 | tmp = NULL; |
| 4045 | } else { |
| 4046 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 4047 | return 1; |
| 4048 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4049 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4050 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4051 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4052 | if (tmp == NULL) goto failed; |
| 4053 | res = obj2ast_expr(tmp, &value, arena); |
| 4054 | if (res != 0) goto failed; |
| 4055 | Py_XDECREF(tmp); |
| 4056 | tmp = NULL; |
| 4057 | } else { |
| 4058 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 4059 | return 1; |
| 4060 | } |
| 4061 | *out = AugAssign(target, op, value, lineno, col_offset, arena); |
| 4062 | if (*out == NULL) goto failed; |
| 4063 | return 0; |
| 4064 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4065 | isinstance = PyObject_IsInstance(obj, (PyObject*)For_type); |
| 4066 | if (isinstance == -1) { |
| 4067 | return 1; |
| 4068 | } |
| 4069 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4070 | expr_ty target; |
| 4071 | expr_ty iter; |
| 4072 | asdl_seq* body; |
| 4073 | asdl_seq* orelse; |
| 4074 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4075 | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4076 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4077 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4078 | if (tmp == NULL) goto failed; |
| 4079 | res = obj2ast_expr(tmp, &target, arena); |
| 4080 | if (res != 0) goto failed; |
| 4081 | Py_XDECREF(tmp); |
| 4082 | tmp = NULL; |
| 4083 | } else { |
| 4084 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 4085 | return 1; |
| 4086 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4087 | if (_PyObject_HasAttrId(obj, &PyId_iter)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4088 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4089 | tmp = _PyObject_GetAttrId(obj, &PyId_iter); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4090 | if (tmp == NULL) goto failed; |
| 4091 | res = obj2ast_expr(tmp, &iter, arena); |
| 4092 | if (res != 0) goto failed; |
| 4093 | Py_XDECREF(tmp); |
| 4094 | tmp = NULL; |
| 4095 | } else { |
| 4096 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 4097 | return 1; |
| 4098 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4099 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4100 | int res; |
| 4101 | Py_ssize_t len; |
| 4102 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4103 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4104 | if (tmp == NULL) goto failed; |
| 4105 | if (!PyList_Check(tmp)) { |
| 4106 | PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4107 | goto failed; |
| 4108 | } |
| 4109 | len = PyList_GET_SIZE(tmp); |
| 4110 | body = asdl_seq_new(len, arena); |
| 4111 | if (body == NULL) goto failed; |
| 4112 | for (i = 0; i < len; i++) { |
| 4113 | stmt_ty value; |
| 4114 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4115 | if (res != 0) goto failed; |
| 4116 | asdl_seq_SET(body, i, value); |
| 4117 | } |
| 4118 | Py_XDECREF(tmp); |
| 4119 | tmp = NULL; |
| 4120 | } else { |
| 4121 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 4122 | return 1; |
| 4123 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4124 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4125 | int res; |
| 4126 | Py_ssize_t len; |
| 4127 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4128 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4129 | if (tmp == NULL) goto failed; |
| 4130 | if (!PyList_Check(tmp)) { |
| 4131 | PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4132 | goto failed; |
| 4133 | } |
| 4134 | len = PyList_GET_SIZE(tmp); |
| 4135 | orelse = asdl_seq_new(len, arena); |
| 4136 | if (orelse == NULL) goto failed; |
| 4137 | for (i = 0; i < len; i++) { |
| 4138 | stmt_ty value; |
| 4139 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4140 | if (res != 0) goto failed; |
| 4141 | asdl_seq_SET(orelse, i, value); |
| 4142 | } |
| 4143 | Py_XDECREF(tmp); |
| 4144 | tmp = NULL; |
| 4145 | } else { |
| 4146 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 4147 | return 1; |
| 4148 | } |
| 4149 | *out = For(target, iter, body, orelse, lineno, col_offset, |
| 4150 | arena); |
| 4151 | if (*out == NULL) goto failed; |
| 4152 | return 0; |
| 4153 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4154 | isinstance = PyObject_IsInstance(obj, (PyObject*)While_type); |
| 4155 | if (isinstance == -1) { |
| 4156 | return 1; |
| 4157 | } |
| 4158 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4159 | expr_ty test; |
| 4160 | asdl_seq* body; |
| 4161 | asdl_seq* orelse; |
| 4162 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4163 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4164 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4165 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4166 | if (tmp == NULL) goto failed; |
| 4167 | res = obj2ast_expr(tmp, &test, arena); |
| 4168 | if (res != 0) goto failed; |
| 4169 | Py_XDECREF(tmp); |
| 4170 | tmp = NULL; |
| 4171 | } else { |
| 4172 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 4173 | return 1; |
| 4174 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4175 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4176 | int res; |
| 4177 | Py_ssize_t len; |
| 4178 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4179 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4180 | if (tmp == NULL) goto failed; |
| 4181 | if (!PyList_Check(tmp)) { |
| 4182 | PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4183 | goto failed; |
| 4184 | } |
| 4185 | len = PyList_GET_SIZE(tmp); |
| 4186 | body = asdl_seq_new(len, arena); |
| 4187 | if (body == NULL) goto failed; |
| 4188 | for (i = 0; i < len; i++) { |
| 4189 | stmt_ty value; |
| 4190 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4191 | if (res != 0) goto failed; |
| 4192 | asdl_seq_SET(body, i, value); |
| 4193 | } |
| 4194 | Py_XDECREF(tmp); |
| 4195 | tmp = NULL; |
| 4196 | } else { |
| 4197 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 4198 | return 1; |
| 4199 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4200 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4201 | int res; |
| 4202 | Py_ssize_t len; |
| 4203 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4204 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4205 | if (tmp == NULL) goto failed; |
| 4206 | if (!PyList_Check(tmp)) { |
| 4207 | PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4208 | goto failed; |
| 4209 | } |
| 4210 | len = PyList_GET_SIZE(tmp); |
| 4211 | orelse = asdl_seq_new(len, arena); |
| 4212 | if (orelse == NULL) goto failed; |
| 4213 | for (i = 0; i < len; i++) { |
| 4214 | stmt_ty value; |
| 4215 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4216 | if (res != 0) goto failed; |
| 4217 | asdl_seq_SET(orelse, i, value); |
| 4218 | } |
| 4219 | Py_XDECREF(tmp); |
| 4220 | tmp = NULL; |
| 4221 | } else { |
| 4222 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 4223 | return 1; |
| 4224 | } |
| 4225 | *out = While(test, body, orelse, lineno, col_offset, arena); |
| 4226 | if (*out == NULL) goto failed; |
| 4227 | return 0; |
| 4228 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4229 | isinstance = PyObject_IsInstance(obj, (PyObject*)If_type); |
| 4230 | if (isinstance == -1) { |
| 4231 | return 1; |
| 4232 | } |
| 4233 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4234 | expr_ty test; |
| 4235 | asdl_seq* body; |
| 4236 | asdl_seq* orelse; |
| 4237 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4238 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4239 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4240 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4241 | if (tmp == NULL) goto failed; |
| 4242 | res = obj2ast_expr(tmp, &test, arena); |
| 4243 | if (res != 0) goto failed; |
| 4244 | Py_XDECREF(tmp); |
| 4245 | tmp = NULL; |
| 4246 | } else { |
| 4247 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 4248 | return 1; |
| 4249 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4250 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4251 | int res; |
| 4252 | Py_ssize_t len; |
| 4253 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4254 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4255 | if (tmp == NULL) goto failed; |
| 4256 | if (!PyList_Check(tmp)) { |
| 4257 | PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4258 | goto failed; |
| 4259 | } |
| 4260 | len = PyList_GET_SIZE(tmp); |
| 4261 | body = asdl_seq_new(len, arena); |
| 4262 | if (body == NULL) goto failed; |
| 4263 | for (i = 0; i < len; i++) { |
| 4264 | stmt_ty value; |
| 4265 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4266 | if (res != 0) goto failed; |
| 4267 | asdl_seq_SET(body, i, value); |
| 4268 | } |
| 4269 | Py_XDECREF(tmp); |
| 4270 | tmp = NULL; |
| 4271 | } else { |
| 4272 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 4273 | return 1; |
| 4274 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4275 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4276 | int res; |
| 4277 | Py_ssize_t len; |
| 4278 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4279 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4280 | if (tmp == NULL) goto failed; |
| 4281 | if (!PyList_Check(tmp)) { |
| 4282 | PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4283 | goto failed; |
| 4284 | } |
| 4285 | len = PyList_GET_SIZE(tmp); |
| 4286 | orelse = asdl_seq_new(len, arena); |
| 4287 | if (orelse == NULL) goto failed; |
| 4288 | for (i = 0; i < len; i++) { |
| 4289 | stmt_ty value; |
| 4290 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4291 | if (res != 0) goto failed; |
| 4292 | asdl_seq_SET(orelse, i, value); |
| 4293 | } |
| 4294 | Py_XDECREF(tmp); |
| 4295 | tmp = NULL; |
| 4296 | } else { |
| 4297 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 4298 | return 1; |
| 4299 | } |
| 4300 | *out = If(test, body, orelse, lineno, col_offset, arena); |
| 4301 | if (*out == NULL) goto failed; |
| 4302 | return 0; |
| 4303 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4304 | isinstance = PyObject_IsInstance(obj, (PyObject*)With_type); |
| 4305 | if (isinstance == -1) { |
| 4306 | return 1; |
| 4307 | } |
| 4308 | if (isinstance) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4309 | asdl_seq* items; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4310 | asdl_seq* body; |
| 4311 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4312 | if (_PyObject_HasAttrId(obj, &PyId_items)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4313 | int res; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4314 | Py_ssize_t len; |
| 4315 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4316 | tmp = _PyObject_GetAttrId(obj, &PyId_items); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4317 | if (tmp == NULL) goto failed; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4318 | if (!PyList_Check(tmp)) { |
| 4319 | PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4320 | goto failed; |
| 4321 | } |
| 4322 | len = PyList_GET_SIZE(tmp); |
| 4323 | items = asdl_seq_new(len, arena); |
| 4324 | if (items == NULL) goto failed; |
| 4325 | for (i = 0; i < len; i++) { |
| 4326 | withitem_ty value; |
| 4327 | res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4328 | if (res != 0) goto failed; |
| 4329 | asdl_seq_SET(items, i, value); |
| 4330 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4331 | Py_XDECREF(tmp); |
| 4332 | tmp = NULL; |
| 4333 | } else { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4334 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4335 | return 1; |
| 4336 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4337 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4338 | int res; |
| 4339 | Py_ssize_t len; |
| 4340 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4341 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4342 | if (tmp == NULL) goto failed; |
| 4343 | if (!PyList_Check(tmp)) { |
| 4344 | PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4345 | goto failed; |
| 4346 | } |
| 4347 | len = PyList_GET_SIZE(tmp); |
| 4348 | body = asdl_seq_new(len, arena); |
| 4349 | if (body == NULL) goto failed; |
| 4350 | for (i = 0; i < len; i++) { |
| 4351 | stmt_ty value; |
| 4352 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4353 | if (res != 0) goto failed; |
| 4354 | asdl_seq_SET(body, i, value); |
| 4355 | } |
| 4356 | Py_XDECREF(tmp); |
| 4357 | tmp = NULL; |
| 4358 | } else { |
| 4359 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 4360 | return 1; |
| 4361 | } |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4362 | *out = With(items, body, lineno, col_offset, arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4363 | if (*out == NULL) goto failed; |
| 4364 | return 0; |
| 4365 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4366 | isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type); |
| 4367 | if (isinstance == -1) { |
| 4368 | return 1; |
| 4369 | } |
| 4370 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4371 | expr_ty exc; |
| 4372 | expr_ty cause; |
| 4373 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4374 | if (_PyObject_HasAttrId(obj, &PyId_exc)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4375 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4376 | tmp = _PyObject_GetAttrId(obj, &PyId_exc); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4377 | if (tmp == NULL) goto failed; |
| 4378 | res = obj2ast_expr(tmp, &exc, arena); |
| 4379 | if (res != 0) goto failed; |
| 4380 | Py_XDECREF(tmp); |
| 4381 | tmp = NULL; |
| 4382 | } else { |
| 4383 | exc = NULL; |
| 4384 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4385 | if (_PyObject_HasAttrId(obj, &PyId_cause)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4386 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4387 | tmp = _PyObject_GetAttrId(obj, &PyId_cause); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4388 | if (tmp == NULL) goto failed; |
| 4389 | res = obj2ast_expr(tmp, &cause, arena); |
| 4390 | if (res != 0) goto failed; |
| 4391 | Py_XDECREF(tmp); |
| 4392 | tmp = NULL; |
| 4393 | } else { |
| 4394 | cause = NULL; |
| 4395 | } |
| 4396 | *out = Raise(exc, cause, lineno, col_offset, arena); |
| 4397 | if (*out == NULL) goto failed; |
| 4398 | return 0; |
| 4399 | } |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4400 | isinstance = PyObject_IsInstance(obj, (PyObject*)Try_type); |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4401 | if (isinstance == -1) { |
| 4402 | return 1; |
| 4403 | } |
| 4404 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4405 | asdl_seq* body; |
| 4406 | asdl_seq* handlers; |
| 4407 | asdl_seq* orelse; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4408 | asdl_seq* finalbody; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4409 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4410 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4411 | int res; |
| 4412 | Py_ssize_t len; |
| 4413 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4414 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4415 | if (tmp == NULL) goto failed; |
| 4416 | if (!PyList_Check(tmp)) { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4417 | 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] | 4418 | goto failed; |
| 4419 | } |
| 4420 | len = PyList_GET_SIZE(tmp); |
| 4421 | body = asdl_seq_new(len, arena); |
| 4422 | if (body == NULL) goto failed; |
| 4423 | for (i = 0; i < len; i++) { |
| 4424 | stmt_ty value; |
| 4425 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4426 | if (res != 0) goto failed; |
| 4427 | asdl_seq_SET(body, i, value); |
| 4428 | } |
| 4429 | Py_XDECREF(tmp); |
| 4430 | tmp = NULL; |
| 4431 | } else { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4432 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4433 | return 1; |
| 4434 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4435 | if (_PyObject_HasAttrId(obj, &PyId_handlers)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4436 | int res; |
| 4437 | Py_ssize_t len; |
| 4438 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4439 | tmp = _PyObject_GetAttrId(obj, &PyId_handlers); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4440 | if (tmp == NULL) goto failed; |
| 4441 | if (!PyList_Check(tmp)) { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4442 | 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] | 4443 | goto failed; |
| 4444 | } |
| 4445 | len = PyList_GET_SIZE(tmp); |
| 4446 | handlers = asdl_seq_new(len, arena); |
| 4447 | if (handlers == NULL) goto failed; |
| 4448 | for (i = 0; i < len; i++) { |
| 4449 | excepthandler_ty value; |
| 4450 | res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4451 | if (res != 0) goto failed; |
| 4452 | asdl_seq_SET(handlers, i, value); |
| 4453 | } |
| 4454 | Py_XDECREF(tmp); |
| 4455 | tmp = NULL; |
| 4456 | } else { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4457 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4458 | return 1; |
| 4459 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4460 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4461 | int res; |
| 4462 | Py_ssize_t len; |
| 4463 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4464 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4465 | if (tmp == NULL) goto failed; |
| 4466 | if (!PyList_Check(tmp)) { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4467 | 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] | 4468 | goto failed; |
| 4469 | } |
| 4470 | len = PyList_GET_SIZE(tmp); |
| 4471 | orelse = asdl_seq_new(len, arena); |
| 4472 | if (orelse == NULL) goto failed; |
| 4473 | for (i = 0; i < len; i++) { |
| 4474 | stmt_ty value; |
| 4475 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4476 | if (res != 0) goto failed; |
| 4477 | asdl_seq_SET(orelse, i, value); |
| 4478 | } |
| 4479 | Py_XDECREF(tmp); |
| 4480 | tmp = NULL; |
| 4481 | } else { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4482 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4483 | return 1; |
| 4484 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4485 | if (_PyObject_HasAttrId(obj, &PyId_finalbody)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4486 | int res; |
| 4487 | Py_ssize_t len; |
| 4488 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4489 | tmp = _PyObject_GetAttrId(obj, &PyId_finalbody); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4490 | if (tmp == NULL) goto failed; |
| 4491 | if (!PyList_Check(tmp)) { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4492 | 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] | 4493 | goto failed; |
| 4494 | } |
| 4495 | len = PyList_GET_SIZE(tmp); |
| 4496 | finalbody = asdl_seq_new(len, arena); |
| 4497 | if (finalbody == NULL) goto failed; |
| 4498 | for (i = 0; i < len; i++) { |
| 4499 | stmt_ty value; |
| 4500 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4501 | if (res != 0) goto failed; |
| 4502 | asdl_seq_SET(finalbody, i, value); |
| 4503 | } |
| 4504 | Py_XDECREF(tmp); |
| 4505 | tmp = NULL; |
| 4506 | } else { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4507 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4508 | return 1; |
| 4509 | } |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4510 | *out = Try(body, handlers, orelse, finalbody, lineno, |
| 4511 | col_offset, arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4512 | if (*out == NULL) goto failed; |
| 4513 | return 0; |
| 4514 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4515 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type); |
| 4516 | if (isinstance == -1) { |
| 4517 | return 1; |
| 4518 | } |
| 4519 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4520 | expr_ty test; |
| 4521 | expr_ty msg; |
| 4522 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4523 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4524 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4525 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4526 | if (tmp == NULL) goto failed; |
| 4527 | res = obj2ast_expr(tmp, &test, arena); |
| 4528 | if (res != 0) goto failed; |
| 4529 | Py_XDECREF(tmp); |
| 4530 | tmp = NULL; |
| 4531 | } else { |
| 4532 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 4533 | return 1; |
| 4534 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4535 | if (_PyObject_HasAttrId(obj, &PyId_msg)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4536 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4537 | tmp = _PyObject_GetAttrId(obj, &PyId_msg); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4538 | if (tmp == NULL) goto failed; |
| 4539 | res = obj2ast_expr(tmp, &msg, arena); |
| 4540 | if (res != 0) goto failed; |
| 4541 | Py_XDECREF(tmp); |
| 4542 | tmp = NULL; |
| 4543 | } else { |
| 4544 | msg = NULL; |
| 4545 | } |
| 4546 | *out = Assert(test, msg, lineno, col_offset, arena); |
| 4547 | if (*out == NULL) goto failed; |
| 4548 | return 0; |
| 4549 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4550 | isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type); |
| 4551 | if (isinstance == -1) { |
| 4552 | return 1; |
| 4553 | } |
| 4554 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4555 | asdl_seq* names; |
| 4556 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4557 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4558 | int res; |
| 4559 | Py_ssize_t len; |
| 4560 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4561 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4562 | if (tmp == NULL) goto failed; |
| 4563 | if (!PyList_Check(tmp)) { |
| 4564 | PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4565 | goto failed; |
| 4566 | } |
| 4567 | len = PyList_GET_SIZE(tmp); |
| 4568 | names = asdl_seq_new(len, arena); |
| 4569 | if (names == NULL) goto failed; |
| 4570 | for (i = 0; i < len; i++) { |
| 4571 | alias_ty value; |
| 4572 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4573 | if (res != 0) goto failed; |
| 4574 | asdl_seq_SET(names, i, value); |
| 4575 | } |
| 4576 | Py_XDECREF(tmp); |
| 4577 | tmp = NULL; |
| 4578 | } else { |
| 4579 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 4580 | return 1; |
| 4581 | } |
| 4582 | *out = Import(names, lineno, col_offset, arena); |
| 4583 | if (*out == NULL) goto failed; |
| 4584 | return 0; |
| 4585 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4586 | isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type); |
| 4587 | if (isinstance == -1) { |
| 4588 | return 1; |
| 4589 | } |
| 4590 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4591 | identifier module; |
| 4592 | asdl_seq* names; |
| 4593 | int level; |
| 4594 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4595 | if (_PyObject_HasAttrId(obj, &PyId_module)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4596 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4597 | tmp = _PyObject_GetAttrId(obj, &PyId_module); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4598 | if (tmp == NULL) goto failed; |
| 4599 | res = obj2ast_identifier(tmp, &module, arena); |
| 4600 | if (res != 0) goto failed; |
| 4601 | Py_XDECREF(tmp); |
| 4602 | tmp = NULL; |
| 4603 | } else { |
Benjamin Peterson | 78565b2 | 2009-06-28 19:19:51 +0000 | [diff] [blame] | 4604 | module = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4605 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4606 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4607 | int res; |
| 4608 | Py_ssize_t len; |
| 4609 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4610 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4611 | if (tmp == NULL) goto failed; |
| 4612 | if (!PyList_Check(tmp)) { |
| 4613 | PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4614 | goto failed; |
| 4615 | } |
| 4616 | len = PyList_GET_SIZE(tmp); |
| 4617 | names = asdl_seq_new(len, arena); |
| 4618 | if (names == NULL) goto failed; |
| 4619 | for (i = 0; i < len; i++) { |
| 4620 | alias_ty value; |
| 4621 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4622 | if (res != 0) goto failed; |
| 4623 | asdl_seq_SET(names, i, value); |
| 4624 | } |
| 4625 | Py_XDECREF(tmp); |
| 4626 | tmp = NULL; |
| 4627 | } else { |
| 4628 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 4629 | return 1; |
| 4630 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4631 | if (_PyObject_HasAttrId(obj, &PyId_level)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4632 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4633 | tmp = _PyObject_GetAttrId(obj, &PyId_level); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4634 | if (tmp == NULL) goto failed; |
| 4635 | res = obj2ast_int(tmp, &level, arena); |
| 4636 | if (res != 0) goto failed; |
| 4637 | Py_XDECREF(tmp); |
| 4638 | tmp = NULL; |
| 4639 | } else { |
| 4640 | level = 0; |
| 4641 | } |
| 4642 | *out = ImportFrom(module, names, level, lineno, col_offset, |
| 4643 | arena); |
| 4644 | if (*out == NULL) goto failed; |
| 4645 | return 0; |
| 4646 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4647 | isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type); |
| 4648 | if (isinstance == -1) { |
| 4649 | return 1; |
| 4650 | } |
| 4651 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4652 | asdl_seq* names; |
| 4653 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4654 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4655 | int res; |
| 4656 | Py_ssize_t len; |
| 4657 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4658 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4659 | if (tmp == NULL) goto failed; |
| 4660 | if (!PyList_Check(tmp)) { |
| 4661 | PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4662 | goto failed; |
| 4663 | } |
| 4664 | len = PyList_GET_SIZE(tmp); |
| 4665 | names = asdl_seq_new(len, arena); |
| 4666 | if (names == NULL) goto failed; |
| 4667 | for (i = 0; i < len; i++) { |
| 4668 | identifier value; |
| 4669 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4670 | if (res != 0) goto failed; |
| 4671 | asdl_seq_SET(names, i, value); |
| 4672 | } |
| 4673 | Py_XDECREF(tmp); |
| 4674 | tmp = NULL; |
| 4675 | } else { |
| 4676 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 4677 | return 1; |
| 4678 | } |
| 4679 | *out = Global(names, lineno, col_offset, arena); |
| 4680 | if (*out == NULL) goto failed; |
| 4681 | return 0; |
| 4682 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4683 | isinstance = PyObject_IsInstance(obj, (PyObject*)Nonlocal_type); |
| 4684 | if (isinstance == -1) { |
| 4685 | return 1; |
| 4686 | } |
| 4687 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4688 | asdl_seq* names; |
| 4689 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4690 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4691 | int res; |
| 4692 | Py_ssize_t len; |
| 4693 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4694 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4695 | if (tmp == NULL) goto failed; |
| 4696 | if (!PyList_Check(tmp)) { |
| 4697 | PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4698 | goto failed; |
| 4699 | } |
| 4700 | len = PyList_GET_SIZE(tmp); |
| 4701 | names = asdl_seq_new(len, arena); |
| 4702 | if (names == NULL) goto failed; |
| 4703 | for (i = 0; i < len; i++) { |
| 4704 | identifier value; |
| 4705 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4706 | if (res != 0) goto failed; |
| 4707 | asdl_seq_SET(names, i, value); |
| 4708 | } |
| 4709 | Py_XDECREF(tmp); |
| 4710 | tmp = NULL; |
| 4711 | } else { |
| 4712 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 4713 | return 1; |
| 4714 | } |
| 4715 | *out = Nonlocal(names, lineno, col_offset, arena); |
| 4716 | if (*out == NULL) goto failed; |
| 4717 | return 0; |
| 4718 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4719 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type); |
| 4720 | if (isinstance == -1) { |
| 4721 | return 1; |
| 4722 | } |
| 4723 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4724 | expr_ty value; |
| 4725 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4726 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4727 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4728 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4729 | if (tmp == NULL) goto failed; |
| 4730 | res = obj2ast_expr(tmp, &value, arena); |
| 4731 | if (res != 0) goto failed; |
| 4732 | Py_XDECREF(tmp); |
| 4733 | tmp = NULL; |
| 4734 | } else { |
| 4735 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 4736 | return 1; |
| 4737 | } |
| 4738 | *out = Expr(value, lineno, col_offset, arena); |
| 4739 | if (*out == NULL) goto failed; |
| 4740 | return 0; |
| 4741 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4742 | isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type); |
| 4743 | if (isinstance == -1) { |
| 4744 | return 1; |
| 4745 | } |
| 4746 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4747 | |
| 4748 | *out = Pass(lineno, col_offset, arena); |
| 4749 | if (*out == NULL) goto failed; |
| 4750 | return 0; |
| 4751 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4752 | isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type); |
| 4753 | if (isinstance == -1) { |
| 4754 | return 1; |
| 4755 | } |
| 4756 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4757 | |
| 4758 | *out = Break(lineno, col_offset, arena); |
| 4759 | if (*out == NULL) goto failed; |
| 4760 | return 0; |
| 4761 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4762 | isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type); |
| 4763 | if (isinstance == -1) { |
| 4764 | return 1; |
| 4765 | } |
| 4766 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4767 | |
| 4768 | *out = Continue(lineno, col_offset, arena); |
| 4769 | if (*out == NULL) goto failed; |
| 4770 | return 0; |
| 4771 | } |
| 4772 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 4773 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
| 4774 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 4775 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4776 | return 1; |
| 4777 | } |
| 4778 | |
| 4779 | int |
| 4780 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 4781 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4782 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4783 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 4784 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4785 | int lineno; |
| 4786 | int col_offset; |
| 4787 | |
| 4788 | if (obj == Py_None) { |
| 4789 | *out = NULL; |
| 4790 | return 0; |
| 4791 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4792 | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4793 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4794 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4795 | if (tmp == NULL) goto failed; |
| 4796 | res = obj2ast_int(tmp, &lineno, arena); |
| 4797 | if (res != 0) goto failed; |
| 4798 | Py_XDECREF(tmp); |
| 4799 | tmp = NULL; |
| 4800 | } else { |
| 4801 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 4802 | return 1; |
| 4803 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4804 | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4805 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4806 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4807 | if (tmp == NULL) goto failed; |
| 4808 | res = obj2ast_int(tmp, &col_offset, arena); |
| 4809 | if (res != 0) goto failed; |
| 4810 | Py_XDECREF(tmp); |
| 4811 | tmp = NULL; |
| 4812 | } else { |
| 4813 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 4814 | return 1; |
| 4815 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4816 | isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type); |
| 4817 | if (isinstance == -1) { |
| 4818 | return 1; |
| 4819 | } |
| 4820 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4821 | boolop_ty op; |
| 4822 | asdl_seq* values; |
| 4823 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4824 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4825 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4826 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4827 | if (tmp == NULL) goto failed; |
| 4828 | res = obj2ast_boolop(tmp, &op, arena); |
| 4829 | if (res != 0) goto failed; |
| 4830 | Py_XDECREF(tmp); |
| 4831 | tmp = NULL; |
| 4832 | } else { |
| 4833 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 4834 | return 1; |
| 4835 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4836 | if (_PyObject_HasAttrId(obj, &PyId_values)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4837 | int res; |
| 4838 | Py_ssize_t len; |
| 4839 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4840 | tmp = _PyObject_GetAttrId(obj, &PyId_values); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4841 | if (tmp == NULL) goto failed; |
| 4842 | if (!PyList_Check(tmp)) { |
| 4843 | PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4844 | goto failed; |
| 4845 | } |
| 4846 | len = PyList_GET_SIZE(tmp); |
| 4847 | values = asdl_seq_new(len, arena); |
| 4848 | if (values == NULL) goto failed; |
| 4849 | for (i = 0; i < len; i++) { |
| 4850 | expr_ty value; |
| 4851 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4852 | if (res != 0) goto failed; |
| 4853 | asdl_seq_SET(values, i, value); |
| 4854 | } |
| 4855 | Py_XDECREF(tmp); |
| 4856 | tmp = NULL; |
| 4857 | } else { |
| 4858 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 4859 | return 1; |
| 4860 | } |
| 4861 | *out = BoolOp(op, values, lineno, col_offset, arena); |
| 4862 | if (*out == NULL) goto failed; |
| 4863 | return 0; |
| 4864 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4865 | isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type); |
| 4866 | if (isinstance == -1) { |
| 4867 | return 1; |
| 4868 | } |
| 4869 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4870 | expr_ty left; |
| 4871 | operator_ty op; |
| 4872 | expr_ty right; |
| 4873 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4874 | if (_PyObject_HasAttrId(obj, &PyId_left)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4875 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4876 | tmp = _PyObject_GetAttrId(obj, &PyId_left); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4877 | if (tmp == NULL) goto failed; |
| 4878 | res = obj2ast_expr(tmp, &left, arena); |
| 4879 | if (res != 0) goto failed; |
| 4880 | Py_XDECREF(tmp); |
| 4881 | tmp = NULL; |
| 4882 | } else { |
| 4883 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 4884 | return 1; |
| 4885 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4886 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4887 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4888 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4889 | if (tmp == NULL) goto failed; |
| 4890 | res = obj2ast_operator(tmp, &op, arena); |
| 4891 | if (res != 0) goto failed; |
| 4892 | Py_XDECREF(tmp); |
| 4893 | tmp = NULL; |
| 4894 | } else { |
| 4895 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 4896 | return 1; |
| 4897 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4898 | if (_PyObject_HasAttrId(obj, &PyId_right)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4899 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4900 | tmp = _PyObject_GetAttrId(obj, &PyId_right); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4901 | if (tmp == NULL) goto failed; |
| 4902 | res = obj2ast_expr(tmp, &right, arena); |
| 4903 | if (res != 0) goto failed; |
| 4904 | Py_XDECREF(tmp); |
| 4905 | tmp = NULL; |
| 4906 | } else { |
| 4907 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 4908 | return 1; |
| 4909 | } |
| 4910 | *out = BinOp(left, op, right, lineno, col_offset, arena); |
| 4911 | if (*out == NULL) goto failed; |
| 4912 | return 0; |
| 4913 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4914 | isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type); |
| 4915 | if (isinstance == -1) { |
| 4916 | return 1; |
| 4917 | } |
| 4918 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4919 | unaryop_ty op; |
| 4920 | expr_ty operand; |
| 4921 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4922 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4923 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4924 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4925 | if (tmp == NULL) goto failed; |
| 4926 | res = obj2ast_unaryop(tmp, &op, arena); |
| 4927 | if (res != 0) goto failed; |
| 4928 | Py_XDECREF(tmp); |
| 4929 | tmp = NULL; |
| 4930 | } else { |
| 4931 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 4932 | return 1; |
| 4933 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4934 | if (_PyObject_HasAttrId(obj, &PyId_operand)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4935 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4936 | tmp = _PyObject_GetAttrId(obj, &PyId_operand); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4937 | if (tmp == NULL) goto failed; |
| 4938 | res = obj2ast_expr(tmp, &operand, arena); |
| 4939 | if (res != 0) goto failed; |
| 4940 | Py_XDECREF(tmp); |
| 4941 | tmp = NULL; |
| 4942 | } else { |
| 4943 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 4944 | return 1; |
| 4945 | } |
| 4946 | *out = UnaryOp(op, operand, lineno, col_offset, arena); |
| 4947 | if (*out == NULL) goto failed; |
| 4948 | return 0; |
| 4949 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4950 | isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type); |
| 4951 | if (isinstance == -1) { |
| 4952 | return 1; |
| 4953 | } |
| 4954 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4955 | arguments_ty args; |
| 4956 | expr_ty body; |
| 4957 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4958 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4959 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4960 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4961 | if (tmp == NULL) goto failed; |
| 4962 | res = obj2ast_arguments(tmp, &args, arena); |
| 4963 | if (res != 0) goto failed; |
| 4964 | Py_XDECREF(tmp); |
| 4965 | tmp = NULL; |
| 4966 | } else { |
| 4967 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 4968 | return 1; |
| 4969 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4970 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4971 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4972 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4973 | if (tmp == NULL) goto failed; |
| 4974 | res = obj2ast_expr(tmp, &body, arena); |
| 4975 | if (res != 0) goto failed; |
| 4976 | Py_XDECREF(tmp); |
| 4977 | tmp = NULL; |
| 4978 | } else { |
| 4979 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 4980 | return 1; |
| 4981 | } |
| 4982 | *out = Lambda(args, body, lineno, col_offset, arena); |
| 4983 | if (*out == NULL) goto failed; |
| 4984 | return 0; |
| 4985 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4986 | isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type); |
| 4987 | if (isinstance == -1) { |
| 4988 | return 1; |
| 4989 | } |
| 4990 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4991 | expr_ty test; |
| 4992 | expr_ty body; |
| 4993 | expr_ty orelse; |
| 4994 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4995 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4996 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4997 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4998 | if (tmp == NULL) goto failed; |
| 4999 | res = obj2ast_expr(tmp, &test, arena); |
| 5000 | if (res != 0) goto failed; |
| 5001 | Py_XDECREF(tmp); |
| 5002 | tmp = NULL; |
| 5003 | } else { |
| 5004 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 5005 | return 1; |
| 5006 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5007 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5008 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5009 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5010 | if (tmp == NULL) goto failed; |
| 5011 | res = obj2ast_expr(tmp, &body, arena); |
| 5012 | if (res != 0) goto failed; |
| 5013 | Py_XDECREF(tmp); |
| 5014 | tmp = NULL; |
| 5015 | } else { |
| 5016 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 5017 | return 1; |
| 5018 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5019 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5020 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5021 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5022 | if (tmp == NULL) goto failed; |
| 5023 | res = obj2ast_expr(tmp, &orelse, arena); |
| 5024 | if (res != 0) goto failed; |
| 5025 | Py_XDECREF(tmp); |
| 5026 | tmp = NULL; |
| 5027 | } else { |
| 5028 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 5029 | return 1; |
| 5030 | } |
| 5031 | *out = IfExp(test, body, orelse, lineno, col_offset, arena); |
| 5032 | if (*out == NULL) goto failed; |
| 5033 | return 0; |
| 5034 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5035 | isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type); |
| 5036 | if (isinstance == -1) { |
| 5037 | return 1; |
| 5038 | } |
| 5039 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5040 | asdl_seq* keys; |
| 5041 | asdl_seq* values; |
| 5042 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5043 | if (_PyObject_HasAttrId(obj, &PyId_keys)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5044 | int res; |
| 5045 | Py_ssize_t len; |
| 5046 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5047 | tmp = _PyObject_GetAttrId(obj, &PyId_keys); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5048 | if (tmp == NULL) goto failed; |
| 5049 | if (!PyList_Check(tmp)) { |
| 5050 | PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5051 | goto failed; |
| 5052 | } |
| 5053 | len = PyList_GET_SIZE(tmp); |
| 5054 | keys = asdl_seq_new(len, arena); |
| 5055 | if (keys == NULL) goto failed; |
| 5056 | for (i = 0; i < len; i++) { |
| 5057 | expr_ty value; |
| 5058 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5059 | if (res != 0) goto failed; |
| 5060 | asdl_seq_SET(keys, i, value); |
| 5061 | } |
| 5062 | Py_XDECREF(tmp); |
| 5063 | tmp = NULL; |
| 5064 | } else { |
| 5065 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 5066 | return 1; |
| 5067 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5068 | if (_PyObject_HasAttrId(obj, &PyId_values)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5069 | int res; |
| 5070 | Py_ssize_t len; |
| 5071 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5072 | tmp = _PyObject_GetAttrId(obj, &PyId_values); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5073 | if (tmp == NULL) goto failed; |
| 5074 | if (!PyList_Check(tmp)) { |
| 5075 | PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5076 | goto failed; |
| 5077 | } |
| 5078 | len = PyList_GET_SIZE(tmp); |
| 5079 | values = asdl_seq_new(len, arena); |
| 5080 | if (values == NULL) goto failed; |
| 5081 | for (i = 0; i < len; i++) { |
| 5082 | expr_ty value; |
| 5083 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5084 | if (res != 0) goto failed; |
| 5085 | asdl_seq_SET(values, i, value); |
| 5086 | } |
| 5087 | Py_XDECREF(tmp); |
| 5088 | tmp = NULL; |
| 5089 | } else { |
| 5090 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 5091 | return 1; |
| 5092 | } |
| 5093 | *out = Dict(keys, values, lineno, col_offset, arena); |
| 5094 | if (*out == NULL) goto failed; |
| 5095 | return 0; |
| 5096 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5097 | isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type); |
| 5098 | if (isinstance == -1) { |
| 5099 | return 1; |
| 5100 | } |
| 5101 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5102 | asdl_seq* elts; |
| 5103 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5104 | if (_PyObject_HasAttrId(obj, &PyId_elts)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5105 | int res; |
| 5106 | Py_ssize_t len; |
| 5107 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5108 | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5109 | if (tmp == NULL) goto failed; |
| 5110 | if (!PyList_Check(tmp)) { |
| 5111 | PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5112 | goto failed; |
| 5113 | } |
| 5114 | len = PyList_GET_SIZE(tmp); |
| 5115 | elts = asdl_seq_new(len, arena); |
| 5116 | if (elts == NULL) goto failed; |
| 5117 | for (i = 0; i < len; i++) { |
| 5118 | expr_ty value; |
| 5119 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5120 | if (res != 0) goto failed; |
| 5121 | asdl_seq_SET(elts, i, value); |
| 5122 | } |
| 5123 | Py_XDECREF(tmp); |
| 5124 | tmp = NULL; |
| 5125 | } else { |
| 5126 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 5127 | return 1; |
| 5128 | } |
| 5129 | *out = Set(elts, lineno, col_offset, arena); |
| 5130 | if (*out == NULL) goto failed; |
| 5131 | return 0; |
| 5132 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5133 | isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type); |
| 5134 | if (isinstance == -1) { |
| 5135 | return 1; |
| 5136 | } |
| 5137 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5138 | expr_ty elt; |
| 5139 | asdl_seq* generators; |
| 5140 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5141 | if (_PyObject_HasAttrId(obj, &PyId_elt)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5142 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5143 | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5144 | if (tmp == NULL) goto failed; |
| 5145 | res = obj2ast_expr(tmp, &elt, arena); |
| 5146 | if (res != 0) goto failed; |
| 5147 | Py_XDECREF(tmp); |
| 5148 | tmp = NULL; |
| 5149 | } else { |
| 5150 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 5151 | return 1; |
| 5152 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5153 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5154 | int res; |
| 5155 | Py_ssize_t len; |
| 5156 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5157 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5158 | if (tmp == NULL) goto failed; |
| 5159 | if (!PyList_Check(tmp)) { |
| 5160 | PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5161 | goto failed; |
| 5162 | } |
| 5163 | len = PyList_GET_SIZE(tmp); |
| 5164 | generators = asdl_seq_new(len, arena); |
| 5165 | if (generators == NULL) goto failed; |
| 5166 | for (i = 0; i < len; i++) { |
| 5167 | comprehension_ty value; |
| 5168 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5169 | if (res != 0) goto failed; |
| 5170 | asdl_seq_SET(generators, i, value); |
| 5171 | } |
| 5172 | Py_XDECREF(tmp); |
| 5173 | tmp = NULL; |
| 5174 | } else { |
| 5175 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 5176 | return 1; |
| 5177 | } |
| 5178 | *out = ListComp(elt, generators, lineno, col_offset, arena); |
| 5179 | if (*out == NULL) goto failed; |
| 5180 | return 0; |
| 5181 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5182 | isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type); |
| 5183 | if (isinstance == -1) { |
| 5184 | return 1; |
| 5185 | } |
| 5186 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5187 | expr_ty elt; |
| 5188 | asdl_seq* generators; |
| 5189 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5190 | if (_PyObject_HasAttrId(obj, &PyId_elt)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5191 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5192 | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5193 | if (tmp == NULL) goto failed; |
| 5194 | res = obj2ast_expr(tmp, &elt, arena); |
| 5195 | if (res != 0) goto failed; |
| 5196 | Py_XDECREF(tmp); |
| 5197 | tmp = NULL; |
| 5198 | } else { |
| 5199 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 5200 | return 1; |
| 5201 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5202 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5203 | int res; |
| 5204 | Py_ssize_t len; |
| 5205 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5206 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5207 | if (tmp == NULL) goto failed; |
| 5208 | if (!PyList_Check(tmp)) { |
| 5209 | PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5210 | goto failed; |
| 5211 | } |
| 5212 | len = PyList_GET_SIZE(tmp); |
| 5213 | generators = asdl_seq_new(len, arena); |
| 5214 | if (generators == NULL) goto failed; |
| 5215 | for (i = 0; i < len; i++) { |
| 5216 | comprehension_ty value; |
| 5217 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5218 | if (res != 0) goto failed; |
| 5219 | asdl_seq_SET(generators, i, value); |
| 5220 | } |
| 5221 | Py_XDECREF(tmp); |
| 5222 | tmp = NULL; |
| 5223 | } else { |
| 5224 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 5225 | return 1; |
| 5226 | } |
| 5227 | *out = SetComp(elt, generators, lineno, col_offset, arena); |
| 5228 | if (*out == NULL) goto failed; |
| 5229 | return 0; |
| 5230 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5231 | isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type); |
| 5232 | if (isinstance == -1) { |
| 5233 | return 1; |
| 5234 | } |
| 5235 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5236 | expr_ty key; |
| 5237 | expr_ty value; |
| 5238 | asdl_seq* generators; |
| 5239 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5240 | if (_PyObject_HasAttrId(obj, &PyId_key)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5241 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5242 | tmp = _PyObject_GetAttrId(obj, &PyId_key); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5243 | if (tmp == NULL) goto failed; |
| 5244 | res = obj2ast_expr(tmp, &key, arena); |
| 5245 | if (res != 0) goto failed; |
| 5246 | Py_XDECREF(tmp); |
| 5247 | tmp = NULL; |
| 5248 | } else { |
| 5249 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 5250 | return 1; |
| 5251 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5252 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5253 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5254 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5255 | if (tmp == NULL) goto failed; |
| 5256 | res = obj2ast_expr(tmp, &value, arena); |
| 5257 | if (res != 0) goto failed; |
| 5258 | Py_XDECREF(tmp); |
| 5259 | tmp = NULL; |
| 5260 | } else { |
| 5261 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 5262 | return 1; |
| 5263 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5264 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5265 | int res; |
| 5266 | Py_ssize_t len; |
| 5267 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5268 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5269 | if (tmp == NULL) goto failed; |
| 5270 | if (!PyList_Check(tmp)) { |
| 5271 | PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5272 | goto failed; |
| 5273 | } |
| 5274 | len = PyList_GET_SIZE(tmp); |
| 5275 | generators = asdl_seq_new(len, arena); |
| 5276 | if (generators == NULL) goto failed; |
| 5277 | for (i = 0; i < len; i++) { |
| 5278 | comprehension_ty value; |
| 5279 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5280 | if (res != 0) goto failed; |
| 5281 | asdl_seq_SET(generators, i, value); |
| 5282 | } |
| 5283 | Py_XDECREF(tmp); |
| 5284 | tmp = NULL; |
| 5285 | } else { |
| 5286 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 5287 | return 1; |
| 5288 | } |
| 5289 | *out = DictComp(key, value, generators, lineno, col_offset, |
| 5290 | arena); |
| 5291 | if (*out == NULL) goto failed; |
| 5292 | return 0; |
| 5293 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5294 | isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type); |
| 5295 | if (isinstance == -1) { |
| 5296 | return 1; |
| 5297 | } |
| 5298 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5299 | expr_ty elt; |
| 5300 | asdl_seq* generators; |
| 5301 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5302 | if (_PyObject_HasAttrId(obj, &PyId_elt)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5303 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5304 | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5305 | if (tmp == NULL) goto failed; |
| 5306 | res = obj2ast_expr(tmp, &elt, arena); |
| 5307 | if (res != 0) goto failed; |
| 5308 | Py_XDECREF(tmp); |
| 5309 | tmp = NULL; |
| 5310 | } else { |
| 5311 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 5312 | return 1; |
| 5313 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5314 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5315 | int res; |
| 5316 | Py_ssize_t len; |
| 5317 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5318 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5319 | if (tmp == NULL) goto failed; |
| 5320 | if (!PyList_Check(tmp)) { |
| 5321 | PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5322 | goto failed; |
| 5323 | } |
| 5324 | len = PyList_GET_SIZE(tmp); |
| 5325 | generators = asdl_seq_new(len, arena); |
| 5326 | if (generators == NULL) goto failed; |
| 5327 | for (i = 0; i < len; i++) { |
| 5328 | comprehension_ty value; |
| 5329 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5330 | if (res != 0) goto failed; |
| 5331 | asdl_seq_SET(generators, i, value); |
| 5332 | } |
| 5333 | Py_XDECREF(tmp); |
| 5334 | tmp = NULL; |
| 5335 | } else { |
| 5336 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 5337 | return 1; |
| 5338 | } |
| 5339 | *out = GeneratorExp(elt, generators, lineno, col_offset, arena); |
| 5340 | if (*out == NULL) goto failed; |
| 5341 | return 0; |
| 5342 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5343 | isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); |
| 5344 | if (isinstance == -1) { |
| 5345 | return 1; |
| 5346 | } |
| 5347 | if (isinstance) { |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame^] | 5348 | int is_from; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5349 | expr_ty value; |
| 5350 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame^] | 5351 | if (_PyObject_HasAttrId(obj, &PyId_is_from)) { |
| 5352 | int res; |
| 5353 | tmp = _PyObject_GetAttrId(obj, &PyId_is_from); |
| 5354 | if (tmp == NULL) goto failed; |
| 5355 | res = obj2ast_int(tmp, &is_from, arena); |
| 5356 | if (res != 0) goto failed; |
| 5357 | Py_XDECREF(tmp); |
| 5358 | tmp = NULL; |
| 5359 | } else { |
| 5360 | PyErr_SetString(PyExc_TypeError, "required field \"is_from\" missing from Yield"); |
| 5361 | return 1; |
| 5362 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5363 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5364 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5365 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5366 | if (tmp == NULL) goto failed; |
| 5367 | res = obj2ast_expr(tmp, &value, arena); |
| 5368 | if (res != 0) goto failed; |
| 5369 | Py_XDECREF(tmp); |
| 5370 | tmp = NULL; |
| 5371 | } else { |
| 5372 | value = NULL; |
| 5373 | } |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame^] | 5374 | *out = Yield(is_from, value, lineno, col_offset, arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5375 | if (*out == NULL) goto failed; |
| 5376 | return 0; |
| 5377 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5378 | isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); |
| 5379 | if (isinstance == -1) { |
| 5380 | return 1; |
| 5381 | } |
| 5382 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5383 | expr_ty left; |
| 5384 | asdl_int_seq* ops; |
| 5385 | asdl_seq* comparators; |
| 5386 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5387 | if (_PyObject_HasAttrId(obj, &PyId_left)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5388 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5389 | tmp = _PyObject_GetAttrId(obj, &PyId_left); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5390 | if (tmp == NULL) goto failed; |
| 5391 | res = obj2ast_expr(tmp, &left, arena); |
| 5392 | if (res != 0) goto failed; |
| 5393 | Py_XDECREF(tmp); |
| 5394 | tmp = NULL; |
| 5395 | } else { |
| 5396 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 5397 | return 1; |
| 5398 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5399 | if (_PyObject_HasAttrId(obj, &PyId_ops)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5400 | int res; |
| 5401 | Py_ssize_t len; |
| 5402 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5403 | tmp = _PyObject_GetAttrId(obj, &PyId_ops); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5404 | if (tmp == NULL) goto failed; |
| 5405 | if (!PyList_Check(tmp)) { |
| 5406 | PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5407 | goto failed; |
| 5408 | } |
| 5409 | len = PyList_GET_SIZE(tmp); |
| 5410 | ops = asdl_int_seq_new(len, arena); |
| 5411 | if (ops == NULL) goto failed; |
| 5412 | for (i = 0; i < len; i++) { |
| 5413 | cmpop_ty value; |
| 5414 | res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5415 | if (res != 0) goto failed; |
| 5416 | asdl_seq_SET(ops, i, value); |
| 5417 | } |
| 5418 | Py_XDECREF(tmp); |
| 5419 | tmp = NULL; |
| 5420 | } else { |
| 5421 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 5422 | return 1; |
| 5423 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5424 | if (_PyObject_HasAttrId(obj, &PyId_comparators)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5425 | int res; |
| 5426 | Py_ssize_t len; |
| 5427 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5428 | tmp = _PyObject_GetAttrId(obj, &PyId_comparators); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5429 | if (tmp == NULL) goto failed; |
| 5430 | if (!PyList_Check(tmp)) { |
| 5431 | PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5432 | goto failed; |
| 5433 | } |
| 5434 | len = PyList_GET_SIZE(tmp); |
| 5435 | comparators = asdl_seq_new(len, arena); |
| 5436 | if (comparators == NULL) goto failed; |
| 5437 | for (i = 0; i < len; i++) { |
| 5438 | expr_ty value; |
| 5439 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5440 | if (res != 0) goto failed; |
| 5441 | asdl_seq_SET(comparators, i, value); |
| 5442 | } |
| 5443 | Py_XDECREF(tmp); |
| 5444 | tmp = NULL; |
| 5445 | } else { |
| 5446 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 5447 | return 1; |
| 5448 | } |
| 5449 | *out = Compare(left, ops, comparators, lineno, col_offset, |
| 5450 | arena); |
| 5451 | if (*out == NULL) goto failed; |
| 5452 | return 0; |
| 5453 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5454 | isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type); |
| 5455 | if (isinstance == -1) { |
| 5456 | return 1; |
| 5457 | } |
| 5458 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5459 | expr_ty func; |
| 5460 | asdl_seq* args; |
| 5461 | asdl_seq* keywords; |
| 5462 | expr_ty starargs; |
| 5463 | expr_ty kwargs; |
| 5464 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5465 | if (_PyObject_HasAttrId(obj, &PyId_func)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5466 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5467 | tmp = _PyObject_GetAttrId(obj, &PyId_func); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5468 | if (tmp == NULL) goto failed; |
| 5469 | res = obj2ast_expr(tmp, &func, arena); |
| 5470 | if (res != 0) goto failed; |
| 5471 | Py_XDECREF(tmp); |
| 5472 | tmp = NULL; |
| 5473 | } else { |
| 5474 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 5475 | return 1; |
| 5476 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5477 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5478 | int res; |
| 5479 | Py_ssize_t len; |
| 5480 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5481 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5482 | if (tmp == NULL) goto failed; |
| 5483 | if (!PyList_Check(tmp)) { |
| 5484 | PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5485 | goto failed; |
| 5486 | } |
| 5487 | len = PyList_GET_SIZE(tmp); |
| 5488 | args = asdl_seq_new(len, arena); |
| 5489 | if (args == NULL) goto failed; |
| 5490 | for (i = 0; i < len; i++) { |
| 5491 | expr_ty value; |
| 5492 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5493 | if (res != 0) goto failed; |
| 5494 | asdl_seq_SET(args, i, value); |
| 5495 | } |
| 5496 | Py_XDECREF(tmp); |
| 5497 | tmp = NULL; |
| 5498 | } else { |
| 5499 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 5500 | return 1; |
| 5501 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5502 | if (_PyObject_HasAttrId(obj, &PyId_keywords)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5503 | int res; |
| 5504 | Py_ssize_t len; |
| 5505 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5506 | tmp = _PyObject_GetAttrId(obj, &PyId_keywords); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5507 | if (tmp == NULL) goto failed; |
| 5508 | if (!PyList_Check(tmp)) { |
| 5509 | PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5510 | goto failed; |
| 5511 | } |
| 5512 | len = PyList_GET_SIZE(tmp); |
| 5513 | keywords = asdl_seq_new(len, arena); |
| 5514 | if (keywords == NULL) goto failed; |
| 5515 | for (i = 0; i < len; i++) { |
| 5516 | keyword_ty value; |
| 5517 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5518 | if (res != 0) goto failed; |
| 5519 | asdl_seq_SET(keywords, i, value); |
| 5520 | } |
| 5521 | Py_XDECREF(tmp); |
| 5522 | tmp = NULL; |
| 5523 | } else { |
| 5524 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 5525 | return 1; |
| 5526 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5527 | if (_PyObject_HasAttrId(obj, &PyId_starargs)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5528 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5529 | tmp = _PyObject_GetAttrId(obj, &PyId_starargs); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5530 | if (tmp == NULL) goto failed; |
| 5531 | res = obj2ast_expr(tmp, &starargs, arena); |
| 5532 | if (res != 0) goto failed; |
| 5533 | Py_XDECREF(tmp); |
| 5534 | tmp = NULL; |
| 5535 | } else { |
| 5536 | starargs = NULL; |
| 5537 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5538 | if (_PyObject_HasAttrId(obj, &PyId_kwargs)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5539 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5540 | tmp = _PyObject_GetAttrId(obj, &PyId_kwargs); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5541 | if (tmp == NULL) goto failed; |
| 5542 | res = obj2ast_expr(tmp, &kwargs, arena); |
| 5543 | if (res != 0) goto failed; |
| 5544 | Py_XDECREF(tmp); |
| 5545 | tmp = NULL; |
| 5546 | } else { |
| 5547 | kwargs = NULL; |
| 5548 | } |
| 5549 | *out = Call(func, args, keywords, starargs, kwargs, lineno, |
| 5550 | col_offset, arena); |
| 5551 | if (*out == NULL) goto failed; |
| 5552 | return 0; |
| 5553 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5554 | isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type); |
| 5555 | if (isinstance == -1) { |
| 5556 | return 1; |
| 5557 | } |
| 5558 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5559 | object n; |
| 5560 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5561 | if (_PyObject_HasAttrId(obj, &PyId_n)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5562 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5563 | tmp = _PyObject_GetAttrId(obj, &PyId_n); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5564 | if (tmp == NULL) goto failed; |
| 5565 | res = obj2ast_object(tmp, &n, arena); |
| 5566 | if (res != 0) goto failed; |
| 5567 | Py_XDECREF(tmp); |
| 5568 | tmp = NULL; |
| 5569 | } else { |
| 5570 | PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num"); |
| 5571 | return 1; |
| 5572 | } |
| 5573 | *out = Num(n, lineno, col_offset, arena); |
| 5574 | if (*out == NULL) goto failed; |
| 5575 | return 0; |
| 5576 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5577 | isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type); |
| 5578 | if (isinstance == -1) { |
| 5579 | return 1; |
| 5580 | } |
| 5581 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5582 | string s; |
| 5583 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5584 | if (_PyObject_HasAttrId(obj, &PyId_s)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5585 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5586 | tmp = _PyObject_GetAttrId(obj, &PyId_s); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5587 | if (tmp == NULL) goto failed; |
| 5588 | res = obj2ast_string(tmp, &s, arena); |
| 5589 | if (res != 0) goto failed; |
| 5590 | Py_XDECREF(tmp); |
| 5591 | tmp = NULL; |
| 5592 | } else { |
| 5593 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str"); |
| 5594 | return 1; |
| 5595 | } |
| 5596 | *out = Str(s, lineno, col_offset, arena); |
| 5597 | if (*out == NULL) goto failed; |
| 5598 | return 0; |
| 5599 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5600 | isinstance = PyObject_IsInstance(obj, (PyObject*)Bytes_type); |
| 5601 | if (isinstance == -1) { |
| 5602 | return 1; |
| 5603 | } |
| 5604 | if (isinstance) { |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 5605 | bytes s; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5606 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5607 | if (_PyObject_HasAttrId(obj, &PyId_s)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5608 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5609 | tmp = _PyObject_GetAttrId(obj, &PyId_s); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5610 | if (tmp == NULL) goto failed; |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 5611 | res = obj2ast_bytes(tmp, &s, arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5612 | if (res != 0) goto failed; |
| 5613 | Py_XDECREF(tmp); |
| 5614 | tmp = NULL; |
| 5615 | } else { |
| 5616 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Bytes"); |
| 5617 | return 1; |
| 5618 | } |
| 5619 | *out = Bytes(s, lineno, col_offset, arena); |
| 5620 | if (*out == NULL) goto failed; |
| 5621 | return 0; |
| 5622 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5623 | isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type); |
| 5624 | if (isinstance == -1) { |
| 5625 | return 1; |
| 5626 | } |
| 5627 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5628 | |
| 5629 | *out = Ellipsis(lineno, col_offset, arena); |
| 5630 | if (*out == NULL) goto failed; |
| 5631 | return 0; |
| 5632 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5633 | isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type); |
| 5634 | if (isinstance == -1) { |
| 5635 | return 1; |
| 5636 | } |
| 5637 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5638 | expr_ty value; |
| 5639 | identifier attr; |
| 5640 | expr_context_ty ctx; |
| 5641 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5642 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5643 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5644 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5645 | if (tmp == NULL) goto failed; |
| 5646 | res = obj2ast_expr(tmp, &value, arena); |
| 5647 | if (res != 0) goto failed; |
| 5648 | Py_XDECREF(tmp); |
| 5649 | tmp = NULL; |
| 5650 | } else { |
| 5651 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 5652 | return 1; |
| 5653 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5654 | if (_PyObject_HasAttrId(obj, &PyId_attr)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5655 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5656 | tmp = _PyObject_GetAttrId(obj, &PyId_attr); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5657 | if (tmp == NULL) goto failed; |
| 5658 | res = obj2ast_identifier(tmp, &attr, arena); |
| 5659 | if (res != 0) goto failed; |
| 5660 | Py_XDECREF(tmp); |
| 5661 | tmp = NULL; |
| 5662 | } else { |
| 5663 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 5664 | return 1; |
| 5665 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5666 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5667 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5668 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5669 | if (tmp == NULL) goto failed; |
| 5670 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5671 | if (res != 0) goto failed; |
| 5672 | Py_XDECREF(tmp); |
| 5673 | tmp = NULL; |
| 5674 | } else { |
| 5675 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 5676 | return 1; |
| 5677 | } |
| 5678 | *out = Attribute(value, attr, ctx, lineno, col_offset, arena); |
| 5679 | if (*out == NULL) goto failed; |
| 5680 | return 0; |
| 5681 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5682 | isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type); |
| 5683 | if (isinstance == -1) { |
| 5684 | return 1; |
| 5685 | } |
| 5686 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5687 | expr_ty value; |
| 5688 | slice_ty slice; |
| 5689 | expr_context_ty ctx; |
| 5690 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5691 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5692 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5693 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5694 | if (tmp == NULL) goto failed; |
| 5695 | res = obj2ast_expr(tmp, &value, arena); |
| 5696 | if (res != 0) goto failed; |
| 5697 | Py_XDECREF(tmp); |
| 5698 | tmp = NULL; |
| 5699 | } else { |
| 5700 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 5701 | return 1; |
| 5702 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5703 | if (_PyObject_HasAttrId(obj, &PyId_slice)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5704 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5705 | tmp = _PyObject_GetAttrId(obj, &PyId_slice); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5706 | if (tmp == NULL) goto failed; |
| 5707 | res = obj2ast_slice(tmp, &slice, arena); |
| 5708 | if (res != 0) goto failed; |
| 5709 | Py_XDECREF(tmp); |
| 5710 | tmp = NULL; |
| 5711 | } else { |
| 5712 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 5713 | return 1; |
| 5714 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5715 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5716 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5717 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5718 | if (tmp == NULL) goto failed; |
| 5719 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5720 | if (res != 0) goto failed; |
| 5721 | Py_XDECREF(tmp); |
| 5722 | tmp = NULL; |
| 5723 | } else { |
| 5724 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 5725 | return 1; |
| 5726 | } |
| 5727 | *out = Subscript(value, slice, ctx, lineno, col_offset, arena); |
| 5728 | if (*out == NULL) goto failed; |
| 5729 | return 0; |
| 5730 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5731 | isinstance = PyObject_IsInstance(obj, (PyObject*)Starred_type); |
| 5732 | if (isinstance == -1) { |
| 5733 | return 1; |
| 5734 | } |
| 5735 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5736 | expr_ty value; |
| 5737 | expr_context_ty ctx; |
| 5738 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5739 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5740 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5741 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5742 | if (tmp == NULL) goto failed; |
| 5743 | res = obj2ast_expr(tmp, &value, arena); |
| 5744 | if (res != 0) goto failed; |
| 5745 | Py_XDECREF(tmp); |
| 5746 | tmp = NULL; |
| 5747 | } else { |
| 5748 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 5749 | return 1; |
| 5750 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5751 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5752 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5753 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5754 | if (tmp == NULL) goto failed; |
| 5755 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5756 | if (res != 0) goto failed; |
| 5757 | Py_XDECREF(tmp); |
| 5758 | tmp = NULL; |
| 5759 | } else { |
| 5760 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 5761 | return 1; |
| 5762 | } |
| 5763 | *out = Starred(value, ctx, lineno, col_offset, arena); |
| 5764 | if (*out == NULL) goto failed; |
| 5765 | return 0; |
| 5766 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5767 | isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type); |
| 5768 | if (isinstance == -1) { |
| 5769 | return 1; |
| 5770 | } |
| 5771 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5772 | identifier id; |
| 5773 | expr_context_ty ctx; |
| 5774 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5775 | if (_PyObject_HasAttrId(obj, &PyId_id)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5776 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5777 | tmp = _PyObject_GetAttrId(obj, &PyId_id); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5778 | if (tmp == NULL) goto failed; |
| 5779 | res = obj2ast_identifier(tmp, &id, arena); |
| 5780 | if (res != 0) goto failed; |
| 5781 | Py_XDECREF(tmp); |
| 5782 | tmp = NULL; |
| 5783 | } else { |
| 5784 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 5785 | return 1; |
| 5786 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5787 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5788 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5789 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5790 | if (tmp == NULL) goto failed; |
| 5791 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5792 | if (res != 0) goto failed; |
| 5793 | Py_XDECREF(tmp); |
| 5794 | tmp = NULL; |
| 5795 | } else { |
| 5796 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 5797 | return 1; |
| 5798 | } |
| 5799 | *out = Name(id, ctx, lineno, col_offset, arena); |
| 5800 | if (*out == NULL) goto failed; |
| 5801 | return 0; |
| 5802 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5803 | isinstance = PyObject_IsInstance(obj, (PyObject*)List_type); |
| 5804 | if (isinstance == -1) { |
| 5805 | return 1; |
| 5806 | } |
| 5807 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5808 | asdl_seq* elts; |
| 5809 | expr_context_ty ctx; |
| 5810 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5811 | if (_PyObject_HasAttrId(obj, &PyId_elts)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5812 | int res; |
| 5813 | Py_ssize_t len; |
| 5814 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5815 | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5816 | if (tmp == NULL) goto failed; |
| 5817 | if (!PyList_Check(tmp)) { |
| 5818 | PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5819 | goto failed; |
| 5820 | } |
| 5821 | len = PyList_GET_SIZE(tmp); |
| 5822 | elts = asdl_seq_new(len, arena); |
| 5823 | if (elts == NULL) goto failed; |
| 5824 | for (i = 0; i < len; i++) { |
| 5825 | expr_ty value; |
| 5826 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5827 | if (res != 0) goto failed; |
| 5828 | asdl_seq_SET(elts, i, value); |
| 5829 | } |
| 5830 | Py_XDECREF(tmp); |
| 5831 | tmp = NULL; |
| 5832 | } else { |
| 5833 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 5834 | return 1; |
| 5835 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5836 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5837 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5838 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5839 | if (tmp == NULL) goto failed; |
| 5840 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5841 | if (res != 0) goto failed; |
| 5842 | Py_XDECREF(tmp); |
| 5843 | tmp = NULL; |
| 5844 | } else { |
| 5845 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 5846 | return 1; |
| 5847 | } |
| 5848 | *out = List(elts, ctx, lineno, col_offset, arena); |
| 5849 | if (*out == NULL) goto failed; |
| 5850 | return 0; |
| 5851 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5852 | isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type); |
| 5853 | if (isinstance == -1) { |
| 5854 | return 1; |
| 5855 | } |
| 5856 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5857 | asdl_seq* elts; |
| 5858 | expr_context_ty ctx; |
| 5859 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5860 | if (_PyObject_HasAttrId(obj, &PyId_elts)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5861 | int res; |
| 5862 | Py_ssize_t len; |
| 5863 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5864 | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5865 | if (tmp == NULL) goto failed; |
| 5866 | if (!PyList_Check(tmp)) { |
| 5867 | PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5868 | goto failed; |
| 5869 | } |
| 5870 | len = PyList_GET_SIZE(tmp); |
| 5871 | elts = asdl_seq_new(len, arena); |
| 5872 | if (elts == NULL) goto failed; |
| 5873 | for (i = 0; i < len; i++) { |
| 5874 | expr_ty value; |
| 5875 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5876 | if (res != 0) goto failed; |
| 5877 | asdl_seq_SET(elts, i, value); |
| 5878 | } |
| 5879 | Py_XDECREF(tmp); |
| 5880 | tmp = NULL; |
| 5881 | } else { |
| 5882 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 5883 | return 1; |
| 5884 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5885 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5886 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5887 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5888 | if (tmp == NULL) goto failed; |
| 5889 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5890 | if (res != 0) goto failed; |
| 5891 | Py_XDECREF(tmp); |
| 5892 | tmp = NULL; |
| 5893 | } else { |
| 5894 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 5895 | return 1; |
| 5896 | } |
| 5897 | *out = Tuple(elts, ctx, lineno, col_offset, arena); |
| 5898 | if (*out == NULL) goto failed; |
| 5899 | return 0; |
| 5900 | } |
| 5901 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 5902 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
| 5903 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 5904 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5905 | return 1; |
| 5906 | } |
| 5907 | |
| 5908 | int |
| 5909 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 5910 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5911 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5912 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5913 | isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); |
| 5914 | if (isinstance == -1) { |
| 5915 | return 1; |
| 5916 | } |
| 5917 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5918 | *out = Load; |
| 5919 | return 0; |
| 5920 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5921 | isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type); |
| 5922 | if (isinstance == -1) { |
| 5923 | return 1; |
| 5924 | } |
| 5925 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5926 | *out = Store; |
| 5927 | return 0; |
| 5928 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5929 | isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type); |
| 5930 | if (isinstance == -1) { |
| 5931 | return 1; |
| 5932 | } |
| 5933 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5934 | *out = Del; |
| 5935 | return 0; |
| 5936 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5937 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type); |
| 5938 | if (isinstance == -1) { |
| 5939 | return 1; |
| 5940 | } |
| 5941 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5942 | *out = AugLoad; |
| 5943 | return 0; |
| 5944 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5945 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type); |
| 5946 | if (isinstance == -1) { |
| 5947 | return 1; |
| 5948 | } |
| 5949 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5950 | *out = AugStore; |
| 5951 | return 0; |
| 5952 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5953 | isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type); |
| 5954 | if (isinstance == -1) { |
| 5955 | return 1; |
| 5956 | } |
| 5957 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5958 | *out = Param; |
| 5959 | return 0; |
| 5960 | } |
| 5961 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 5962 | 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] | 5963 | return 1; |
| 5964 | } |
| 5965 | |
| 5966 | int |
| 5967 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
| 5968 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5969 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5970 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 5971 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5972 | |
| 5973 | if (obj == Py_None) { |
| 5974 | *out = NULL; |
| 5975 | return 0; |
| 5976 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5977 | isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type); |
| 5978 | if (isinstance == -1) { |
| 5979 | return 1; |
| 5980 | } |
| 5981 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5982 | expr_ty lower; |
| 5983 | expr_ty upper; |
| 5984 | expr_ty step; |
| 5985 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5986 | if (_PyObject_HasAttrId(obj, &PyId_lower)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5987 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5988 | tmp = _PyObject_GetAttrId(obj, &PyId_lower); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5989 | if (tmp == NULL) goto failed; |
| 5990 | res = obj2ast_expr(tmp, &lower, arena); |
| 5991 | if (res != 0) goto failed; |
| 5992 | Py_XDECREF(tmp); |
| 5993 | tmp = NULL; |
| 5994 | } else { |
| 5995 | lower = NULL; |
| 5996 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5997 | if (_PyObject_HasAttrId(obj, &PyId_upper)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5998 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5999 | tmp = _PyObject_GetAttrId(obj, &PyId_upper); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6000 | if (tmp == NULL) goto failed; |
| 6001 | res = obj2ast_expr(tmp, &upper, arena); |
| 6002 | if (res != 0) goto failed; |
| 6003 | Py_XDECREF(tmp); |
| 6004 | tmp = NULL; |
| 6005 | } else { |
| 6006 | upper = NULL; |
| 6007 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6008 | if (_PyObject_HasAttrId(obj, &PyId_step)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6009 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6010 | tmp = _PyObject_GetAttrId(obj, &PyId_step); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6011 | if (tmp == NULL) goto failed; |
| 6012 | res = obj2ast_expr(tmp, &step, arena); |
| 6013 | if (res != 0) goto failed; |
| 6014 | Py_XDECREF(tmp); |
| 6015 | tmp = NULL; |
| 6016 | } else { |
| 6017 | step = NULL; |
| 6018 | } |
| 6019 | *out = Slice(lower, upper, step, arena); |
| 6020 | if (*out == NULL) goto failed; |
| 6021 | return 0; |
| 6022 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6023 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type); |
| 6024 | if (isinstance == -1) { |
| 6025 | return 1; |
| 6026 | } |
| 6027 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6028 | asdl_seq* dims; |
| 6029 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6030 | if (_PyObject_HasAttrId(obj, &PyId_dims)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6031 | int res; |
| 6032 | Py_ssize_t len; |
| 6033 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6034 | tmp = _PyObject_GetAttrId(obj, &PyId_dims); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6035 | if (tmp == NULL) goto failed; |
| 6036 | if (!PyList_Check(tmp)) { |
| 6037 | PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6038 | goto failed; |
| 6039 | } |
| 6040 | len = PyList_GET_SIZE(tmp); |
| 6041 | dims = asdl_seq_new(len, arena); |
| 6042 | if (dims == NULL) goto failed; |
| 6043 | for (i = 0; i < len; i++) { |
| 6044 | slice_ty value; |
| 6045 | res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6046 | if (res != 0) goto failed; |
| 6047 | asdl_seq_SET(dims, i, value); |
| 6048 | } |
| 6049 | Py_XDECREF(tmp); |
| 6050 | tmp = NULL; |
| 6051 | } else { |
| 6052 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
| 6053 | return 1; |
| 6054 | } |
| 6055 | *out = ExtSlice(dims, arena); |
| 6056 | if (*out == NULL) goto failed; |
| 6057 | return 0; |
| 6058 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6059 | isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type); |
| 6060 | if (isinstance == -1) { |
| 6061 | return 1; |
| 6062 | } |
| 6063 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6064 | expr_ty value; |
| 6065 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6066 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6067 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6068 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6069 | if (tmp == NULL) goto failed; |
| 6070 | res = obj2ast_expr(tmp, &value, arena); |
| 6071 | if (res != 0) goto failed; |
| 6072 | Py_XDECREF(tmp); |
| 6073 | tmp = NULL; |
| 6074 | } else { |
| 6075 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
| 6076 | return 1; |
| 6077 | } |
| 6078 | *out = Index(value, arena); |
| 6079 | if (*out == NULL) goto failed; |
| 6080 | return 0; |
| 6081 | } |
| 6082 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6083 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj); |
| 6084 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 6085 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6086 | return 1; |
| 6087 | } |
| 6088 | |
| 6089 | int |
| 6090 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 6091 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6092 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6093 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6094 | isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); |
| 6095 | if (isinstance == -1) { |
| 6096 | return 1; |
| 6097 | } |
| 6098 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6099 | *out = And; |
| 6100 | return 0; |
| 6101 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6102 | isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type); |
| 6103 | if (isinstance == -1) { |
| 6104 | return 1; |
| 6105 | } |
| 6106 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6107 | *out = Or; |
| 6108 | return 0; |
| 6109 | } |
| 6110 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6111 | 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] | 6112 | return 1; |
| 6113 | } |
| 6114 | |
| 6115 | int |
| 6116 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 6117 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6118 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6119 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6120 | isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); |
| 6121 | if (isinstance == -1) { |
| 6122 | return 1; |
| 6123 | } |
| 6124 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6125 | *out = Add; |
| 6126 | return 0; |
| 6127 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6128 | isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type); |
| 6129 | if (isinstance == -1) { |
| 6130 | return 1; |
| 6131 | } |
| 6132 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6133 | *out = Sub; |
| 6134 | return 0; |
| 6135 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6136 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type); |
| 6137 | if (isinstance == -1) { |
| 6138 | return 1; |
| 6139 | } |
| 6140 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6141 | *out = Mult; |
| 6142 | return 0; |
| 6143 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6144 | isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type); |
| 6145 | if (isinstance == -1) { |
| 6146 | return 1; |
| 6147 | } |
| 6148 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6149 | *out = Div; |
| 6150 | return 0; |
| 6151 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6152 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type); |
| 6153 | if (isinstance == -1) { |
| 6154 | return 1; |
| 6155 | } |
| 6156 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6157 | *out = Mod; |
| 6158 | return 0; |
| 6159 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6160 | isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type); |
| 6161 | if (isinstance == -1) { |
| 6162 | return 1; |
| 6163 | } |
| 6164 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6165 | *out = Pow; |
| 6166 | return 0; |
| 6167 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6168 | isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type); |
| 6169 | if (isinstance == -1) { |
| 6170 | return 1; |
| 6171 | } |
| 6172 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6173 | *out = LShift; |
| 6174 | return 0; |
| 6175 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6176 | isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type); |
| 6177 | if (isinstance == -1) { |
| 6178 | return 1; |
| 6179 | } |
| 6180 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6181 | *out = RShift; |
| 6182 | return 0; |
| 6183 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6184 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type); |
| 6185 | if (isinstance == -1) { |
| 6186 | return 1; |
| 6187 | } |
| 6188 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6189 | *out = BitOr; |
| 6190 | return 0; |
| 6191 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6192 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type); |
| 6193 | if (isinstance == -1) { |
| 6194 | return 1; |
| 6195 | } |
| 6196 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6197 | *out = BitXor; |
| 6198 | return 0; |
| 6199 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6200 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type); |
| 6201 | if (isinstance == -1) { |
| 6202 | return 1; |
| 6203 | } |
| 6204 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6205 | *out = BitAnd; |
| 6206 | return 0; |
| 6207 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6208 | isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type); |
| 6209 | if (isinstance == -1) { |
| 6210 | return 1; |
| 6211 | } |
| 6212 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6213 | *out = FloorDiv; |
| 6214 | return 0; |
| 6215 | } |
| 6216 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6217 | 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] | 6218 | return 1; |
| 6219 | } |
| 6220 | |
| 6221 | int |
| 6222 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 6223 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6224 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6225 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6226 | isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); |
| 6227 | if (isinstance == -1) { |
| 6228 | return 1; |
| 6229 | } |
| 6230 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6231 | *out = Invert; |
| 6232 | return 0; |
| 6233 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6234 | isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type); |
| 6235 | if (isinstance == -1) { |
| 6236 | return 1; |
| 6237 | } |
| 6238 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6239 | *out = Not; |
| 6240 | return 0; |
| 6241 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6242 | isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type); |
| 6243 | if (isinstance == -1) { |
| 6244 | return 1; |
| 6245 | } |
| 6246 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6247 | *out = UAdd; |
| 6248 | return 0; |
| 6249 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6250 | isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type); |
| 6251 | if (isinstance == -1) { |
| 6252 | return 1; |
| 6253 | } |
| 6254 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6255 | *out = USub; |
| 6256 | return 0; |
| 6257 | } |
| 6258 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6259 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6260 | return 1; |
| 6261 | } |
| 6262 | |
| 6263 | int |
| 6264 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 6265 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6266 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6267 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6268 | isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); |
| 6269 | if (isinstance == -1) { |
| 6270 | return 1; |
| 6271 | } |
| 6272 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6273 | *out = Eq; |
| 6274 | return 0; |
| 6275 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6276 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type); |
| 6277 | if (isinstance == -1) { |
| 6278 | return 1; |
| 6279 | } |
| 6280 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6281 | *out = NotEq; |
| 6282 | return 0; |
| 6283 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6284 | isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type); |
| 6285 | if (isinstance == -1) { |
| 6286 | return 1; |
| 6287 | } |
| 6288 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6289 | *out = Lt; |
| 6290 | return 0; |
| 6291 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6292 | isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type); |
| 6293 | if (isinstance == -1) { |
| 6294 | return 1; |
| 6295 | } |
| 6296 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6297 | *out = LtE; |
| 6298 | return 0; |
| 6299 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6300 | isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type); |
| 6301 | if (isinstance == -1) { |
| 6302 | return 1; |
| 6303 | } |
| 6304 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6305 | *out = Gt; |
| 6306 | return 0; |
| 6307 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6308 | isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type); |
| 6309 | if (isinstance == -1) { |
| 6310 | return 1; |
| 6311 | } |
| 6312 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6313 | *out = GtE; |
| 6314 | return 0; |
| 6315 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6316 | isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type); |
| 6317 | if (isinstance == -1) { |
| 6318 | return 1; |
| 6319 | } |
| 6320 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6321 | *out = Is; |
| 6322 | return 0; |
| 6323 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6324 | isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type); |
| 6325 | if (isinstance == -1) { |
| 6326 | return 1; |
| 6327 | } |
| 6328 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6329 | *out = IsNot; |
| 6330 | return 0; |
| 6331 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6332 | isinstance = PyObject_IsInstance(obj, (PyObject *)In_type); |
| 6333 | if (isinstance == -1) { |
| 6334 | return 1; |
| 6335 | } |
| 6336 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6337 | *out = In; |
| 6338 | return 0; |
| 6339 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6340 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type); |
| 6341 | if (isinstance == -1) { |
| 6342 | return 1; |
| 6343 | } |
| 6344 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6345 | *out = NotIn; |
| 6346 | return 0; |
| 6347 | } |
| 6348 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6349 | 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] | 6350 | return 1; |
| 6351 | } |
| 6352 | |
| 6353 | int |
| 6354 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 6355 | { |
| 6356 | PyObject* tmp = NULL; |
| 6357 | expr_ty target; |
| 6358 | expr_ty iter; |
| 6359 | asdl_seq* ifs; |
| 6360 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6361 | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6362 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6363 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6364 | if (tmp == NULL) goto failed; |
| 6365 | res = obj2ast_expr(tmp, &target, arena); |
| 6366 | if (res != 0) goto failed; |
| 6367 | Py_XDECREF(tmp); |
| 6368 | tmp = NULL; |
| 6369 | } else { |
| 6370 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 6371 | return 1; |
| 6372 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6373 | if (_PyObject_HasAttrId(obj, &PyId_iter)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6374 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6375 | tmp = _PyObject_GetAttrId(obj, &PyId_iter); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6376 | if (tmp == NULL) goto failed; |
| 6377 | res = obj2ast_expr(tmp, &iter, arena); |
| 6378 | if (res != 0) goto failed; |
| 6379 | Py_XDECREF(tmp); |
| 6380 | tmp = NULL; |
| 6381 | } else { |
| 6382 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 6383 | return 1; |
| 6384 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6385 | if (_PyObject_HasAttrId(obj, &PyId_ifs)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6386 | int res; |
| 6387 | Py_ssize_t len; |
| 6388 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6389 | tmp = _PyObject_GetAttrId(obj, &PyId_ifs); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6390 | if (tmp == NULL) goto failed; |
| 6391 | if (!PyList_Check(tmp)) { |
| 6392 | PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6393 | goto failed; |
| 6394 | } |
| 6395 | len = PyList_GET_SIZE(tmp); |
| 6396 | ifs = asdl_seq_new(len, arena); |
| 6397 | if (ifs == NULL) goto failed; |
| 6398 | for (i = 0; i < len; i++) { |
| 6399 | expr_ty value; |
| 6400 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6401 | if (res != 0) goto failed; |
| 6402 | asdl_seq_SET(ifs, i, value); |
| 6403 | } |
| 6404 | Py_XDECREF(tmp); |
| 6405 | tmp = NULL; |
| 6406 | } else { |
| 6407 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 6408 | return 1; |
| 6409 | } |
| 6410 | *out = comprehension(target, iter, ifs, arena); |
| 6411 | return 0; |
| 6412 | failed: |
| 6413 | Py_XDECREF(tmp); |
| 6414 | return 1; |
| 6415 | } |
| 6416 | |
| 6417 | int |
| 6418 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 6419 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6420 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6421 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 6422 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6423 | int lineno; |
| 6424 | int col_offset; |
| 6425 | |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6426 | if (obj == Py_None) { |
| 6427 | *out = NULL; |
| 6428 | return 0; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6429 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6430 | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6431 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6432 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6433 | if (tmp == NULL) goto failed; |
| 6434 | res = obj2ast_int(tmp, &lineno, arena); |
| 6435 | if (res != 0) goto failed; |
| 6436 | Py_XDECREF(tmp); |
| 6437 | tmp = NULL; |
| 6438 | } else { |
| 6439 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 6440 | return 1; |
| 6441 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6442 | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +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_col_offset); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6445 | if (tmp == NULL) goto failed; |
| 6446 | res = obj2ast_int(tmp, &col_offset, arena); |
| 6447 | if (res != 0) goto failed; |
| 6448 | Py_XDECREF(tmp); |
| 6449 | tmp = NULL; |
| 6450 | } else { |
| 6451 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 6452 | return 1; |
| 6453 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6454 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type); |
| 6455 | if (isinstance == -1) { |
| 6456 | return 1; |
| 6457 | } |
| 6458 | if (isinstance) { |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6459 | expr_ty type; |
| 6460 | identifier name; |
| 6461 | asdl_seq* body; |
| 6462 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6463 | if (_PyObject_HasAttrId(obj, &PyId_type)) { |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6464 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6465 | tmp = _PyObject_GetAttrId(obj, &PyId_type); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6466 | if (tmp == NULL) goto failed; |
| 6467 | res = obj2ast_expr(tmp, &type, arena); |
| 6468 | if (res != 0) goto failed; |
| 6469 | Py_XDECREF(tmp); |
| 6470 | tmp = NULL; |
| 6471 | } else { |
| 6472 | type = NULL; |
| 6473 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6474 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6475 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6476 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6477 | if (tmp == NULL) goto failed; |
| 6478 | res = obj2ast_identifier(tmp, &name, arena); |
| 6479 | if (res != 0) goto failed; |
| 6480 | Py_XDECREF(tmp); |
| 6481 | tmp = NULL; |
| 6482 | } else { |
| 6483 | name = NULL; |
| 6484 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6485 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6486 | int res; |
| 6487 | Py_ssize_t len; |
| 6488 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6489 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6490 | if (tmp == NULL) goto failed; |
| 6491 | if (!PyList_Check(tmp)) { |
| 6492 | PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6493 | goto failed; |
| 6494 | } |
| 6495 | len = PyList_GET_SIZE(tmp); |
| 6496 | body = asdl_seq_new(len, arena); |
| 6497 | if (body == NULL) goto failed; |
| 6498 | for (i = 0; i < len; i++) { |
| 6499 | stmt_ty value; |
| 6500 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6501 | if (res != 0) goto failed; |
| 6502 | asdl_seq_SET(body, i, value); |
| 6503 | } |
| 6504 | Py_XDECREF(tmp); |
| 6505 | tmp = NULL; |
| 6506 | } else { |
| 6507 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 6508 | return 1; |
| 6509 | } |
| 6510 | *out = ExceptHandler(type, name, body, lineno, col_offset, |
| 6511 | arena); |
| 6512 | if (*out == NULL) goto failed; |
| 6513 | return 0; |
| 6514 | } |
| 6515 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6516 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
| 6517 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 6518 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6519 | return 1; |
| 6520 | } |
| 6521 | |
| 6522 | int |
| 6523 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 6524 | { |
| 6525 | PyObject* tmp = NULL; |
| 6526 | asdl_seq* args; |
| 6527 | identifier vararg; |
| 6528 | expr_ty varargannotation; |
| 6529 | asdl_seq* kwonlyargs; |
| 6530 | identifier kwarg; |
| 6531 | expr_ty kwargannotation; |
| 6532 | asdl_seq* defaults; |
| 6533 | asdl_seq* kw_defaults; |
| 6534 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6535 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6536 | int res; |
| 6537 | Py_ssize_t len; |
| 6538 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6539 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6540 | if (tmp == NULL) goto failed; |
| 6541 | if (!PyList_Check(tmp)) { |
| 6542 | PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6543 | goto failed; |
| 6544 | } |
| 6545 | len = PyList_GET_SIZE(tmp); |
| 6546 | args = asdl_seq_new(len, arena); |
| 6547 | if (args == NULL) goto failed; |
| 6548 | for (i = 0; i < len; i++) { |
| 6549 | arg_ty value; |
| 6550 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6551 | if (res != 0) goto failed; |
| 6552 | asdl_seq_SET(args, i, value); |
| 6553 | } |
| 6554 | Py_XDECREF(tmp); |
| 6555 | tmp = NULL; |
| 6556 | } else { |
| 6557 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 6558 | return 1; |
| 6559 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6560 | if (_PyObject_HasAttrId(obj, &PyId_vararg)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6561 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6562 | tmp = _PyObject_GetAttrId(obj, &PyId_vararg); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6563 | if (tmp == NULL) goto failed; |
| 6564 | res = obj2ast_identifier(tmp, &vararg, arena); |
| 6565 | if (res != 0) goto failed; |
| 6566 | Py_XDECREF(tmp); |
| 6567 | tmp = NULL; |
| 6568 | } else { |
| 6569 | vararg = NULL; |
| 6570 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6571 | if (_PyObject_HasAttrId(obj, &PyId_varargannotation)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6572 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6573 | tmp = _PyObject_GetAttrId(obj, &PyId_varargannotation); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6574 | if (tmp == NULL) goto failed; |
| 6575 | res = obj2ast_expr(tmp, &varargannotation, arena); |
| 6576 | if (res != 0) goto failed; |
| 6577 | Py_XDECREF(tmp); |
| 6578 | tmp = NULL; |
| 6579 | } else { |
| 6580 | varargannotation = NULL; |
| 6581 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6582 | if (_PyObject_HasAttrId(obj, &PyId_kwonlyargs)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6583 | int res; |
| 6584 | Py_ssize_t len; |
| 6585 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6586 | tmp = _PyObject_GetAttrId(obj, &PyId_kwonlyargs); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6587 | if (tmp == NULL) goto failed; |
| 6588 | if (!PyList_Check(tmp)) { |
| 6589 | PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6590 | goto failed; |
| 6591 | } |
| 6592 | len = PyList_GET_SIZE(tmp); |
| 6593 | kwonlyargs = asdl_seq_new(len, arena); |
| 6594 | if (kwonlyargs == NULL) goto failed; |
| 6595 | for (i = 0; i < len; i++) { |
| 6596 | arg_ty value; |
| 6597 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6598 | if (res != 0) goto failed; |
| 6599 | asdl_seq_SET(kwonlyargs, i, value); |
| 6600 | } |
| 6601 | Py_XDECREF(tmp); |
| 6602 | tmp = NULL; |
| 6603 | } else { |
| 6604 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 6605 | return 1; |
| 6606 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6607 | if (_PyObject_HasAttrId(obj, &PyId_kwarg)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6608 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6609 | tmp = _PyObject_GetAttrId(obj, &PyId_kwarg); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6610 | if (tmp == NULL) goto failed; |
| 6611 | res = obj2ast_identifier(tmp, &kwarg, arena); |
| 6612 | if (res != 0) goto failed; |
| 6613 | Py_XDECREF(tmp); |
| 6614 | tmp = NULL; |
| 6615 | } else { |
| 6616 | kwarg = NULL; |
| 6617 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6618 | if (_PyObject_HasAttrId(obj, &PyId_kwargannotation)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6619 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6620 | tmp = _PyObject_GetAttrId(obj, &PyId_kwargannotation); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6621 | if (tmp == NULL) goto failed; |
| 6622 | res = obj2ast_expr(tmp, &kwargannotation, arena); |
| 6623 | if (res != 0) goto failed; |
| 6624 | Py_XDECREF(tmp); |
| 6625 | tmp = NULL; |
| 6626 | } else { |
| 6627 | kwargannotation = NULL; |
| 6628 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6629 | if (_PyObject_HasAttrId(obj, &PyId_defaults)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6630 | int res; |
| 6631 | Py_ssize_t len; |
| 6632 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6633 | tmp = _PyObject_GetAttrId(obj, &PyId_defaults); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6634 | if (tmp == NULL) goto failed; |
| 6635 | if (!PyList_Check(tmp)) { |
| 6636 | PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6637 | goto failed; |
| 6638 | } |
| 6639 | len = PyList_GET_SIZE(tmp); |
| 6640 | defaults = asdl_seq_new(len, arena); |
| 6641 | if (defaults == NULL) goto failed; |
| 6642 | for (i = 0; i < len; i++) { |
| 6643 | expr_ty value; |
| 6644 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6645 | if (res != 0) goto failed; |
| 6646 | asdl_seq_SET(defaults, i, value); |
| 6647 | } |
| 6648 | Py_XDECREF(tmp); |
| 6649 | tmp = NULL; |
| 6650 | } else { |
| 6651 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 6652 | return 1; |
| 6653 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6654 | if (_PyObject_HasAttrId(obj, &PyId_kw_defaults)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6655 | int res; |
| 6656 | Py_ssize_t len; |
| 6657 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6658 | tmp = _PyObject_GetAttrId(obj, &PyId_kw_defaults); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6659 | if (tmp == NULL) goto failed; |
| 6660 | if (!PyList_Check(tmp)) { |
| 6661 | PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6662 | goto failed; |
| 6663 | } |
| 6664 | len = PyList_GET_SIZE(tmp); |
| 6665 | kw_defaults = asdl_seq_new(len, arena); |
| 6666 | if (kw_defaults == NULL) goto failed; |
| 6667 | for (i = 0; i < len; i++) { |
| 6668 | expr_ty value; |
| 6669 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6670 | if (res != 0) goto failed; |
| 6671 | asdl_seq_SET(kw_defaults, i, value); |
| 6672 | } |
| 6673 | Py_XDECREF(tmp); |
| 6674 | tmp = NULL; |
| 6675 | } else { |
| 6676 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 6677 | return 1; |
| 6678 | } |
| 6679 | *out = arguments(args, vararg, varargannotation, kwonlyargs, kwarg, |
| 6680 | kwargannotation, defaults, kw_defaults, arena); |
| 6681 | return 0; |
| 6682 | failed: |
| 6683 | Py_XDECREF(tmp); |
| 6684 | return 1; |
| 6685 | } |
| 6686 | |
| 6687 | int |
| 6688 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 6689 | { |
| 6690 | PyObject* tmp = NULL; |
| 6691 | identifier arg; |
| 6692 | expr_ty annotation; |
| 6693 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6694 | if (_PyObject_HasAttrId(obj, &PyId_arg)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6695 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6696 | tmp = _PyObject_GetAttrId(obj, &PyId_arg); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6697 | if (tmp == NULL) goto failed; |
| 6698 | res = obj2ast_identifier(tmp, &arg, arena); |
| 6699 | if (res != 0) goto failed; |
| 6700 | Py_XDECREF(tmp); |
| 6701 | tmp = NULL; |
| 6702 | } else { |
| 6703 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
| 6704 | return 1; |
| 6705 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6706 | if (_PyObject_HasAttrId(obj, &PyId_annotation)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6707 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6708 | tmp = _PyObject_GetAttrId(obj, &PyId_annotation); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6709 | if (tmp == NULL) goto failed; |
| 6710 | res = obj2ast_expr(tmp, &annotation, arena); |
| 6711 | if (res != 0) goto failed; |
| 6712 | Py_XDECREF(tmp); |
| 6713 | tmp = NULL; |
| 6714 | } else { |
| 6715 | annotation = NULL; |
| 6716 | } |
| 6717 | *out = arg(arg, annotation, arena); |
| 6718 | return 0; |
| 6719 | failed: |
| 6720 | Py_XDECREF(tmp); |
| 6721 | return 1; |
| 6722 | } |
| 6723 | |
| 6724 | int |
| 6725 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 6726 | { |
| 6727 | PyObject* tmp = NULL; |
| 6728 | identifier arg; |
| 6729 | expr_ty value; |
| 6730 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6731 | if (_PyObject_HasAttrId(obj, &PyId_arg)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6732 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6733 | tmp = _PyObject_GetAttrId(obj, &PyId_arg); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6734 | if (tmp == NULL) goto failed; |
| 6735 | res = obj2ast_identifier(tmp, &arg, arena); |
| 6736 | if (res != 0) goto failed; |
| 6737 | Py_XDECREF(tmp); |
| 6738 | tmp = NULL; |
| 6739 | } else { |
| 6740 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from keyword"); |
| 6741 | return 1; |
| 6742 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6743 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6744 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6745 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6746 | if (tmp == NULL) goto failed; |
| 6747 | res = obj2ast_expr(tmp, &value, arena); |
| 6748 | if (res != 0) goto failed; |
| 6749 | Py_XDECREF(tmp); |
| 6750 | tmp = NULL; |
| 6751 | } else { |
| 6752 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 6753 | return 1; |
| 6754 | } |
| 6755 | *out = keyword(arg, value, arena); |
| 6756 | return 0; |
| 6757 | failed: |
| 6758 | Py_XDECREF(tmp); |
| 6759 | return 1; |
| 6760 | } |
| 6761 | |
| 6762 | int |
| 6763 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 6764 | { |
| 6765 | PyObject* tmp = NULL; |
| 6766 | identifier name; |
| 6767 | identifier asname; |
| 6768 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6769 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6770 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6771 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6772 | if (tmp == NULL) goto failed; |
| 6773 | res = obj2ast_identifier(tmp, &name, arena); |
| 6774 | if (res != 0) goto failed; |
| 6775 | Py_XDECREF(tmp); |
| 6776 | tmp = NULL; |
| 6777 | } else { |
| 6778 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 6779 | return 1; |
| 6780 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6781 | if (_PyObject_HasAttrId(obj, &PyId_asname)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6782 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6783 | tmp = _PyObject_GetAttrId(obj, &PyId_asname); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6784 | if (tmp == NULL) goto failed; |
| 6785 | res = obj2ast_identifier(tmp, &asname, arena); |
| 6786 | if (res != 0) goto failed; |
| 6787 | Py_XDECREF(tmp); |
| 6788 | tmp = NULL; |
| 6789 | } else { |
| 6790 | asname = NULL; |
| 6791 | } |
| 6792 | *out = alias(name, asname, arena); |
| 6793 | return 0; |
| 6794 | failed: |
| 6795 | Py_XDECREF(tmp); |
| 6796 | return 1; |
| 6797 | } |
| 6798 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6799 | int |
| 6800 | obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) |
| 6801 | { |
| 6802 | PyObject* tmp = NULL; |
| 6803 | expr_ty context_expr; |
| 6804 | expr_ty optional_vars; |
| 6805 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6806 | if (_PyObject_HasAttrId(obj, &PyId_context_expr)) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6807 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6808 | tmp = _PyObject_GetAttrId(obj, &PyId_context_expr); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6809 | if (tmp == NULL) goto failed; |
| 6810 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 6811 | if (res != 0) goto failed; |
| 6812 | Py_XDECREF(tmp); |
| 6813 | tmp = NULL; |
| 6814 | } else { |
| 6815 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); |
| 6816 | return 1; |
| 6817 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6818 | if (_PyObject_HasAttrId(obj, &PyId_optional_vars)) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6819 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6820 | tmp = _PyObject_GetAttrId(obj, &PyId_optional_vars); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6821 | if (tmp == NULL) goto failed; |
| 6822 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 6823 | if (res != 0) goto failed; |
| 6824 | Py_XDECREF(tmp); |
| 6825 | tmp = NULL; |
| 6826 | } else { |
| 6827 | optional_vars = NULL; |
| 6828 | } |
| 6829 | *out = withitem(context_expr, optional_vars, arena); |
| 6830 | return 0; |
| 6831 | failed: |
| 6832 | Py_XDECREF(tmp); |
| 6833 | return 1; |
| 6834 | } |
| 6835 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6836 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6837 | static struct PyModuleDef _astmodule = { |
| 6838 | PyModuleDef_HEAD_INIT, "_ast" |
| 6839 | }; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6840 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6841 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6842 | { |
| 6843 | PyObject *m, *d; |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6844 | if (!init_types()) return NULL; |
| 6845 | m = PyModule_Create(&_astmodule); |
| 6846 | if (!m) return NULL; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6847 | d = PyModule_GetDict(m); |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6848 | if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return |
| 6849 | NULL; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6850 | 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] | 6851 | return NULL; |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6852 | if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return |
| 6853 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6854 | if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6855 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6856 | if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6857 | < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6858 | if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6859 | 0) return NULL; |
| 6860 | if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return |
| 6861 | NULL; |
| 6862 | if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return |
| 6863 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6864 | if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6865 | < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6866 | if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_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, "Return", (PyObject*)Return_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, "Delete", (PyObject*)Delete_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6871 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6872 | if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6873 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6874 | if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6875 | 0) return NULL; |
| 6876 | if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return |
| 6877 | NULL; |
| 6878 | if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return |
| 6879 | NULL; |
| 6880 | if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return NULL; |
| 6881 | if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return |
| 6882 | NULL; |
| 6883 | if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return |
| 6884 | NULL; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 6885 | if (PyDict_SetItemString(d, "Try", (PyObject*)Try_type) < 0) return |
| 6886 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6887 | if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6888 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6889 | if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6890 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6891 | if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6892 | 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6893 | if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6894 | return NULL; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 6895 | if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6896 | return NULL; |
| 6897 | if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return |
| 6898 | NULL; |
| 6899 | if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return |
| 6900 | NULL; |
| 6901 | if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return |
| 6902 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6903 | if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6904 | return NULL; |
| 6905 | if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return |
| 6906 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6907 | if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6908 | return NULL; |
| 6909 | if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return |
| 6910 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6911 | if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6912 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6913 | if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6914 | return NULL; |
| 6915 | if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return |
| 6916 | NULL; |
| 6917 | if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return |
| 6918 | NULL; |
| 6919 | if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return |
| 6920 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6921 | if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6922 | return NULL; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 6923 | if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6924 | return NULL; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 6925 | if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6926 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6927 | if (PyDict_SetItemString(d, "GeneratorExp", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6928 | (PyObject*)GeneratorExp_type) < 0) return NULL; |
| 6929 | if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return |
| 6930 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6931 | if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6932 | return NULL; |
| 6933 | if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return |
| 6934 | NULL; |
| 6935 | if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return |
| 6936 | NULL; |
| 6937 | if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return |
| 6938 | NULL; |
| 6939 | if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return |
| 6940 | NULL; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 6941 | if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6942 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6943 | if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6944 | 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6945 | if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6946 | 0) return NULL; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 6947 | if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6948 | return NULL; |
| 6949 | if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return |
| 6950 | NULL; |
| 6951 | if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return |
| 6952 | NULL; |
| 6953 | if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return |
| 6954 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6955 | if (PyDict_SetItemString(d, "expr_context", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6956 | (PyObject*)expr_context_type) < 0) return NULL; |
| 6957 | if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return |
| 6958 | NULL; |
| 6959 | if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return |
| 6960 | NULL; |
| 6961 | if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return |
| 6962 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6963 | if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6964 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6965 | if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6966 | return NULL; |
| 6967 | if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return |
| 6968 | NULL; |
| 6969 | if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return |
| 6970 | NULL; |
| 6971 | if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return |
| 6972 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6973 | if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6974 | return NULL; |
| 6975 | if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return |
| 6976 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6977 | if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6978 | return NULL; |
| 6979 | if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return |
| 6980 | NULL; |
| 6981 | if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6982 | if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6983 | return NULL; |
| 6984 | if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return |
| 6985 | NULL; |
| 6986 | if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return |
| 6987 | NULL; |
| 6988 | if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return |
| 6989 | NULL; |
| 6990 | if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return |
| 6991 | NULL; |
| 6992 | if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return |
| 6993 | NULL; |
| 6994 | if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return |
| 6995 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6996 | if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6997 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6998 | if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6999 | return NULL; |
| 7000 | if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return |
| 7001 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7002 | if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7003 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7004 | if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7005 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7006 | if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7007 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7008 | if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7009 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7010 | if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7011 | return NULL; |
| 7012 | if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return |
| 7013 | NULL; |
| 7014 | if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return |
| 7015 | NULL; |
| 7016 | if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return |
| 7017 | NULL; |
| 7018 | if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return |
| 7019 | NULL; |
| 7020 | if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return NULL; |
| 7021 | if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return |
| 7022 | NULL; |
| 7023 | if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return NULL; |
| 7024 | if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return |
| 7025 | NULL; |
| 7026 | if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return NULL; |
| 7027 | if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return |
| 7028 | NULL; |
| 7029 | if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return NULL; |
| 7030 | if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return |
| 7031 | NULL; |
| 7032 | if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return NULL; |
| 7033 | if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return |
| 7034 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7035 | if (PyDict_SetItemString(d, "comprehension", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7036 | (PyObject*)comprehension_type) < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7037 | if (PyDict_SetItemString(d, "excepthandler", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7038 | (PyObject*)excepthandler_type) < 0) return NULL; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 7039 | if (PyDict_SetItemString(d, "ExceptHandler", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7040 | (PyObject*)ExceptHandler_type) < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7041 | if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7042 | 0) return NULL; |
| 7043 | if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return |
| 7044 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7045 | if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7046 | return NULL; |
| 7047 | if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return |
| 7048 | NULL; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 7049 | if (PyDict_SetItemString(d, "withitem", (PyObject*)withitem_type) < 0) |
| 7050 | return NULL; |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7051 | return m; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 7052 | } |
| 7053 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 7054 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 7055 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 7056 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 7057 | init_types(); |
| 7058 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 7059 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 7060 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7061 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 7062 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7063 | { |
| 7064 | mod_ty res; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7065 | PyObject *req_type[] = {(PyObject*)Module_type, (PyObject*)Expression_type, |
| 7066 | (PyObject*)Interactive_type}; |
| 7067 | char *req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 7068 | int isinstance; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7069 | assert(0 <= mode && mode <= 2); |
| 7070 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7071 | init_types(); |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7072 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 7073 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 7074 | if (isinstance == -1) |
| 7075 | return NULL; |
| 7076 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7077 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
| 7078 | req_name[mode], Py_TYPE(ast)->tp_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7079 | return NULL; |
| 7080 | } |
| 7081 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 7082 | return NULL; |
| 7083 | else |
| 7084 | return res; |
| 7085 | } |
| 7086 | |
| 7087 | int PyAST_Check(PyObject* obj) |
| 7088 | { |
| 7089 | init_types(); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 7090 | return PyObject_IsInstance(obj, (PyObject*)&AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7091 | } |
| 7092 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 7093 | |