Thomas Wouters | cf297e4 | 2007-02-23 15:07:44 +0000 | [diff] [blame] | 1 | /* File automatically generated by Parser/asdl_c.py. */ |
| 2 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 3 | #include <stddef.h> |
| 4 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 5 | #include "Python.h" |
| 6 | #include "Python-ast.h" |
| 7 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 8 | static PyTypeObject AST_type; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 9 | static PyTypeObject *mod_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 10 | static PyObject* ast2obj_mod(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 11 | static PyTypeObject *Module_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 12 | _Py_IDENTIFIER(body); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 13 | static char *Module_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 14 | "body", |
| 15 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 16 | static PyTypeObject *Interactive_type; |
| 17 | static char *Interactive_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 18 | "body", |
| 19 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 20 | static PyTypeObject *Expression_type; |
| 21 | static char *Expression_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 22 | "body", |
| 23 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 24 | static PyTypeObject *Suite_type; |
| 25 | static char *Suite_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 26 | "body", |
| 27 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 28 | static PyTypeObject *stmt_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 29 | _Py_IDENTIFIER(lineno); |
| 30 | _Py_IDENTIFIER(col_offset); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 31 | static char *stmt_attributes[] = { |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 32 | "lineno", |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 33 | "col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 34 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 35 | static PyObject* ast2obj_stmt(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 36 | static PyTypeObject *FunctionDef_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 37 | _Py_IDENTIFIER(name); |
| 38 | _Py_IDENTIFIER(args); |
| 39 | _Py_IDENTIFIER(decorator_list); |
| 40 | _Py_IDENTIFIER(returns); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 41 | static char *FunctionDef_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 42 | "name", |
| 43 | "args", |
| 44 | "body", |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 45 | "decorator_list", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 46 | "returns", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 47 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 48 | static PyTypeObject *ClassDef_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 49 | _Py_IDENTIFIER(bases); |
| 50 | _Py_IDENTIFIER(keywords); |
| 51 | _Py_IDENTIFIER(starargs); |
| 52 | _Py_IDENTIFIER(kwargs); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 53 | static char *ClassDef_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 54 | "name", |
| 55 | "bases", |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 56 | "keywords", |
| 57 | "starargs", |
| 58 | "kwargs", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 59 | "body", |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 60 | "decorator_list", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 61 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 62 | static PyTypeObject *Return_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 63 | _Py_IDENTIFIER(value); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 64 | static char *Return_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 65 | "value", |
| 66 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 67 | static PyTypeObject *Delete_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 68 | _Py_IDENTIFIER(targets); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 69 | static char *Delete_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 70 | "targets", |
| 71 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 72 | static PyTypeObject *Assign_type; |
| 73 | static char *Assign_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 74 | "targets", |
| 75 | "value", |
| 76 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 77 | static PyTypeObject *AugAssign_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 78 | _Py_IDENTIFIER(target); |
| 79 | _Py_IDENTIFIER(op); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 80 | static char *AugAssign_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 81 | "target", |
| 82 | "op", |
| 83 | "value", |
| 84 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 85 | static PyTypeObject *For_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 86 | _Py_IDENTIFIER(iter); |
| 87 | _Py_IDENTIFIER(orelse); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 88 | static char *For_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 89 | "target", |
| 90 | "iter", |
| 91 | "body", |
| 92 | "orelse", |
| 93 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 94 | static PyTypeObject *While_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 95 | _Py_IDENTIFIER(test); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 96 | static char *While_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 97 | "test", |
| 98 | "body", |
| 99 | "orelse", |
| 100 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 101 | static PyTypeObject *If_type; |
| 102 | static char *If_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 103 | "test", |
| 104 | "body", |
| 105 | "orelse", |
| 106 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 107 | static PyTypeObject *With_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 108 | _Py_IDENTIFIER(items); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 109 | static char *With_fields[]={ |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 110 | "items", |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 111 | "body", |
| 112 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 113 | static PyTypeObject *Raise_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 114 | _Py_IDENTIFIER(exc); |
| 115 | _Py_IDENTIFIER(cause); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 116 | static char *Raise_fields[]={ |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 117 | "exc", |
| 118 | "cause", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 119 | }; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 120 | static PyTypeObject *Try_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 121 | _Py_IDENTIFIER(handlers); |
| 122 | _Py_IDENTIFIER(finalbody); |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 123 | static char *Try_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 124 | "body", |
| 125 | "handlers", |
| 126 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 127 | "finalbody", |
| 128 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 129 | static PyTypeObject *Assert_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 130 | _Py_IDENTIFIER(msg); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 131 | static char *Assert_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 132 | "test", |
| 133 | "msg", |
| 134 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 135 | static PyTypeObject *Import_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 136 | _Py_IDENTIFIER(names); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 137 | static char *Import_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 138 | "names", |
| 139 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 140 | static PyTypeObject *ImportFrom_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 141 | _Py_IDENTIFIER(module); |
| 142 | _Py_IDENTIFIER(level); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 143 | static char *ImportFrom_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 144 | "module", |
| 145 | "names", |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 146 | "level", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 147 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 148 | static PyTypeObject *Global_type; |
| 149 | static char *Global_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 150 | "names", |
| 151 | }; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 152 | static PyTypeObject *Nonlocal_type; |
| 153 | static char *Nonlocal_fields[]={ |
| 154 | "names", |
| 155 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 156 | static PyTypeObject *Expr_type; |
| 157 | static char *Expr_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 158 | "value", |
| 159 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 160 | static PyTypeObject *Pass_type; |
| 161 | static PyTypeObject *Break_type; |
| 162 | static PyTypeObject *Continue_type; |
| 163 | static PyTypeObject *expr_type; |
| 164 | static char *expr_attributes[] = { |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 165 | "lineno", |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 166 | "col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 167 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 168 | static PyObject* ast2obj_expr(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 169 | static PyTypeObject *BoolOp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 170 | _Py_IDENTIFIER(values); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 171 | static char *BoolOp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 172 | "op", |
| 173 | "values", |
| 174 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 175 | static PyTypeObject *BinOp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 176 | _Py_IDENTIFIER(left); |
| 177 | _Py_IDENTIFIER(right); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 178 | static char *BinOp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 179 | "left", |
| 180 | "op", |
| 181 | "right", |
| 182 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 183 | static PyTypeObject *UnaryOp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 184 | _Py_IDENTIFIER(operand); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 185 | static char *UnaryOp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 186 | "op", |
| 187 | "operand", |
| 188 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 189 | static PyTypeObject *Lambda_type; |
| 190 | static char *Lambda_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 191 | "args", |
| 192 | "body", |
| 193 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 194 | static PyTypeObject *IfExp_type; |
| 195 | static char *IfExp_fields[]={ |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 196 | "test", |
| 197 | "body", |
| 198 | "orelse", |
| 199 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 200 | static PyTypeObject *Dict_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 201 | _Py_IDENTIFIER(keys); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 202 | static char *Dict_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 203 | "keys", |
| 204 | "values", |
| 205 | }; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 206 | static PyTypeObject *Set_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 207 | _Py_IDENTIFIER(elts); |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 208 | static char *Set_fields[]={ |
| 209 | "elts", |
| 210 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 211 | static PyTypeObject *ListComp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 212 | _Py_IDENTIFIER(elt); |
| 213 | _Py_IDENTIFIER(generators); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 214 | static char *ListComp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 215 | "elt", |
| 216 | "generators", |
| 217 | }; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 218 | static PyTypeObject *SetComp_type; |
| 219 | static char *SetComp_fields[]={ |
| 220 | "elt", |
| 221 | "generators", |
| 222 | }; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 223 | static PyTypeObject *DictComp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 224 | _Py_IDENTIFIER(key); |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 225 | static char *DictComp_fields[]={ |
| 226 | "key", |
| 227 | "value", |
| 228 | "generators", |
| 229 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 230 | static PyTypeObject *GeneratorExp_type; |
| 231 | static char *GeneratorExp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 232 | "elt", |
| 233 | "generators", |
| 234 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 235 | static PyTypeObject *Yield_type; |
| 236 | static char *Yield_fields[]={ |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 237 | "value", |
| 238 | }; |
| 239 | static PyTypeObject *YieldFrom_type; |
| 240 | static char *YieldFrom_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 241 | "value", |
| 242 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 243 | static PyTypeObject *Compare_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 244 | _Py_IDENTIFIER(ops); |
| 245 | _Py_IDENTIFIER(comparators); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 246 | static char *Compare_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 247 | "left", |
| 248 | "ops", |
| 249 | "comparators", |
| 250 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 251 | static PyTypeObject *Call_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 252 | _Py_IDENTIFIER(func); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 253 | static char *Call_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 254 | "func", |
| 255 | "args", |
| 256 | "keywords", |
| 257 | "starargs", |
| 258 | "kwargs", |
| 259 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 260 | static PyTypeObject *Num_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 261 | _Py_IDENTIFIER(n); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 262 | static char *Num_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 263 | "n", |
| 264 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 265 | static PyTypeObject *Str_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 266 | _Py_IDENTIFIER(s); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 267 | static char *Str_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 268 | "s", |
| 269 | }; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 270 | static PyTypeObject *Bytes_type; |
| 271 | static char *Bytes_fields[]={ |
| 272 | "s", |
| 273 | }; |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 274 | static PyTypeObject *NameConstant_type; |
| 275 | static char *NameConstant_fields[]={ |
| 276 | "value", |
| 277 | }; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 278 | static PyTypeObject *Ellipsis_type; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 279 | static PyTypeObject *Attribute_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 280 | _Py_IDENTIFIER(attr); |
| 281 | _Py_IDENTIFIER(ctx); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 282 | static char *Attribute_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 283 | "value", |
| 284 | "attr", |
| 285 | "ctx", |
| 286 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 287 | static PyTypeObject *Subscript_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 288 | _Py_IDENTIFIER(slice); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 289 | static char *Subscript_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 290 | "value", |
| 291 | "slice", |
| 292 | "ctx", |
| 293 | }; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 294 | static PyTypeObject *Starred_type; |
| 295 | static char *Starred_fields[]={ |
| 296 | "value", |
| 297 | "ctx", |
| 298 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 299 | static PyTypeObject *Name_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 300 | _Py_IDENTIFIER(id); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 301 | static char *Name_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 302 | "id", |
| 303 | "ctx", |
| 304 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 305 | static PyTypeObject *List_type; |
| 306 | static char *List_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 307 | "elts", |
| 308 | "ctx", |
| 309 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 310 | static PyTypeObject *Tuple_type; |
| 311 | static char *Tuple_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 312 | "elts", |
| 313 | "ctx", |
| 314 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 315 | static PyTypeObject *expr_context_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 316 | static PyObject *Load_singleton, *Store_singleton, *Del_singleton, |
| 317 | *AugLoad_singleton, *AugStore_singleton, *Param_singleton; |
| 318 | static PyObject* ast2obj_expr_context(expr_context_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 319 | static PyTypeObject *Load_type; |
| 320 | static PyTypeObject *Store_type; |
| 321 | static PyTypeObject *Del_type; |
| 322 | static PyTypeObject *AugLoad_type; |
| 323 | static PyTypeObject *AugStore_type; |
| 324 | static PyTypeObject *Param_type; |
| 325 | static PyTypeObject *slice_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 326 | static PyObject* ast2obj_slice(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 327 | static PyTypeObject *Slice_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 328 | _Py_IDENTIFIER(lower); |
| 329 | _Py_IDENTIFIER(upper); |
| 330 | _Py_IDENTIFIER(step); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 331 | static char *Slice_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 332 | "lower", |
| 333 | "upper", |
| 334 | "step", |
| 335 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 336 | static PyTypeObject *ExtSlice_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 337 | _Py_IDENTIFIER(dims); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 338 | static char *ExtSlice_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 339 | "dims", |
| 340 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 341 | static PyTypeObject *Index_type; |
| 342 | static char *Index_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 343 | "value", |
| 344 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 345 | static PyTypeObject *boolop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 346 | static PyObject *And_singleton, *Or_singleton; |
| 347 | static PyObject* ast2obj_boolop(boolop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 348 | static PyTypeObject *And_type; |
| 349 | static PyTypeObject *Or_type; |
| 350 | static PyTypeObject *operator_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 351 | static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton, |
| 352 | *Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton, |
| 353 | *RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton, |
| 354 | *FloorDiv_singleton; |
| 355 | static PyObject* ast2obj_operator(operator_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 356 | static PyTypeObject *Add_type; |
| 357 | static PyTypeObject *Sub_type; |
| 358 | static PyTypeObject *Mult_type; |
| 359 | static PyTypeObject *Div_type; |
| 360 | static PyTypeObject *Mod_type; |
| 361 | static PyTypeObject *Pow_type; |
| 362 | static PyTypeObject *LShift_type; |
| 363 | static PyTypeObject *RShift_type; |
| 364 | static PyTypeObject *BitOr_type; |
| 365 | static PyTypeObject *BitXor_type; |
| 366 | static PyTypeObject *BitAnd_type; |
| 367 | static PyTypeObject *FloorDiv_type; |
| 368 | static PyTypeObject *unaryop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 369 | static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton, |
| 370 | *USub_singleton; |
| 371 | static PyObject* ast2obj_unaryop(unaryop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 372 | static PyTypeObject *Invert_type; |
| 373 | static PyTypeObject *Not_type; |
| 374 | static PyTypeObject *UAdd_type; |
| 375 | static PyTypeObject *USub_type; |
| 376 | static PyTypeObject *cmpop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 377 | static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton, |
| 378 | *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton, |
| 379 | *NotIn_singleton; |
| 380 | static PyObject* ast2obj_cmpop(cmpop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 381 | static PyTypeObject *Eq_type; |
| 382 | static PyTypeObject *NotEq_type; |
| 383 | static PyTypeObject *Lt_type; |
| 384 | static PyTypeObject *LtE_type; |
| 385 | static PyTypeObject *Gt_type; |
| 386 | static PyTypeObject *GtE_type; |
| 387 | static PyTypeObject *Is_type; |
| 388 | static PyTypeObject *IsNot_type; |
| 389 | static PyTypeObject *In_type; |
| 390 | static PyTypeObject *NotIn_type; |
| 391 | static PyTypeObject *comprehension_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 392 | static PyObject* ast2obj_comprehension(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 393 | _Py_IDENTIFIER(ifs); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 394 | static char *comprehension_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 395 | "target", |
| 396 | "iter", |
| 397 | "ifs", |
| 398 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 399 | static PyTypeObject *excepthandler_type; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 400 | static char *excepthandler_attributes[] = { |
| 401 | "lineno", |
| 402 | "col_offset", |
| 403 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 404 | static PyObject* ast2obj_excepthandler(void*); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 405 | static PyTypeObject *ExceptHandler_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 406 | _Py_IDENTIFIER(type); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 407 | static char *ExceptHandler_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 408 | "type", |
| 409 | "name", |
| 410 | "body", |
| 411 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 412 | static PyTypeObject *arguments_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 413 | static PyObject* ast2obj_arguments(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 414 | _Py_IDENTIFIER(vararg); |
| 415 | _Py_IDENTIFIER(varargannotation); |
| 416 | _Py_IDENTIFIER(kwonlyargs); |
| 417 | _Py_IDENTIFIER(kwarg); |
| 418 | _Py_IDENTIFIER(kwargannotation); |
| 419 | _Py_IDENTIFIER(defaults); |
| 420 | _Py_IDENTIFIER(kw_defaults); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 421 | static char *arguments_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 422 | "args", |
| 423 | "vararg", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 424 | "varargannotation", |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 425 | "kwonlyargs", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 426 | "kwarg", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 427 | "kwargannotation", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 428 | "defaults", |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 429 | "kw_defaults", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 430 | }; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 431 | static PyTypeObject *arg_type; |
| 432 | static PyObject* ast2obj_arg(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 433 | _Py_IDENTIFIER(arg); |
| 434 | _Py_IDENTIFIER(annotation); |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 435 | static char *arg_fields[]={ |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 436 | "arg", |
| 437 | "annotation", |
| 438 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 439 | static PyTypeObject *keyword_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 440 | static PyObject* ast2obj_keyword(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 441 | static char *keyword_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 442 | "arg", |
| 443 | "value", |
| 444 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 445 | static PyTypeObject *alias_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 446 | static PyObject* ast2obj_alias(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 447 | _Py_IDENTIFIER(asname); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 448 | static char *alias_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 449 | "name", |
| 450 | "asname", |
| 451 | }; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 452 | static PyTypeObject *withitem_type; |
| 453 | static PyObject* ast2obj_withitem(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 454 | _Py_IDENTIFIER(context_expr); |
| 455 | _Py_IDENTIFIER(optional_vars); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 456 | static char *withitem_fields[]={ |
| 457 | "context_expr", |
| 458 | "optional_vars", |
| 459 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 460 | |
| 461 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 462 | typedef struct { |
Victor Stinner | 45e50de | 2012-03-13 01:17:31 +0100 | [diff] [blame] | 463 | PyObject_HEAD |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 464 | PyObject *dict; |
| 465 | } AST_object; |
| 466 | |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 467 | static void |
| 468 | ast_dealloc(AST_object *self) |
| 469 | { |
| 470 | Py_CLEAR(self->dict); |
Antoine Pitrou | 5075074 | 2012-07-08 12:43:32 +0200 | [diff] [blame] | 471 | Py_TYPE(self)->tp_free(self); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 472 | } |
| 473 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 474 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 475 | ast_traverse(AST_object *self, visitproc visit, void *arg) |
| 476 | { |
| 477 | Py_VISIT(self->dict); |
| 478 | return 0; |
| 479 | } |
| 480 | |
| 481 | static void |
| 482 | ast_clear(AST_object *self) |
| 483 | { |
| 484 | Py_CLEAR(self->dict); |
| 485 | } |
| 486 | |
| 487 | static int |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 488 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 489 | { |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 490 | _Py_IDENTIFIER(_fields); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 491 | Py_ssize_t i, numfields = 0; |
| 492 | int res = -1; |
| 493 | PyObject *key, *value, *fields; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 494 | fields = _PyObject_GetAttrId((PyObject*)Py_TYPE(self), &PyId__fields); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 495 | if (!fields) |
| 496 | PyErr_Clear(); |
| 497 | if (fields) { |
| 498 | numfields = PySequence_Size(fields); |
| 499 | if (numfields == -1) |
| 500 | goto cleanup; |
| 501 | } |
| 502 | res = 0; /* if no error occurs, this stays 0 to the end */ |
| 503 | if (PyTuple_GET_SIZE(args) > 0) { |
| 504 | if (numfields != PyTuple_GET_SIZE(args)) { |
| 505 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes %s" |
Amaury Forgeot d'Arc | 245c70b | 2008-09-10 22:24:24 +0000 | [diff] [blame] | 506 | "%zd positional argument%s", |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 507 | Py_TYPE(self)->tp_name, |
| 508 | numfields == 0 ? "" : "either 0 or ", |
| 509 | numfields, numfields == 1 ? "" : "s"); |
| 510 | res = -1; |
| 511 | goto cleanup; |
| 512 | } |
| 513 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
| 514 | /* cannot be reached when fields is NULL */ |
| 515 | PyObject *name = PySequence_GetItem(fields, i); |
| 516 | if (!name) { |
| 517 | res = -1; |
| 518 | goto cleanup; |
| 519 | } |
| 520 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
| 521 | Py_DECREF(name); |
| 522 | if (res < 0) |
| 523 | goto cleanup; |
| 524 | } |
| 525 | } |
| 526 | if (kw) { |
| 527 | i = 0; /* needed by PyDict_Next */ |
| 528 | while (PyDict_Next(kw, &i, &key, &value)) { |
| 529 | res = PyObject_SetAttr(self, key, value); |
| 530 | if (res < 0) |
| 531 | goto cleanup; |
| 532 | } |
| 533 | } |
| 534 | cleanup: |
| 535 | Py_XDECREF(fields); |
| 536 | return res; |
| 537 | } |
| 538 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 539 | /* Pickling support */ |
| 540 | static PyObject * |
| 541 | ast_type_reduce(PyObject *self, PyObject *unused) |
| 542 | { |
| 543 | PyObject *res; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 544 | _Py_IDENTIFIER(__dict__); |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 545 | PyObject *dict = _PyObject_GetAttrId(self, &PyId___dict__); |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 546 | if (dict == NULL) { |
| 547 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) |
| 548 | PyErr_Clear(); |
| 549 | else |
| 550 | return NULL; |
| 551 | } |
| 552 | if (dict) { |
| 553 | res = Py_BuildValue("O()O", Py_TYPE(self), dict); |
| 554 | Py_DECREF(dict); |
| 555 | return res; |
| 556 | } |
| 557 | return Py_BuildValue("O()", Py_TYPE(self)); |
| 558 | } |
| 559 | |
| 560 | static PyMethodDef ast_type_methods[] = { |
| 561 | {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, |
| 562 | {NULL} |
| 563 | }; |
| 564 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 565 | static PyGetSetDef ast_type_getsets[] = { |
| 566 | {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict}, |
| 567 | {NULL} |
| 568 | }; |
| 569 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 570 | static PyTypeObject AST_type = { |
| 571 | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 572 | "_ast.AST", |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 573 | sizeof(AST_object), |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 574 | 0, |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 575 | (destructor)ast_dealloc, /* tp_dealloc */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 576 | 0, /* tp_print */ |
| 577 | 0, /* tp_getattr */ |
| 578 | 0, /* tp_setattr */ |
Mark Dickinson | e94c679 | 2009-02-02 20:36:42 +0000 | [diff] [blame] | 579 | 0, /* tp_reserved */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 580 | 0, /* tp_repr */ |
| 581 | 0, /* tp_as_number */ |
| 582 | 0, /* tp_as_sequence */ |
| 583 | 0, /* tp_as_mapping */ |
| 584 | 0, /* tp_hash */ |
| 585 | 0, /* tp_call */ |
| 586 | 0, /* tp_str */ |
| 587 | PyObject_GenericGetAttr, /* tp_getattro */ |
| 588 | PyObject_GenericSetAttr, /* tp_setattro */ |
| 589 | 0, /* tp_as_buffer */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 590 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 591 | 0, /* tp_doc */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 592 | (traverseproc)ast_traverse, /* tp_traverse */ |
| 593 | (inquiry)ast_clear, /* tp_clear */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 594 | 0, /* tp_richcompare */ |
| 595 | 0, /* tp_weaklistoffset */ |
| 596 | 0, /* tp_iter */ |
| 597 | 0, /* tp_iternext */ |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 598 | ast_type_methods, /* tp_methods */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 599 | 0, /* tp_members */ |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 600 | ast_type_getsets, /* tp_getset */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 601 | 0, /* tp_base */ |
| 602 | 0, /* tp_dict */ |
| 603 | 0, /* tp_descr_get */ |
| 604 | 0, /* tp_descr_set */ |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 605 | offsetof(AST_object, dict),/* tp_dictoffset */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 606 | (initproc)ast_type_init, /* tp_init */ |
| 607 | PyType_GenericAlloc, /* tp_alloc */ |
| 608 | PyType_GenericNew, /* tp_new */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 609 | PyObject_GC_Del, /* tp_free */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 610 | }; |
| 611 | |
| 612 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 613 | static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields) |
| 614 | { |
| 615 | PyObject *fnames, *result; |
| 616 | int i; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 617 | fnames = PyTuple_New(num_fields); |
| 618 | if (!fnames) return NULL; |
| 619 | for (i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 620 | PyObject *field = PyUnicode_FromString(fields[i]); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 621 | if (!field) { |
| 622 | Py_DECREF(fnames); |
| 623 | return NULL; |
| 624 | } |
| 625 | PyTuple_SET_ITEM(fnames, i, field); |
| 626 | } |
Victor Stinner | 7eeb5b5 | 2010-06-07 19:57:46 +0000 | [diff] [blame] | 627 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 628 | type, base, "_fields", fnames, "__module__", "_ast"); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 629 | Py_DECREF(fnames); |
| 630 | return (PyTypeObject*)result; |
| 631 | } |
| 632 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 633 | static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) |
| 634 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 635 | int i, result; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 636 | _Py_IDENTIFIER(_attributes); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 637 | PyObject *s, *l = PyTuple_New(num_fields); |
Benjamin Peterson | 3e5cd1d | 2010-06-27 21:45:24 +0000 | [diff] [blame] | 638 | if (!l) |
| 639 | return 0; |
| 640 | for (i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 641 | s = PyUnicode_FromString(attrs[i]); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 642 | if (!s) { |
| 643 | Py_DECREF(l); |
| 644 | return 0; |
| 645 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 646 | PyTuple_SET_ITEM(l, i, s); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 647 | } |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 648 | result = _PyObject_SetAttrId((PyObject*)type, &PyId__attributes, l) >= 0; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 649 | Py_DECREF(l); |
| 650 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 651 | } |
| 652 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 653 | /* Conversion AST -> Python */ |
| 654 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 655 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 656 | { |
Benjamin Peterson | 77fa937 | 2012-05-15 10:10:27 -0700 | [diff] [blame] | 657 | Py_ssize_t i, n = asdl_seq_LEN(seq); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 658 | PyObject *result = PyList_New(n); |
| 659 | PyObject *value; |
| 660 | if (!result) |
| 661 | return NULL; |
| 662 | for (i = 0; i < n; i++) { |
| 663 | value = func(asdl_seq_GET(seq, i)); |
| 664 | if (!value) { |
| 665 | Py_DECREF(result); |
| 666 | return NULL; |
| 667 | } |
| 668 | PyList_SET_ITEM(result, i, value); |
| 669 | } |
| 670 | return result; |
| 671 | } |
| 672 | |
| 673 | static PyObject* ast2obj_object(void *o) |
| 674 | { |
| 675 | if (!o) |
| 676 | o = Py_None; |
| 677 | Py_INCREF((PyObject*)o); |
| 678 | return (PyObject*)o; |
| 679 | } |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 680 | #define ast2obj_singleton ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 681 | #define ast2obj_identifier ast2obj_object |
| 682 | #define ast2obj_string ast2obj_object |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 683 | #define ast2obj_bytes ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 684 | |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 685 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 686 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 687 | return PyLong_FromLong(b); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 688 | } |
| 689 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 690 | /* Conversion Python -> AST */ |
| 691 | |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 692 | static int obj2ast_singleton(PyObject *obj, PyObject** out, PyArena* arena) |
| 693 | { |
| 694 | if (obj != Py_None && obj != Py_True && obj != Py_False) { |
| 695 | PyErr_SetString(PyExc_ValueError, |
| 696 | "AST singleton must be True, False, or None"); |
| 697 | return 1; |
| 698 | } |
| 699 | *out = obj; |
| 700 | return 0; |
| 701 | } |
| 702 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 703 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 704 | { |
| 705 | if (obj == Py_None) |
| 706 | obj = NULL; |
| 707 | if (obj) |
| 708 | PyArena_AddPyObject(arena, obj); |
| 709 | Py_XINCREF(obj); |
| 710 | *out = obj; |
| 711 | return 0; |
| 712 | } |
| 713 | |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 714 | static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 715 | { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 716 | if (!PyUnicode_CheckExact(obj) && obj != Py_None) { |
| 717 | PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 718 | return 1; |
| 719 | } |
| 720 | return obj2ast_object(obj, out, arena); |
| 721 | } |
| 722 | |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 723 | static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) |
| 724 | { |
Benjamin Peterson | 0224d4e | 2011-08-31 22:13:03 -0400 | [diff] [blame] | 725 | if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 726 | PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); |
| 727 | return 1; |
| 728 | } |
| 729 | return obj2ast_object(obj, out, arena); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 730 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 731 | |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 732 | static int obj2ast_bytes(PyObject* obj, PyObject** out, PyArena* arena) |
| 733 | { |
| 734 | if (!PyBytes_CheckExact(obj)) { |
| 735 | PyErr_SetString(PyExc_TypeError, "AST bytes must be of type bytes"); |
| 736 | return 1; |
| 737 | } |
| 738 | return obj2ast_object(obj, out, arena); |
| 739 | } |
| 740 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 741 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 742 | { |
| 743 | int i; |
| 744 | if (!PyLong_Check(obj)) { |
Amaury Forgeot d'Arc | 5e8f810 | 2011-11-22 21:52:30 +0100 | [diff] [blame] | 745 | PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 746 | return 1; |
| 747 | } |
| 748 | |
| 749 | i = (int)PyLong_AsLong(obj); |
| 750 | if (i == -1 && PyErr_Occurred()) |
| 751 | return 1; |
| 752 | *out = i; |
| 753 | return 0; |
| 754 | } |
| 755 | |
Benjamin Peterson | 1a6e0d0 | 2008-10-25 15:49:17 +0000 | [diff] [blame] | 756 | static int add_ast_fields(void) |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 757 | { |
| 758 | PyObject *empty_tuple, *d; |
| 759 | if (PyType_Ready(&AST_type) < 0) |
| 760 | return -1; |
| 761 | d = AST_type.tp_dict; |
| 762 | empty_tuple = PyTuple_New(0); |
| 763 | if (!empty_tuple || |
| 764 | PyDict_SetItemString(d, "_fields", empty_tuple) < 0 || |
| 765 | PyDict_SetItemString(d, "_attributes", empty_tuple) < 0) { |
| 766 | Py_XDECREF(empty_tuple); |
| 767 | return -1; |
| 768 | } |
| 769 | Py_DECREF(empty_tuple); |
| 770 | return 0; |
| 771 | } |
| 772 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 773 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 774 | static int init_types(void) |
| 775 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 776 | static int initialized; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 777 | if (initialized) return 1; |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 778 | if (add_ast_fields() < 0) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 779 | mod_type = make_type("mod", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 780 | if (!mod_type) return 0; |
| 781 | if (!add_attributes(mod_type, NULL, 0)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 782 | Module_type = make_type("Module", mod_type, Module_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 783 | if (!Module_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 784 | Interactive_type = make_type("Interactive", mod_type, |
| 785 | Interactive_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 786 | if (!Interactive_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 787 | Expression_type = make_type("Expression", mod_type, Expression_fields, |
| 788 | 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 789 | if (!Expression_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 790 | Suite_type = make_type("Suite", mod_type, Suite_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 791 | if (!Suite_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 792 | stmt_type = make_type("stmt", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 793 | if (!stmt_type) return 0; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 794 | if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 795 | FunctionDef_type = make_type("FunctionDef", stmt_type, |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 796 | FunctionDef_fields, 5); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 797 | if (!FunctionDef_type) return 0; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 798 | ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 7); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 799 | if (!ClassDef_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 800 | Return_type = make_type("Return", stmt_type, Return_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 801 | if (!Return_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 802 | Delete_type = make_type("Delete", stmt_type, Delete_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 803 | if (!Delete_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 804 | Assign_type = make_type("Assign", stmt_type, Assign_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 805 | if (!Assign_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 806 | AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 807 | if (!AugAssign_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 808 | For_type = make_type("For", stmt_type, For_fields, 4); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 809 | if (!For_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 810 | While_type = make_type("While", stmt_type, While_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 811 | if (!While_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 812 | If_type = make_type("If", stmt_type, If_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 813 | if (!If_type) return 0; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 814 | With_type = make_type("With", stmt_type, With_fields, 2); |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 815 | if (!With_type) return 0; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 816 | Raise_type = make_type("Raise", stmt_type, Raise_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 817 | if (!Raise_type) return 0; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 818 | Try_type = make_type("Try", stmt_type, Try_fields, 4); |
| 819 | if (!Try_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 820 | Assert_type = make_type("Assert", stmt_type, Assert_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 821 | if (!Assert_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 822 | Import_type = make_type("Import", stmt_type, Import_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 823 | if (!Import_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 824 | ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 825 | 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 826 | if (!ImportFrom_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 827 | Global_type = make_type("Global", stmt_type, Global_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 828 | if (!Global_type) return 0; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 829 | Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1); |
| 830 | if (!Nonlocal_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 831 | Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 832 | if (!Expr_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 833 | Pass_type = make_type("Pass", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 834 | if (!Pass_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 835 | Break_type = make_type("Break", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 836 | if (!Break_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 837 | Continue_type = make_type("Continue", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 838 | if (!Continue_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 839 | expr_type = make_type("expr", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 840 | if (!expr_type) return 0; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 841 | if (!add_attributes(expr_type, expr_attributes, 2)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 842 | BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 843 | if (!BoolOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 844 | BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 845 | if (!BinOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 846 | UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 847 | if (!UnaryOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 848 | Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 849 | if (!Lambda_type) return 0; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 850 | IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 851 | if (!IfExp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 852 | Dict_type = make_type("Dict", expr_type, Dict_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 853 | if (!Dict_type) return 0; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 854 | Set_type = make_type("Set", expr_type, Set_fields, 1); |
| 855 | if (!Set_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 856 | ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 857 | if (!ListComp_type) return 0; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 858 | SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2); |
| 859 | if (!SetComp_type) return 0; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 860 | DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3); |
| 861 | if (!DictComp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 862 | GeneratorExp_type = make_type("GeneratorExp", expr_type, |
| 863 | GeneratorExp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 864 | if (!GeneratorExp_type) return 0; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 865 | Yield_type = make_type("Yield", expr_type, Yield_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 866 | if (!Yield_type) return 0; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 867 | YieldFrom_type = make_type("YieldFrom", expr_type, YieldFrom_fields, 1); |
| 868 | if (!YieldFrom_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 869 | Compare_type = make_type("Compare", expr_type, Compare_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 870 | if (!Compare_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 871 | Call_type = make_type("Call", expr_type, Call_fields, 5); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 872 | if (!Call_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 873 | Num_type = make_type("Num", expr_type, Num_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 874 | if (!Num_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 875 | Str_type = make_type("Str", expr_type, Str_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 876 | if (!Str_type) return 0; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 877 | Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1); |
| 878 | if (!Bytes_type) return 0; |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 879 | NameConstant_type = make_type("NameConstant", expr_type, |
| 880 | NameConstant_fields, 1); |
| 881 | if (!NameConstant_type) return 0; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 882 | Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0); |
| 883 | if (!Ellipsis_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 884 | Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 885 | if (!Attribute_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 886 | Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 887 | if (!Subscript_type) return 0; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 888 | Starred_type = make_type("Starred", expr_type, Starred_fields, 2); |
| 889 | if (!Starred_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 890 | Name_type = make_type("Name", expr_type, Name_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 891 | if (!Name_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 892 | List_type = make_type("List", expr_type, List_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 893 | if (!List_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 894 | Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 895 | if (!Tuple_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 896 | 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] | 897 | if (!expr_context_type) return 0; |
| 898 | if (!add_attributes(expr_context_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 899 | Load_type = make_type("Load", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 900 | if (!Load_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 901 | Load_singleton = PyType_GenericNew(Load_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 902 | if (!Load_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 903 | Store_type = make_type("Store", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 904 | if (!Store_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 905 | Store_singleton = PyType_GenericNew(Store_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 906 | if (!Store_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 907 | Del_type = make_type("Del", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 908 | if (!Del_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 909 | Del_singleton = PyType_GenericNew(Del_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 910 | if (!Del_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 911 | AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 912 | if (!AugLoad_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 913 | AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 914 | if (!AugLoad_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 915 | AugStore_type = make_type("AugStore", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 916 | if (!AugStore_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 917 | AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 918 | if (!AugStore_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 919 | Param_type = make_type("Param", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 920 | if (!Param_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 921 | Param_singleton = PyType_GenericNew(Param_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 922 | if (!Param_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 923 | slice_type = make_type("slice", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 924 | if (!slice_type) return 0; |
| 925 | if (!add_attributes(slice_type, NULL, 0)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 926 | Slice_type = make_type("Slice", slice_type, Slice_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 927 | if (!Slice_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 928 | ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 929 | if (!ExtSlice_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 930 | Index_type = make_type("Index", slice_type, Index_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 931 | if (!Index_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 932 | boolop_type = make_type("boolop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 933 | if (!boolop_type) return 0; |
| 934 | if (!add_attributes(boolop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 935 | And_type = make_type("And", boolop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 936 | if (!And_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 937 | And_singleton = PyType_GenericNew(And_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 938 | if (!And_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 939 | Or_type = make_type("Or", boolop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 940 | if (!Or_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 941 | Or_singleton = PyType_GenericNew(Or_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 942 | if (!Or_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 943 | operator_type = make_type("operator", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 944 | if (!operator_type) return 0; |
| 945 | if (!add_attributes(operator_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 946 | Add_type = make_type("Add", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 947 | if (!Add_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 948 | Add_singleton = PyType_GenericNew(Add_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 949 | if (!Add_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 950 | Sub_type = make_type("Sub", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 951 | if (!Sub_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 952 | Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 953 | if (!Sub_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 954 | Mult_type = make_type("Mult", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 955 | if (!Mult_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 956 | Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 957 | if (!Mult_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 958 | Div_type = make_type("Div", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 959 | if (!Div_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 960 | Div_singleton = PyType_GenericNew(Div_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 961 | if (!Div_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 962 | Mod_type = make_type("Mod", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 963 | if (!Mod_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 964 | Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 965 | if (!Mod_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 966 | Pow_type = make_type("Pow", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 967 | if (!Pow_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 968 | Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 969 | if (!Pow_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 970 | LShift_type = make_type("LShift", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 971 | if (!LShift_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 972 | LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 973 | if (!LShift_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 974 | RShift_type = make_type("RShift", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 975 | if (!RShift_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 976 | RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 977 | if (!RShift_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 978 | BitOr_type = make_type("BitOr", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 979 | if (!BitOr_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 980 | BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 981 | if (!BitOr_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 982 | BitXor_type = make_type("BitXor", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 983 | if (!BitXor_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 984 | BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 985 | if (!BitXor_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 986 | BitAnd_type = make_type("BitAnd", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 987 | if (!BitAnd_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 988 | BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 989 | if (!BitAnd_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 990 | FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 991 | if (!FloorDiv_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 992 | FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 993 | if (!FloorDiv_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 994 | unaryop_type = make_type("unaryop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 995 | if (!unaryop_type) return 0; |
| 996 | if (!add_attributes(unaryop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 997 | Invert_type = make_type("Invert", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 998 | if (!Invert_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 999 | Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1000 | if (!Invert_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1001 | Not_type = make_type("Not", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1002 | if (!Not_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1003 | Not_singleton = PyType_GenericNew(Not_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1004 | if (!Not_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1005 | UAdd_type = make_type("UAdd", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1006 | if (!UAdd_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1007 | UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1008 | if (!UAdd_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1009 | USub_type = make_type("USub", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1010 | if (!USub_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1011 | USub_singleton = PyType_GenericNew(USub_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1012 | if (!USub_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1013 | cmpop_type = make_type("cmpop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1014 | if (!cmpop_type) return 0; |
| 1015 | if (!add_attributes(cmpop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1016 | Eq_type = make_type("Eq", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1017 | if (!Eq_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1018 | Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1019 | if (!Eq_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1020 | NotEq_type = make_type("NotEq", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1021 | if (!NotEq_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1022 | NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1023 | if (!NotEq_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1024 | Lt_type = make_type("Lt", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1025 | if (!Lt_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1026 | Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1027 | if (!Lt_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1028 | LtE_type = make_type("LtE", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1029 | if (!LtE_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1030 | LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1031 | if (!LtE_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1032 | Gt_type = make_type("Gt", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1033 | if (!Gt_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1034 | Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1035 | if (!Gt_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1036 | GtE_type = make_type("GtE", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1037 | if (!GtE_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1038 | GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1039 | if (!GtE_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1040 | Is_type = make_type("Is", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1041 | if (!Is_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1042 | Is_singleton = PyType_GenericNew(Is_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1043 | if (!Is_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1044 | IsNot_type = make_type("IsNot", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1045 | if (!IsNot_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1046 | IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1047 | if (!IsNot_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1048 | In_type = make_type("In", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1049 | if (!In_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1050 | In_singleton = PyType_GenericNew(In_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1051 | if (!In_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1052 | NotIn_type = make_type("NotIn", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1053 | if (!NotIn_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1054 | NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1055 | if (!NotIn_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1056 | comprehension_type = make_type("comprehension", &AST_type, |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1057 | comprehension_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1058 | if (!comprehension_type) return 0; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 1059 | excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1060 | if (!excepthandler_type) return 0; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 1061 | if (!add_attributes(excepthandler_type, excepthandler_attributes, 2)) |
| 1062 | return 0; |
| 1063 | ExceptHandler_type = make_type("ExceptHandler", excepthandler_type, |
| 1064 | ExceptHandler_fields, 3); |
| 1065 | if (!ExceptHandler_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1066 | arguments_type = make_type("arguments", &AST_type, arguments_fields, 8); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1067 | if (!arguments_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1068 | arg_type = make_type("arg", &AST_type, arg_fields, 2); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1069 | if (!arg_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1070 | keyword_type = make_type("keyword", &AST_type, keyword_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1071 | if (!keyword_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1072 | alias_type = make_type("alias", &AST_type, alias_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1073 | if (!alias_type) return 0; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1074 | withitem_type = make_type("withitem", &AST_type, withitem_fields, 2); |
| 1075 | if (!withitem_type) return 0; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1076 | initialized = 1; |
| 1077 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1078 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 1079 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1080 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 1081 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 1082 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 1083 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 1084 | arena); |
| 1085 | static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena); |
| 1086 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 1087 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 1088 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 1089 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 1090 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 1091 | arena); |
| 1092 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 1093 | arena); |
| 1094 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 1095 | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
| 1096 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 1097 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1098 | 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] | 1099 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1100 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1101 | Module(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1102 | { |
| 1103 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1104 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1105 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1106 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1107 | p->kind = Module_kind; |
| 1108 | p->v.Module.body = body; |
| 1109 | return p; |
| 1110 | } |
| 1111 | |
| 1112 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1113 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1114 | { |
| 1115 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1116 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1117 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1118 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1119 | p->kind = Interactive_kind; |
| 1120 | p->v.Interactive.body = body; |
| 1121 | return p; |
| 1122 | } |
| 1123 | |
| 1124 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1125 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1126 | { |
| 1127 | mod_ty p; |
| 1128 | if (!body) { |
| 1129 | PyErr_SetString(PyExc_ValueError, |
| 1130 | "field body is required for Expression"); |
| 1131 | return NULL; |
| 1132 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1133 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1134 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1135 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1136 | p->kind = Expression_kind; |
| 1137 | p->v.Expression.body = body; |
| 1138 | return p; |
| 1139 | } |
| 1140 | |
| 1141 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1142 | Suite(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1143 | { |
| 1144 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1145 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1146 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1147 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1148 | p->kind = Suite_kind; |
| 1149 | p->v.Suite.body = body; |
| 1150 | return p; |
| 1151 | } |
| 1152 | |
| 1153 | stmt_ty |
| 1154 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1155 | decorator_list, expr_ty returns, int lineno, int col_offset, |
| 1156 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1157 | { |
| 1158 | stmt_ty p; |
| 1159 | if (!name) { |
| 1160 | PyErr_SetString(PyExc_ValueError, |
| 1161 | "field name is required for FunctionDef"); |
| 1162 | return NULL; |
| 1163 | } |
| 1164 | if (!args) { |
| 1165 | PyErr_SetString(PyExc_ValueError, |
| 1166 | "field args is required for FunctionDef"); |
| 1167 | return NULL; |
| 1168 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1169 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1170 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1171 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1172 | p->kind = FunctionDef_kind; |
| 1173 | p->v.FunctionDef.name = name; |
| 1174 | p->v.FunctionDef.args = args; |
| 1175 | p->v.FunctionDef.body = body; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1176 | p->v.FunctionDef.decorator_list = decorator_list; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1177 | p->v.FunctionDef.returns = returns; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 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 |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 1184 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, expr_ty |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1185 | starargs, expr_ty kwargs, asdl_seq * body, asdl_seq * decorator_list, |
| 1186 | int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1187 | { |
| 1188 | stmt_ty p; |
| 1189 | if (!name) { |
| 1190 | PyErr_SetString(PyExc_ValueError, |
| 1191 | "field name is required for ClassDef"); |
| 1192 | return NULL; |
| 1193 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1194 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1195 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1196 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1197 | p->kind = ClassDef_kind; |
| 1198 | p->v.ClassDef.name = name; |
| 1199 | p->v.ClassDef.bases = bases; |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 1200 | p->v.ClassDef.keywords = keywords; |
| 1201 | p->v.ClassDef.starargs = starargs; |
| 1202 | p->v.ClassDef.kwargs = kwargs; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1203 | p->v.ClassDef.body = body; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1204 | p->v.ClassDef.decorator_list = decorator_list; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1205 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1206 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1207 | return p; |
| 1208 | } |
| 1209 | |
| 1210 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1211 | Return(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1212 | { |
| 1213 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1214 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1215 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1216 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1217 | p->kind = Return_kind; |
| 1218 | p->v.Return.value = value; |
| 1219 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1220 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1221 | return p; |
| 1222 | } |
| 1223 | |
| 1224 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1225 | Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1226 | { |
| 1227 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1228 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1229 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1230 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1231 | p->kind = Delete_kind; |
| 1232 | p->v.Delete.targets = targets; |
| 1233 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1234 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1235 | return p; |
| 1236 | } |
| 1237 | |
| 1238 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1239 | Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena |
| 1240 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1241 | { |
| 1242 | stmt_ty p; |
| 1243 | if (!value) { |
| 1244 | PyErr_SetString(PyExc_ValueError, |
| 1245 | "field value is required for Assign"); |
| 1246 | return NULL; |
| 1247 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1248 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1249 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1250 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1251 | p->kind = Assign_kind; |
| 1252 | p->v.Assign.targets = targets; |
| 1253 | p->v.Assign.value = value; |
| 1254 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1255 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1256 | return p; |
| 1257 | } |
| 1258 | |
| 1259 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1260 | AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int |
| 1261 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1262 | { |
| 1263 | stmt_ty p; |
| 1264 | if (!target) { |
| 1265 | PyErr_SetString(PyExc_ValueError, |
| 1266 | "field target is required for AugAssign"); |
| 1267 | return NULL; |
| 1268 | } |
| 1269 | if (!op) { |
| 1270 | PyErr_SetString(PyExc_ValueError, |
| 1271 | "field op is required for AugAssign"); |
| 1272 | return NULL; |
| 1273 | } |
| 1274 | if (!value) { |
| 1275 | PyErr_SetString(PyExc_ValueError, |
| 1276 | "field value is required for AugAssign"); |
| 1277 | return NULL; |
| 1278 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1279 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1280 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1281 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1282 | p->kind = AugAssign_kind; |
| 1283 | p->v.AugAssign.target = target; |
| 1284 | p->v.AugAssign.op = op; |
| 1285 | p->v.AugAssign.value = value; |
| 1286 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1287 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1288 | return p; |
| 1289 | } |
| 1290 | |
| 1291 | stmt_ty |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1292 | 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] | 1293 | lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1294 | { |
| 1295 | stmt_ty p; |
| 1296 | if (!target) { |
| 1297 | PyErr_SetString(PyExc_ValueError, |
| 1298 | "field target is required for For"); |
| 1299 | return NULL; |
| 1300 | } |
| 1301 | if (!iter) { |
| 1302 | PyErr_SetString(PyExc_ValueError, |
| 1303 | "field iter is required for For"); |
| 1304 | return NULL; |
| 1305 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1306 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1307 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1308 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1309 | p->kind = For_kind; |
| 1310 | p->v.For.target = target; |
| 1311 | p->v.For.iter = iter; |
| 1312 | p->v.For.body = body; |
| 1313 | p->v.For.orelse = orelse; |
| 1314 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1315 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1316 | return p; |
| 1317 | } |
| 1318 | |
| 1319 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1320 | While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1321 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1322 | { |
| 1323 | stmt_ty p; |
| 1324 | if (!test) { |
| 1325 | PyErr_SetString(PyExc_ValueError, |
| 1326 | "field test is required for While"); |
| 1327 | return NULL; |
| 1328 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1329 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1330 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1331 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1332 | p->kind = While_kind; |
| 1333 | p->v.While.test = test; |
| 1334 | p->v.While.body = body; |
| 1335 | p->v.While.orelse = orelse; |
| 1336 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1337 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1338 | return p; |
| 1339 | } |
| 1340 | |
| 1341 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1342 | If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1343 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1344 | { |
| 1345 | stmt_ty p; |
| 1346 | if (!test) { |
| 1347 | PyErr_SetString(PyExc_ValueError, |
| 1348 | "field test is required for If"); |
| 1349 | return NULL; |
| 1350 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1351 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1352 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1353 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1354 | p->kind = If_kind; |
| 1355 | p->v.If.test = test; |
| 1356 | p->v.If.body = body; |
| 1357 | p->v.If.orelse = orelse; |
| 1358 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1359 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1360 | return p; |
| 1361 | } |
| 1362 | |
| 1363 | stmt_ty |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1364 | With(asdl_seq * items, asdl_seq * body, int lineno, int col_offset, PyArena |
| 1365 | *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1366 | { |
| 1367 | stmt_ty p; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1368 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1369 | if (!p) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1370 | return NULL; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1371 | p->kind = With_kind; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1372 | p->v.With.items = items; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1373 | p->v.With.body = body; |
| 1374 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1375 | p->col_offset = col_offset; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1376 | return p; |
| 1377 | } |
| 1378 | |
| 1379 | stmt_ty |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 1380 | 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] | 1381 | { |
| 1382 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1383 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1384 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1385 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1386 | p->kind = Raise_kind; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 1387 | p->v.Raise.exc = exc; |
| 1388 | p->v.Raise.cause = cause; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1389 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1390 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1391 | return p; |
| 1392 | } |
| 1393 | |
| 1394 | stmt_ty |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 1395 | Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * |
| 1396 | finalbody, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1397 | { |
| 1398 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1399 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1400 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1401 | return NULL; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 1402 | p->kind = Try_kind; |
| 1403 | p->v.Try.body = body; |
| 1404 | p->v.Try.handlers = handlers; |
| 1405 | p->v.Try.orelse = orelse; |
| 1406 | p->v.Try.finalbody = finalbody; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1407 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1408 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1409 | return p; |
| 1410 | } |
| 1411 | |
| 1412 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1413 | 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] | 1414 | { |
| 1415 | stmt_ty p; |
| 1416 | if (!test) { |
| 1417 | PyErr_SetString(PyExc_ValueError, |
| 1418 | "field test is required for Assert"); |
| 1419 | return NULL; |
| 1420 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1421 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1422 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1423 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1424 | p->kind = Assert_kind; |
| 1425 | p->v.Assert.test = test; |
| 1426 | p->v.Assert.msg = msg; |
| 1427 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1428 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1429 | return p; |
| 1430 | } |
| 1431 | |
| 1432 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1433 | Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1434 | { |
| 1435 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1436 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1437 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1438 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1439 | p->kind = Import_kind; |
| 1440 | p->v.Import.names = names; |
| 1441 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1442 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1443 | return p; |
| 1444 | } |
| 1445 | |
| 1446 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1447 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
| 1448 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1449 | { |
| 1450 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1451 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1452 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1453 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1454 | p->kind = ImportFrom_kind; |
| 1455 | p->v.ImportFrom.module = module; |
| 1456 | p->v.ImportFrom.names = names; |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 1457 | p->v.ImportFrom.level = level; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1458 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1459 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1460 | return p; |
| 1461 | } |
| 1462 | |
| 1463 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1464 | Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1465 | { |
| 1466 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1467 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1468 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1469 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1470 | p->kind = Global_kind; |
| 1471 | p->v.Global.names = names; |
| 1472 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1473 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1474 | return p; |
| 1475 | } |
| 1476 | |
| 1477 | stmt_ty |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 1478 | Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
| 1479 | { |
| 1480 | stmt_ty p; |
| 1481 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1482 | if (!p) |
| 1483 | return NULL; |
| 1484 | p->kind = Nonlocal_kind; |
| 1485 | p->v.Nonlocal.names = names; |
| 1486 | p->lineno = lineno; |
| 1487 | p->col_offset = col_offset; |
| 1488 | return p; |
| 1489 | } |
| 1490 | |
| 1491 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1492 | Expr(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1493 | { |
| 1494 | stmt_ty p; |
| 1495 | if (!value) { |
| 1496 | PyErr_SetString(PyExc_ValueError, |
| 1497 | "field value is required for Expr"); |
| 1498 | return NULL; |
| 1499 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1500 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1501 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1502 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1503 | p->kind = Expr_kind; |
| 1504 | p->v.Expr.value = value; |
| 1505 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1506 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1507 | return p; |
| 1508 | } |
| 1509 | |
| 1510 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1511 | Pass(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1512 | { |
| 1513 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1514 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1515 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1516 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1517 | p->kind = Pass_kind; |
| 1518 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1519 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1520 | return p; |
| 1521 | } |
| 1522 | |
| 1523 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1524 | Break(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1525 | { |
| 1526 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1527 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1528 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1529 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1530 | p->kind = Break_kind; |
| 1531 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1532 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1533 | return p; |
| 1534 | } |
| 1535 | |
| 1536 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1537 | Continue(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1538 | { |
| 1539 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1540 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1541 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1542 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1543 | p->kind = Continue_kind; |
| 1544 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1545 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1546 | return p; |
| 1547 | } |
| 1548 | |
| 1549 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1550 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1551 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1552 | { |
| 1553 | expr_ty p; |
| 1554 | if (!op) { |
| 1555 | PyErr_SetString(PyExc_ValueError, |
| 1556 | "field op is required for BoolOp"); |
| 1557 | return NULL; |
| 1558 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1559 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1560 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1561 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1562 | p->kind = BoolOp_kind; |
| 1563 | p->v.BoolOp.op = op; |
| 1564 | p->v.BoolOp.values = values; |
| 1565 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1566 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1567 | return p; |
| 1568 | } |
| 1569 | |
| 1570 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1571 | BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset, |
| 1572 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1573 | { |
| 1574 | expr_ty p; |
| 1575 | if (!left) { |
| 1576 | PyErr_SetString(PyExc_ValueError, |
| 1577 | "field left is required for BinOp"); |
| 1578 | return NULL; |
| 1579 | } |
| 1580 | if (!op) { |
| 1581 | PyErr_SetString(PyExc_ValueError, |
| 1582 | "field op is required for BinOp"); |
| 1583 | return NULL; |
| 1584 | } |
| 1585 | if (!right) { |
| 1586 | PyErr_SetString(PyExc_ValueError, |
| 1587 | "field right is required for BinOp"); |
| 1588 | return NULL; |
| 1589 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1590 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1591 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1592 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1593 | p->kind = BinOp_kind; |
| 1594 | p->v.BinOp.left = left; |
| 1595 | p->v.BinOp.op = op; |
| 1596 | p->v.BinOp.right = right; |
| 1597 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1598 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1599 | return p; |
| 1600 | } |
| 1601 | |
| 1602 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1603 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena |
| 1604 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1605 | { |
| 1606 | expr_ty p; |
| 1607 | if (!op) { |
| 1608 | PyErr_SetString(PyExc_ValueError, |
| 1609 | "field op is required for UnaryOp"); |
| 1610 | return NULL; |
| 1611 | } |
| 1612 | if (!operand) { |
| 1613 | PyErr_SetString(PyExc_ValueError, |
| 1614 | "field operand is required for UnaryOp"); |
| 1615 | return NULL; |
| 1616 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1617 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1618 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1619 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1620 | p->kind = UnaryOp_kind; |
| 1621 | p->v.UnaryOp.op = op; |
| 1622 | p->v.UnaryOp.operand = operand; |
| 1623 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1624 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1625 | return p; |
| 1626 | } |
| 1627 | |
| 1628 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1629 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena |
| 1630 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1631 | { |
| 1632 | expr_ty p; |
| 1633 | if (!args) { |
| 1634 | PyErr_SetString(PyExc_ValueError, |
| 1635 | "field args is required for Lambda"); |
| 1636 | return NULL; |
| 1637 | } |
| 1638 | if (!body) { |
| 1639 | PyErr_SetString(PyExc_ValueError, |
| 1640 | "field body is required for Lambda"); |
| 1641 | return NULL; |
| 1642 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1643 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1644 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1645 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1646 | p->kind = Lambda_kind; |
| 1647 | p->v.Lambda.args = args; |
| 1648 | p->v.Lambda.body = body; |
| 1649 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1650 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1651 | return p; |
| 1652 | } |
| 1653 | |
| 1654 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1655 | IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset, |
| 1656 | PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1657 | { |
| 1658 | expr_ty p; |
| 1659 | if (!test) { |
| 1660 | PyErr_SetString(PyExc_ValueError, |
| 1661 | "field test is required for IfExp"); |
| 1662 | return NULL; |
| 1663 | } |
| 1664 | if (!body) { |
| 1665 | PyErr_SetString(PyExc_ValueError, |
| 1666 | "field body is required for IfExp"); |
| 1667 | return NULL; |
| 1668 | } |
| 1669 | if (!orelse) { |
| 1670 | PyErr_SetString(PyExc_ValueError, |
| 1671 | "field orelse is required for IfExp"); |
| 1672 | return NULL; |
| 1673 | } |
| 1674 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1675 | if (!p) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1676 | return NULL; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1677 | p->kind = IfExp_kind; |
| 1678 | p->v.IfExp.test = test; |
| 1679 | p->v.IfExp.body = body; |
| 1680 | p->v.IfExp.orelse = orelse; |
| 1681 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1682 | p->col_offset = col_offset; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1683 | return p; |
| 1684 | } |
| 1685 | |
| 1686 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1687 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1688 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1689 | { |
| 1690 | expr_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1691 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1692 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1693 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1694 | p->kind = Dict_kind; |
| 1695 | p->v.Dict.keys = keys; |
| 1696 | p->v.Dict.values = values; |
| 1697 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1698 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1699 | return p; |
| 1700 | } |
| 1701 | |
| 1702 | expr_ty |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1703 | Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena) |
| 1704 | { |
| 1705 | expr_ty p; |
| 1706 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1707 | if (!p) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1708 | return NULL; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1709 | p->kind = Set_kind; |
| 1710 | p->v.Set.elts = elts; |
| 1711 | p->lineno = lineno; |
| 1712 | p->col_offset = col_offset; |
| 1713 | return p; |
| 1714 | } |
| 1715 | |
| 1716 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1717 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1718 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1719 | { |
| 1720 | expr_ty p; |
| 1721 | if (!elt) { |
| 1722 | PyErr_SetString(PyExc_ValueError, |
| 1723 | "field elt is required for ListComp"); |
| 1724 | return NULL; |
| 1725 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1726 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1727 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1728 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1729 | p->kind = ListComp_kind; |
| 1730 | p->v.ListComp.elt = elt; |
| 1731 | p->v.ListComp.generators = generators; |
| 1732 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1733 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1734 | return p; |
| 1735 | } |
| 1736 | |
| 1737 | expr_ty |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 1738 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena |
| 1739 | *arena) |
| 1740 | { |
| 1741 | expr_ty p; |
| 1742 | if (!elt) { |
| 1743 | PyErr_SetString(PyExc_ValueError, |
| 1744 | "field elt is required for SetComp"); |
| 1745 | return NULL; |
| 1746 | } |
| 1747 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1748 | if (!p) |
| 1749 | return NULL; |
| 1750 | p->kind = SetComp_kind; |
| 1751 | p->v.SetComp.elt = elt; |
| 1752 | p->v.SetComp.generators = generators; |
| 1753 | p->lineno = lineno; |
| 1754 | p->col_offset = col_offset; |
| 1755 | return p; |
| 1756 | } |
| 1757 | |
| 1758 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 1759 | DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int |
| 1760 | col_offset, PyArena *arena) |
| 1761 | { |
| 1762 | expr_ty p; |
| 1763 | if (!key) { |
| 1764 | PyErr_SetString(PyExc_ValueError, |
| 1765 | "field key is required for DictComp"); |
| 1766 | return NULL; |
| 1767 | } |
| 1768 | if (!value) { |
| 1769 | PyErr_SetString(PyExc_ValueError, |
| 1770 | "field value is required for DictComp"); |
| 1771 | return NULL; |
| 1772 | } |
| 1773 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1774 | if (!p) |
| 1775 | return NULL; |
| 1776 | p->kind = DictComp_kind; |
| 1777 | p->v.DictComp.key = key; |
| 1778 | p->v.DictComp.value = value; |
| 1779 | p->v.DictComp.generators = generators; |
| 1780 | p->lineno = lineno; |
| 1781 | p->col_offset = col_offset; |
| 1782 | return p; |
| 1783 | } |
| 1784 | |
| 1785 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1786 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1787 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1788 | { |
| 1789 | expr_ty p; |
| 1790 | if (!elt) { |
| 1791 | PyErr_SetString(PyExc_ValueError, |
| 1792 | "field elt is required for GeneratorExp"); |
| 1793 | return NULL; |
| 1794 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1795 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1796 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1797 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1798 | p->kind = GeneratorExp_kind; |
| 1799 | p->v.GeneratorExp.elt = elt; |
| 1800 | p->v.GeneratorExp.generators = generators; |
| 1801 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1802 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1803 | return p; |
| 1804 | } |
| 1805 | |
| 1806 | expr_ty |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 1807 | Yield(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1808 | { |
| 1809 | expr_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1810 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1811 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1812 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1813 | p->kind = Yield_kind; |
| 1814 | p->v.Yield.value = value; |
| 1815 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1816 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1817 | return p; |
| 1818 | } |
| 1819 | |
| 1820 | expr_ty |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 1821 | YieldFrom(expr_ty value, int lineno, int col_offset, PyArena *arena) |
| 1822 | { |
| 1823 | expr_ty p; |
Mark Dickinson | ded35ae | 2012-11-25 14:36:26 +0000 | [diff] [blame] | 1824 | if (!value) { |
| 1825 | PyErr_SetString(PyExc_ValueError, |
| 1826 | "field value is required for YieldFrom"); |
| 1827 | return NULL; |
| 1828 | } |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 1829 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1830 | if (!p) |
| 1831 | return NULL; |
| 1832 | p->kind = YieldFrom_kind; |
| 1833 | p->v.YieldFrom.value = value; |
| 1834 | p->lineno = lineno; |
| 1835 | p->col_offset = col_offset; |
| 1836 | return p; |
| 1837 | } |
| 1838 | |
| 1839 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1840 | Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno, |
| 1841 | int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1842 | { |
| 1843 | expr_ty p; |
| 1844 | if (!left) { |
| 1845 | PyErr_SetString(PyExc_ValueError, |
| 1846 | "field left is required for Compare"); |
| 1847 | return NULL; |
| 1848 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1849 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1850 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1851 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1852 | p->kind = Compare_kind; |
| 1853 | p->v.Compare.left = left; |
| 1854 | p->v.Compare.ops = ops; |
| 1855 | p->v.Compare.comparators = comparators; |
| 1856 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1857 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1858 | return p; |
| 1859 | } |
| 1860 | |
| 1861 | expr_ty |
| 1862 | 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] | 1863 | expr_ty kwargs, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1864 | { |
| 1865 | expr_ty p; |
| 1866 | if (!func) { |
| 1867 | PyErr_SetString(PyExc_ValueError, |
| 1868 | "field func is required for Call"); |
| 1869 | return NULL; |
| 1870 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1871 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1872 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1873 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1874 | p->kind = Call_kind; |
| 1875 | p->v.Call.func = func; |
| 1876 | p->v.Call.args = args; |
| 1877 | p->v.Call.keywords = keywords; |
| 1878 | p->v.Call.starargs = starargs; |
| 1879 | p->v.Call.kwargs = kwargs; |
| 1880 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1881 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1882 | return p; |
| 1883 | } |
| 1884 | |
| 1885 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1886 | Num(object n, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1887 | { |
| 1888 | expr_ty p; |
| 1889 | if (!n) { |
| 1890 | PyErr_SetString(PyExc_ValueError, |
| 1891 | "field n is required for Num"); |
| 1892 | return NULL; |
| 1893 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1894 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1895 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1896 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1897 | p->kind = Num_kind; |
| 1898 | p->v.Num.n = n; |
| 1899 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1900 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1901 | return p; |
| 1902 | } |
| 1903 | |
| 1904 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1905 | Str(string s, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1906 | { |
| 1907 | expr_ty p; |
| 1908 | if (!s) { |
| 1909 | PyErr_SetString(PyExc_ValueError, |
| 1910 | "field s is required for Str"); |
| 1911 | return NULL; |
| 1912 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1913 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1914 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1915 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1916 | p->kind = Str_kind; |
| 1917 | p->v.Str.s = s; |
| 1918 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1919 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1920 | return p; |
| 1921 | } |
| 1922 | |
| 1923 | expr_ty |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 1924 | Bytes(bytes s, int lineno, int col_offset, PyArena *arena) |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1925 | { |
| 1926 | expr_ty p; |
| 1927 | if (!s) { |
| 1928 | PyErr_SetString(PyExc_ValueError, |
| 1929 | "field s is required for Bytes"); |
| 1930 | return NULL; |
| 1931 | } |
| 1932 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1933 | if (!p) |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1934 | return NULL; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1935 | p->kind = Bytes_kind; |
| 1936 | p->v.Bytes.s = s; |
| 1937 | p->lineno = lineno; |
| 1938 | p->col_offset = col_offset; |
| 1939 | return p; |
| 1940 | } |
| 1941 | |
| 1942 | expr_ty |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 1943 | NameConstant(singleton value, int lineno, int col_offset, PyArena *arena) |
| 1944 | { |
| 1945 | expr_ty p; |
| 1946 | if (!value) { |
| 1947 | PyErr_SetString(PyExc_ValueError, |
| 1948 | "field value is required for NameConstant"); |
| 1949 | return NULL; |
| 1950 | } |
| 1951 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1952 | if (!p) |
| 1953 | return NULL; |
| 1954 | p->kind = NameConstant_kind; |
| 1955 | p->v.NameConstant.value = value; |
| 1956 | p->lineno = lineno; |
| 1957 | p->col_offset = col_offset; |
| 1958 | return p; |
| 1959 | } |
| 1960 | |
| 1961 | expr_ty |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1962 | Ellipsis(int lineno, int col_offset, PyArena *arena) |
| 1963 | { |
| 1964 | expr_ty p; |
| 1965 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1966 | if (!p) |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1967 | return NULL; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1968 | p->kind = Ellipsis_kind; |
| 1969 | p->lineno = lineno; |
| 1970 | p->col_offset = col_offset; |
| 1971 | return p; |
| 1972 | } |
| 1973 | |
| 1974 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1975 | Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int |
| 1976 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1977 | { |
| 1978 | expr_ty p; |
| 1979 | if (!value) { |
| 1980 | PyErr_SetString(PyExc_ValueError, |
| 1981 | "field value is required for Attribute"); |
| 1982 | return NULL; |
| 1983 | } |
| 1984 | if (!attr) { |
| 1985 | PyErr_SetString(PyExc_ValueError, |
| 1986 | "field attr is required for Attribute"); |
| 1987 | return NULL; |
| 1988 | } |
| 1989 | if (!ctx) { |
| 1990 | PyErr_SetString(PyExc_ValueError, |
| 1991 | "field ctx is required for Attribute"); |
| 1992 | return NULL; |
| 1993 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1994 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1995 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1996 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1997 | p->kind = Attribute_kind; |
| 1998 | p->v.Attribute.value = value; |
| 1999 | p->v.Attribute.attr = attr; |
| 2000 | p->v.Attribute.ctx = ctx; |
| 2001 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2002 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2003 | return p; |
| 2004 | } |
| 2005 | |
| 2006 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2007 | Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int |
| 2008 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2009 | { |
| 2010 | expr_ty p; |
| 2011 | if (!value) { |
| 2012 | PyErr_SetString(PyExc_ValueError, |
| 2013 | "field value is required for Subscript"); |
| 2014 | return NULL; |
| 2015 | } |
| 2016 | if (!slice) { |
| 2017 | PyErr_SetString(PyExc_ValueError, |
| 2018 | "field slice is required for Subscript"); |
| 2019 | return NULL; |
| 2020 | } |
| 2021 | if (!ctx) { |
| 2022 | PyErr_SetString(PyExc_ValueError, |
| 2023 | "field ctx is required for Subscript"); |
| 2024 | return NULL; |
| 2025 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2026 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2027 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2028 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2029 | p->kind = Subscript_kind; |
| 2030 | p->v.Subscript.value = value; |
| 2031 | p->v.Subscript.slice = slice; |
| 2032 | p->v.Subscript.ctx = ctx; |
| 2033 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2034 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2035 | return p; |
| 2036 | } |
| 2037 | |
| 2038 | expr_ty |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2039 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 2040 | *arena) |
| 2041 | { |
| 2042 | expr_ty p; |
| 2043 | if (!value) { |
| 2044 | PyErr_SetString(PyExc_ValueError, |
| 2045 | "field value is required for Starred"); |
| 2046 | return NULL; |
| 2047 | } |
| 2048 | if (!ctx) { |
| 2049 | PyErr_SetString(PyExc_ValueError, |
| 2050 | "field ctx is required for Starred"); |
| 2051 | return NULL; |
| 2052 | } |
| 2053 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2054 | if (!p) |
| 2055 | return NULL; |
| 2056 | p->kind = Starred_kind; |
| 2057 | p->v.Starred.value = value; |
| 2058 | p->v.Starred.ctx = ctx; |
| 2059 | p->lineno = lineno; |
| 2060 | p->col_offset = col_offset; |
| 2061 | return p; |
| 2062 | } |
| 2063 | |
| 2064 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2065 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 2066 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2067 | { |
| 2068 | expr_ty p; |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 2069 | assert(PyUnicode_CompareWithASCIIString(id, "True") && PyUnicode_CompareWithASCIIString(id, "False") && PyUnicode_CompareWithASCIIString(id, "None")); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2070 | if (!id) { |
| 2071 | PyErr_SetString(PyExc_ValueError, |
| 2072 | "field id is required for Name"); |
| 2073 | return NULL; |
| 2074 | } |
| 2075 | if (!ctx) { |
| 2076 | PyErr_SetString(PyExc_ValueError, |
| 2077 | "field ctx is required for Name"); |
| 2078 | return NULL; |
| 2079 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2080 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2081 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2082 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2083 | p->kind = Name_kind; |
| 2084 | p->v.Name.id = id; |
| 2085 | p->v.Name.ctx = ctx; |
| 2086 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2087 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2088 | return p; |
| 2089 | } |
| 2090 | |
| 2091 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2092 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 2093 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2094 | { |
| 2095 | expr_ty p; |
| 2096 | if (!ctx) { |
| 2097 | PyErr_SetString(PyExc_ValueError, |
| 2098 | "field ctx is required for List"); |
| 2099 | return NULL; |
| 2100 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2101 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2102 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2103 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2104 | p->kind = List_kind; |
| 2105 | p->v.List.elts = elts; |
| 2106 | p->v.List.ctx = ctx; |
| 2107 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2108 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2109 | return p; |
| 2110 | } |
| 2111 | |
| 2112 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2113 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 2114 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2115 | { |
| 2116 | expr_ty p; |
| 2117 | if (!ctx) { |
| 2118 | PyErr_SetString(PyExc_ValueError, |
| 2119 | "field ctx is required for Tuple"); |
| 2120 | return NULL; |
| 2121 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2122 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2123 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2124 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2125 | p->kind = Tuple_kind; |
| 2126 | p->v.Tuple.elts = elts; |
| 2127 | p->v.Tuple.ctx = ctx; |
| 2128 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2129 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2130 | return p; |
| 2131 | } |
| 2132 | |
| 2133 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2134 | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2135 | { |
| 2136 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2137 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2138 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2139 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2140 | p->kind = Slice_kind; |
| 2141 | p->v.Slice.lower = lower; |
| 2142 | p->v.Slice.upper = upper; |
| 2143 | p->v.Slice.step = step; |
| 2144 | return p; |
| 2145 | } |
| 2146 | |
| 2147 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2148 | ExtSlice(asdl_seq * dims, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2149 | { |
| 2150 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2151 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2152 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2153 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2154 | p->kind = ExtSlice_kind; |
| 2155 | p->v.ExtSlice.dims = dims; |
| 2156 | return p; |
| 2157 | } |
| 2158 | |
| 2159 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2160 | Index(expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2161 | { |
| 2162 | slice_ty p; |
| 2163 | if (!value) { |
| 2164 | PyErr_SetString(PyExc_ValueError, |
| 2165 | "field value is required for Index"); |
| 2166 | return NULL; |
| 2167 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2168 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2169 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2170 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2171 | p->kind = Index_kind; |
| 2172 | p->v.Index.value = value; |
| 2173 | return p; |
| 2174 | } |
| 2175 | |
| 2176 | comprehension_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2177 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2178 | { |
| 2179 | comprehension_ty p; |
| 2180 | if (!target) { |
| 2181 | PyErr_SetString(PyExc_ValueError, |
| 2182 | "field target is required for comprehension"); |
| 2183 | return NULL; |
| 2184 | } |
| 2185 | if (!iter) { |
| 2186 | PyErr_SetString(PyExc_ValueError, |
| 2187 | "field iter is required for comprehension"); |
| 2188 | return NULL; |
| 2189 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2190 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2191 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2192 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2193 | p->target = target; |
| 2194 | p->iter = iter; |
| 2195 | p->ifs = ifs; |
| 2196 | return p; |
| 2197 | } |
| 2198 | |
| 2199 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 2200 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2201 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2202 | { |
| 2203 | excepthandler_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2204 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2205 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2206 | return NULL; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 2207 | p->kind = ExceptHandler_kind; |
| 2208 | p->v.ExceptHandler.type = type; |
| 2209 | p->v.ExceptHandler.name = name; |
| 2210 | p->v.ExceptHandler.body = body; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2211 | p->lineno = lineno; |
| 2212 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2213 | return p; |
| 2214 | } |
| 2215 | |
| 2216 | arguments_ty |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2217 | arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation, |
| 2218 | asdl_seq * kwonlyargs, identifier kwarg, expr_ty kwargannotation, |
| 2219 | asdl_seq * defaults, asdl_seq * kw_defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2220 | { |
| 2221 | arguments_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2222 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2223 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2224 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2225 | p->args = args; |
| 2226 | p->vararg = vararg; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2227 | p->varargannotation = varargannotation; |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 2228 | p->kwonlyargs = kwonlyargs; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2229 | p->kwarg = kwarg; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2230 | p->kwargannotation = kwargannotation; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2231 | p->defaults = defaults; |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 2232 | p->kw_defaults = kw_defaults; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2233 | return p; |
| 2234 | } |
| 2235 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2236 | arg_ty |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2237 | arg(identifier arg, expr_ty annotation, PyArena *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2238 | { |
| 2239 | arg_ty p; |
| 2240 | if (!arg) { |
| 2241 | PyErr_SetString(PyExc_ValueError, |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2242 | "field arg is required for arg"); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2243 | return NULL; |
| 2244 | } |
| 2245 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2246 | if (!p) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2247 | return NULL; |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2248 | p->arg = arg; |
| 2249 | p->annotation = annotation; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2250 | return p; |
| 2251 | } |
| 2252 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2253 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2254 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2255 | { |
| 2256 | keyword_ty p; |
| 2257 | if (!arg) { |
| 2258 | PyErr_SetString(PyExc_ValueError, |
| 2259 | "field arg is required for keyword"); |
| 2260 | return NULL; |
| 2261 | } |
| 2262 | if (!value) { |
| 2263 | PyErr_SetString(PyExc_ValueError, |
| 2264 | "field value is required for keyword"); |
| 2265 | return NULL; |
| 2266 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2267 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2268 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2269 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2270 | p->arg = arg; |
| 2271 | p->value = value; |
| 2272 | return p; |
| 2273 | } |
| 2274 | |
| 2275 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2276 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2277 | { |
| 2278 | alias_ty p; |
| 2279 | if (!name) { |
| 2280 | PyErr_SetString(PyExc_ValueError, |
| 2281 | "field name is required for alias"); |
| 2282 | return NULL; |
| 2283 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2284 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2285 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2286 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2287 | p->name = name; |
| 2288 | p->asname = asname; |
| 2289 | return p; |
| 2290 | } |
| 2291 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2292 | withitem_ty |
| 2293 | withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) |
| 2294 | { |
| 2295 | withitem_ty p; |
| 2296 | if (!context_expr) { |
| 2297 | PyErr_SetString(PyExc_ValueError, |
| 2298 | "field context_expr is required for withitem"); |
| 2299 | return NULL; |
| 2300 | } |
| 2301 | p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2302 | if (!p) |
| 2303 | return NULL; |
| 2304 | p->context_expr = context_expr; |
| 2305 | p->optional_vars = optional_vars; |
| 2306 | return p; |
| 2307 | } |
| 2308 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2309 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2310 | PyObject* |
| 2311 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2312 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2313 | mod_ty o = (mod_ty)_o; |
| 2314 | PyObject *result = NULL, *value = NULL; |
| 2315 | if (!o) { |
| 2316 | Py_INCREF(Py_None); |
| 2317 | return Py_None; |
| 2318 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2319 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2320 | switch (o->kind) { |
| 2321 | case Module_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2322 | result = PyType_GenericNew(Module_type, NULL, NULL); |
| 2323 | if (!result) goto failed; |
| 2324 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 2325 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2326 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2327 | goto failed; |
| 2328 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2329 | break; |
| 2330 | case Interactive_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2331 | result = PyType_GenericNew(Interactive_type, NULL, NULL); |
| 2332 | if (!result) goto failed; |
| 2333 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 2334 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2335 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2336 | goto failed; |
| 2337 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2338 | break; |
| 2339 | case Expression_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2340 | result = PyType_GenericNew(Expression_type, NULL, NULL); |
| 2341 | if (!result) goto failed; |
| 2342 | value = ast2obj_expr(o->v.Expression.body); |
| 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); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2347 | break; |
| 2348 | case Suite_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2349 | result = PyType_GenericNew(Suite_type, NULL, NULL); |
| 2350 | if (!result) goto failed; |
| 2351 | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
| 2352 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2353 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2354 | goto failed; |
| 2355 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2356 | break; |
| 2357 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2358 | return result; |
| 2359 | failed: |
| 2360 | Py_XDECREF(value); |
| 2361 | Py_XDECREF(result); |
| 2362 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2363 | } |
| 2364 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2365 | PyObject* |
| 2366 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2367 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2368 | stmt_ty o = (stmt_ty)_o; |
| 2369 | PyObject *result = NULL, *value = NULL; |
| 2370 | if (!o) { |
| 2371 | Py_INCREF(Py_None); |
| 2372 | return Py_None; |
| 2373 | } |
| 2374 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2375 | switch (o->kind) { |
| 2376 | case FunctionDef_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2377 | result = PyType_GenericNew(FunctionDef_type, NULL, NULL); |
| 2378 | if (!result) goto failed; |
| 2379 | value = ast2obj_identifier(o->v.FunctionDef.name); |
| 2380 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2381 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2382 | goto failed; |
| 2383 | Py_DECREF(value); |
| 2384 | value = ast2obj_arguments(o->v.FunctionDef.args); |
| 2385 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2386 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2387 | goto failed; |
| 2388 | Py_DECREF(value); |
| 2389 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 2390 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2391 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2392 | goto failed; |
| 2393 | Py_DECREF(value); |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2394 | value = ast2obj_list(o->v.FunctionDef.decorator_list, |
| 2395 | ast2obj_expr); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 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_decorator_list, value) == |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2398 | -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2399 | goto failed; |
| 2400 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2401 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 2402 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2403 | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2404 | goto failed; |
| 2405 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2406 | break; |
| 2407 | case ClassDef_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2408 | result = PyType_GenericNew(ClassDef_type, NULL, NULL); |
| 2409 | if (!result) goto failed; |
| 2410 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 2411 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2412 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2413 | goto failed; |
| 2414 | Py_DECREF(value); |
| 2415 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 2416 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2417 | if (_PyObject_SetAttrId(result, &PyId_bases, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2418 | goto failed; |
| 2419 | Py_DECREF(value); |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 2420 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 2421 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2422 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 2423 | goto failed; |
| 2424 | Py_DECREF(value); |
| 2425 | value = ast2obj_expr(o->v.ClassDef.starargs); |
| 2426 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2427 | if (_PyObject_SetAttrId(result, &PyId_starargs, value) == -1) |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 2428 | goto failed; |
| 2429 | Py_DECREF(value); |
| 2430 | value = ast2obj_expr(o->v.ClassDef.kwargs); |
| 2431 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2432 | if (_PyObject_SetAttrId(result, &PyId_kwargs, value) == -1) |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 2433 | goto failed; |
| 2434 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2435 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 2436 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2437 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2438 | goto failed; |
| 2439 | Py_DECREF(value); |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2440 | value = ast2obj_list(o->v.ClassDef.decorator_list, |
| 2441 | ast2obj_expr); |
| 2442 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2443 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2444 | -1) |
| 2445 | goto failed; |
| 2446 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2447 | break; |
| 2448 | case Return_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2449 | result = PyType_GenericNew(Return_type, NULL, NULL); |
| 2450 | if (!result) goto failed; |
| 2451 | value = ast2obj_expr(o->v.Return.value); |
| 2452 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2453 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2454 | goto failed; |
| 2455 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2456 | break; |
| 2457 | case Delete_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2458 | result = PyType_GenericNew(Delete_type, NULL, NULL); |
| 2459 | if (!result) goto failed; |
| 2460 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 2461 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2462 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2463 | goto failed; |
| 2464 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2465 | break; |
| 2466 | case Assign_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2467 | result = PyType_GenericNew(Assign_type, NULL, NULL); |
| 2468 | if (!result) goto failed; |
| 2469 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 2470 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2471 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2472 | goto failed; |
| 2473 | Py_DECREF(value); |
| 2474 | value = ast2obj_expr(o->v.Assign.value); |
| 2475 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2476 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2477 | goto failed; |
| 2478 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2479 | break; |
| 2480 | case AugAssign_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2481 | result = PyType_GenericNew(AugAssign_type, NULL, NULL); |
| 2482 | if (!result) goto failed; |
| 2483 | value = ast2obj_expr(o->v.AugAssign.target); |
| 2484 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2485 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2486 | goto failed; |
| 2487 | Py_DECREF(value); |
| 2488 | value = ast2obj_operator(o->v.AugAssign.op); |
| 2489 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2490 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2491 | goto failed; |
| 2492 | Py_DECREF(value); |
| 2493 | value = ast2obj_expr(o->v.AugAssign.value); |
| 2494 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2495 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2496 | goto failed; |
| 2497 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2498 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2499 | case For_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2500 | result = PyType_GenericNew(For_type, NULL, NULL); |
| 2501 | if (!result) goto failed; |
| 2502 | value = ast2obj_expr(o->v.For.target); |
| 2503 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2504 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2505 | goto failed; |
| 2506 | Py_DECREF(value); |
| 2507 | value = ast2obj_expr(o->v.For.iter); |
| 2508 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2509 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2510 | goto failed; |
| 2511 | Py_DECREF(value); |
| 2512 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 2513 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2514 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2515 | goto failed; |
| 2516 | Py_DECREF(value); |
| 2517 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 2518 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2519 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2520 | goto failed; |
| 2521 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2522 | break; |
| 2523 | case While_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2524 | result = PyType_GenericNew(While_type, NULL, NULL); |
| 2525 | if (!result) goto failed; |
| 2526 | value = ast2obj_expr(o->v.While.test); |
| 2527 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2528 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2529 | goto failed; |
| 2530 | Py_DECREF(value); |
| 2531 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 2532 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2533 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2534 | goto failed; |
| 2535 | Py_DECREF(value); |
| 2536 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 2537 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2538 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2539 | goto failed; |
| 2540 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2541 | break; |
| 2542 | case If_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2543 | result = PyType_GenericNew(If_type, NULL, NULL); |
| 2544 | if (!result) goto failed; |
| 2545 | value = ast2obj_expr(o->v.If.test); |
| 2546 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2547 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2548 | goto failed; |
| 2549 | Py_DECREF(value); |
| 2550 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 2551 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2552 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2553 | goto failed; |
| 2554 | Py_DECREF(value); |
| 2555 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 2556 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2557 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2558 | goto failed; |
| 2559 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2560 | break; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2561 | case With_kind: |
| 2562 | result = PyType_GenericNew(With_type, NULL, NULL); |
| 2563 | if (!result) goto failed; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2564 | value = ast2obj_list(o->v.With.items, ast2obj_withitem); |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2565 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2566 | if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2567 | goto failed; |
| 2568 | Py_DECREF(value); |
| 2569 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 2570 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2571 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2572 | goto failed; |
| 2573 | Py_DECREF(value); |
| 2574 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2575 | case Raise_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2576 | result = PyType_GenericNew(Raise_type, NULL, NULL); |
| 2577 | if (!result) goto failed; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2578 | value = ast2obj_expr(o->v.Raise.exc); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2579 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2580 | if (_PyObject_SetAttrId(result, &PyId_exc, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2581 | goto failed; |
| 2582 | Py_DECREF(value); |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2583 | value = ast2obj_expr(o->v.Raise.cause); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 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_cause, 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; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2589 | case Try_kind: |
| 2590 | result = PyType_GenericNew(Try_type, NULL, NULL); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2591 | if (!result) goto failed; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2592 | value = ast2obj_list(o->v.Try.body, ast2obj_stmt); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2593 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2594 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2595 | goto failed; |
| 2596 | Py_DECREF(value); |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2597 | value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2598 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2599 | if (_PyObject_SetAttrId(result, &PyId_handlers, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2600 | goto failed; |
| 2601 | Py_DECREF(value); |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2602 | value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 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_orelse, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2605 | goto failed; |
| 2606 | Py_DECREF(value); |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2607 | value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 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_finalbody, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2610 | goto failed; |
| 2611 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2612 | break; |
| 2613 | case Assert_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2614 | result = PyType_GenericNew(Assert_type, NULL, NULL); |
| 2615 | if (!result) goto failed; |
| 2616 | value = ast2obj_expr(o->v.Assert.test); |
| 2617 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2618 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2619 | goto failed; |
| 2620 | Py_DECREF(value); |
| 2621 | value = ast2obj_expr(o->v.Assert.msg); |
| 2622 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2623 | if (_PyObject_SetAttrId(result, &PyId_msg, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2624 | goto failed; |
| 2625 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2626 | break; |
| 2627 | case Import_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2628 | result = PyType_GenericNew(Import_type, NULL, NULL); |
| 2629 | if (!result) goto failed; |
| 2630 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 2631 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2632 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2633 | goto failed; |
| 2634 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2635 | break; |
| 2636 | case ImportFrom_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2637 | result = PyType_GenericNew(ImportFrom_type, NULL, NULL); |
| 2638 | if (!result) goto failed; |
| 2639 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 2640 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2641 | if (_PyObject_SetAttrId(result, &PyId_module, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2642 | goto failed; |
| 2643 | Py_DECREF(value); |
| 2644 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 2645 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2646 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2647 | goto failed; |
| 2648 | Py_DECREF(value); |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 2649 | value = ast2obj_int(o->v.ImportFrom.level); |
| 2650 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2651 | if (_PyObject_SetAttrId(result, &PyId_level, value) == -1) |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 2652 | goto failed; |
| 2653 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2654 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2655 | case Global_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2656 | result = PyType_GenericNew(Global_type, NULL, NULL); |
| 2657 | if (!result) goto failed; |
| 2658 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 2659 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2660 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2661 | goto failed; |
| 2662 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2663 | break; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2664 | case Nonlocal_kind: |
| 2665 | result = PyType_GenericNew(Nonlocal_type, NULL, NULL); |
| 2666 | if (!result) goto failed; |
| 2667 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 2668 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2669 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2670 | goto failed; |
| 2671 | Py_DECREF(value); |
| 2672 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2673 | case Expr_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2674 | result = PyType_GenericNew(Expr_type, NULL, NULL); |
| 2675 | if (!result) goto failed; |
| 2676 | value = ast2obj_expr(o->v.Expr.value); |
| 2677 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2678 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2679 | goto failed; |
| 2680 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2681 | break; |
| 2682 | case Pass_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2683 | result = PyType_GenericNew(Pass_type, NULL, NULL); |
| 2684 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2685 | break; |
| 2686 | case Break_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2687 | result = PyType_GenericNew(Break_type, NULL, NULL); |
| 2688 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2689 | break; |
| 2690 | case Continue_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2691 | result = PyType_GenericNew(Continue_type, NULL, NULL); |
| 2692 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2693 | break; |
| 2694 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2695 | value = ast2obj_int(o->lineno); |
| 2696 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2697 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2698 | goto failed; |
| 2699 | Py_DECREF(value); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2700 | value = ast2obj_int(o->col_offset); |
| 2701 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2702 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2703 | goto failed; |
| 2704 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2705 | return result; |
| 2706 | failed: |
| 2707 | Py_XDECREF(value); |
| 2708 | Py_XDECREF(result); |
| 2709 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2710 | } |
| 2711 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2712 | PyObject* |
| 2713 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2714 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2715 | expr_ty o = (expr_ty)_o; |
| 2716 | PyObject *result = NULL, *value = NULL; |
| 2717 | if (!o) { |
| 2718 | Py_INCREF(Py_None); |
| 2719 | return Py_None; |
| 2720 | } |
| 2721 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2722 | switch (o->kind) { |
| 2723 | case BoolOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2724 | result = PyType_GenericNew(BoolOp_type, NULL, NULL); |
| 2725 | if (!result) goto failed; |
| 2726 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 2727 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2728 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2729 | goto failed; |
| 2730 | Py_DECREF(value); |
| 2731 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 2732 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2733 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2734 | goto failed; |
| 2735 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2736 | break; |
| 2737 | case BinOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2738 | result = PyType_GenericNew(BinOp_type, NULL, NULL); |
| 2739 | if (!result) goto failed; |
| 2740 | value = ast2obj_expr(o->v.BinOp.left); |
| 2741 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2742 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2743 | goto failed; |
| 2744 | Py_DECREF(value); |
| 2745 | value = ast2obj_operator(o->v.BinOp.op); |
| 2746 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2747 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2748 | goto failed; |
| 2749 | Py_DECREF(value); |
| 2750 | value = ast2obj_expr(o->v.BinOp.right); |
| 2751 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2752 | if (_PyObject_SetAttrId(result, &PyId_right, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2753 | goto failed; |
| 2754 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2755 | break; |
| 2756 | case UnaryOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2757 | result = PyType_GenericNew(UnaryOp_type, NULL, NULL); |
| 2758 | if (!result) goto failed; |
| 2759 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 2760 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2761 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2762 | goto failed; |
| 2763 | Py_DECREF(value); |
| 2764 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 2765 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2766 | if (_PyObject_SetAttrId(result, &PyId_operand, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2767 | goto failed; |
| 2768 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2769 | break; |
| 2770 | case Lambda_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2771 | result = PyType_GenericNew(Lambda_type, NULL, NULL); |
| 2772 | if (!result) goto failed; |
| 2773 | value = ast2obj_arguments(o->v.Lambda.args); |
| 2774 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2775 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2776 | goto failed; |
| 2777 | Py_DECREF(value); |
| 2778 | value = ast2obj_expr(o->v.Lambda.body); |
| 2779 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2780 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2781 | goto failed; |
| 2782 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2783 | break; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2784 | case IfExp_kind: |
| 2785 | result = PyType_GenericNew(IfExp_type, NULL, NULL); |
| 2786 | if (!result) goto failed; |
| 2787 | value = ast2obj_expr(o->v.IfExp.test); |
| 2788 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2789 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2790 | goto failed; |
| 2791 | Py_DECREF(value); |
| 2792 | value = ast2obj_expr(o->v.IfExp.body); |
| 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_body, value) == -1) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2795 | goto failed; |
| 2796 | Py_DECREF(value); |
| 2797 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 2798 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2799 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2800 | goto failed; |
| 2801 | Py_DECREF(value); |
| 2802 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2803 | case Dict_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2804 | result = PyType_GenericNew(Dict_type, NULL, NULL); |
| 2805 | if (!result) goto failed; |
| 2806 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 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_keys, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2809 | goto failed; |
| 2810 | Py_DECREF(value); |
| 2811 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 2812 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2813 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2814 | goto failed; |
| 2815 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2816 | break; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2817 | case Set_kind: |
| 2818 | result = PyType_GenericNew(Set_type, NULL, NULL); |
| 2819 | if (!result) goto failed; |
| 2820 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 2821 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2822 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2823 | goto failed; |
| 2824 | Py_DECREF(value); |
| 2825 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2826 | case ListComp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2827 | result = PyType_GenericNew(ListComp_type, NULL, NULL); |
| 2828 | if (!result) goto failed; |
| 2829 | value = ast2obj_expr(o->v.ListComp.elt); |
| 2830 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2831 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2832 | goto failed; |
| 2833 | Py_DECREF(value); |
| 2834 | value = ast2obj_list(o->v.ListComp.generators, |
| 2835 | ast2obj_comprehension); |
| 2836 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2837 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2838 | goto failed; |
| 2839 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2840 | break; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2841 | case SetComp_kind: |
| 2842 | result = PyType_GenericNew(SetComp_type, NULL, NULL); |
| 2843 | if (!result) goto failed; |
| 2844 | value = ast2obj_expr(o->v.SetComp.elt); |
| 2845 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2846 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2847 | goto failed; |
| 2848 | Py_DECREF(value); |
| 2849 | value = ast2obj_list(o->v.SetComp.generators, |
| 2850 | ast2obj_comprehension); |
| 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_generators, value) == -1) |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2853 | goto failed; |
| 2854 | Py_DECREF(value); |
| 2855 | break; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2856 | case DictComp_kind: |
| 2857 | result = PyType_GenericNew(DictComp_type, NULL, NULL); |
| 2858 | if (!result) goto failed; |
| 2859 | value = ast2obj_expr(o->v.DictComp.key); |
| 2860 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2861 | if (_PyObject_SetAttrId(result, &PyId_key, value) == -1) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2862 | goto failed; |
| 2863 | Py_DECREF(value); |
| 2864 | value = ast2obj_expr(o->v.DictComp.value); |
| 2865 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2866 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2867 | goto failed; |
| 2868 | Py_DECREF(value); |
| 2869 | value = ast2obj_list(o->v.DictComp.generators, |
| 2870 | ast2obj_comprehension); |
| 2871 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2872 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2873 | goto failed; |
| 2874 | Py_DECREF(value); |
| 2875 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2876 | case GeneratorExp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2877 | result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); |
| 2878 | if (!result) goto failed; |
| 2879 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 2880 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2881 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2882 | goto failed; |
| 2883 | Py_DECREF(value); |
| 2884 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 2885 | ast2obj_comprehension); |
| 2886 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2887 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2888 | goto failed; |
| 2889 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2890 | break; |
| 2891 | case Yield_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2892 | result = PyType_GenericNew(Yield_type, NULL, NULL); |
| 2893 | if (!result) goto failed; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2894 | value = ast2obj_expr(o->v.Yield.value); |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 2895 | if (!value) goto failed; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2896 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 2897 | goto failed; |
| 2898 | Py_DECREF(value); |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2899 | break; |
| 2900 | case YieldFrom_kind: |
| 2901 | result = PyType_GenericNew(YieldFrom_type, NULL, NULL); |
| 2902 | if (!result) goto failed; |
| 2903 | value = ast2obj_expr(o->v.YieldFrom.value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2904 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2905 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2906 | goto failed; |
| 2907 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2908 | break; |
| 2909 | case Compare_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2910 | result = PyType_GenericNew(Compare_type, NULL, NULL); |
| 2911 | if (!result) goto failed; |
| 2912 | value = ast2obj_expr(o->v.Compare.left); |
| 2913 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2914 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2915 | goto failed; |
| 2916 | Py_DECREF(value); |
Martin v. Löwis | ce1d5d2 | 2006-02-26 20:51:25 +0000 | [diff] [blame] | 2917 | { |
Benjamin Peterson | 77fa937 | 2012-05-15 10:10:27 -0700 | [diff] [blame] | 2918 | Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops); |
Martin v. Löwis | ce1d5d2 | 2006-02-26 20:51:25 +0000 | [diff] [blame] | 2919 | value = PyList_New(n); |
| 2920 | if (!value) goto failed; |
| 2921 | for(i = 0; i < n; i++) |
| 2922 | PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i))); |
| 2923 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2924 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2925 | if (_PyObject_SetAttrId(result, &PyId_ops, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2926 | goto failed; |
| 2927 | Py_DECREF(value); |
| 2928 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
| 2929 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2930 | if (_PyObject_SetAttrId(result, &PyId_comparators, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2931 | goto failed; |
| 2932 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2933 | break; |
| 2934 | case Call_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2935 | result = PyType_GenericNew(Call_type, NULL, NULL); |
| 2936 | if (!result) goto failed; |
| 2937 | value = ast2obj_expr(o->v.Call.func); |
| 2938 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2939 | if (_PyObject_SetAttrId(result, &PyId_func, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2940 | goto failed; |
| 2941 | Py_DECREF(value); |
| 2942 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 2943 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2944 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2945 | goto failed; |
| 2946 | Py_DECREF(value); |
| 2947 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 2948 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2949 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2950 | goto failed; |
| 2951 | Py_DECREF(value); |
| 2952 | value = ast2obj_expr(o->v.Call.starargs); |
| 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_starargs, 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(o->v.Call.kwargs); |
| 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_kwargs, 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; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2963 | case Num_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2964 | result = PyType_GenericNew(Num_type, NULL, NULL); |
| 2965 | if (!result) goto failed; |
| 2966 | value = ast2obj_object(o->v.Num.n); |
| 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_n, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2969 | goto failed; |
| 2970 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2971 | break; |
| 2972 | case Str_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2973 | result = PyType_GenericNew(Str_type, NULL, NULL); |
| 2974 | if (!result) goto failed; |
| 2975 | value = ast2obj_string(o->v.Str.s); |
| 2976 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2977 | if (_PyObject_SetAttrId(result, &PyId_s, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2978 | goto failed; |
| 2979 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2980 | break; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 2981 | case Bytes_kind: |
| 2982 | result = PyType_GenericNew(Bytes_type, NULL, NULL); |
| 2983 | if (!result) goto failed; |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 2984 | value = ast2obj_bytes(o->v.Bytes.s); |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 2985 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2986 | if (_PyObject_SetAttrId(result, &PyId_s, value) == -1) |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 2987 | goto failed; |
| 2988 | Py_DECREF(value); |
| 2989 | break; |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 2990 | case NameConstant_kind: |
| 2991 | result = PyType_GenericNew(NameConstant_type, NULL, NULL); |
| 2992 | if (!result) goto failed; |
| 2993 | value = ast2obj_singleton(o->v.NameConstant.value); |
| 2994 | if (!value) goto failed; |
| 2995 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2996 | goto failed; |
| 2997 | Py_DECREF(value); |
| 2998 | break; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 2999 | case Ellipsis_kind: |
| 3000 | result = PyType_GenericNew(Ellipsis_type, NULL, NULL); |
| 3001 | if (!result) goto failed; |
| 3002 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3003 | case Attribute_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3004 | result = PyType_GenericNew(Attribute_type, NULL, NULL); |
| 3005 | if (!result) goto failed; |
| 3006 | value = ast2obj_expr(o->v.Attribute.value); |
| 3007 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3008 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3009 | goto failed; |
| 3010 | Py_DECREF(value); |
| 3011 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 3012 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3013 | if (_PyObject_SetAttrId(result, &PyId_attr, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3014 | goto failed; |
| 3015 | Py_DECREF(value); |
| 3016 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 3017 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3018 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3019 | goto failed; |
| 3020 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3021 | break; |
| 3022 | case Subscript_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3023 | result = PyType_GenericNew(Subscript_type, NULL, NULL); |
| 3024 | if (!result) goto failed; |
| 3025 | value = ast2obj_expr(o->v.Subscript.value); |
| 3026 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3027 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3028 | goto failed; |
| 3029 | Py_DECREF(value); |
| 3030 | value = ast2obj_slice(o->v.Subscript.slice); |
| 3031 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3032 | if (_PyObject_SetAttrId(result, &PyId_slice, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3033 | goto failed; |
| 3034 | Py_DECREF(value); |
| 3035 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 3036 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3037 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3038 | goto failed; |
| 3039 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3040 | break; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 3041 | case Starred_kind: |
| 3042 | result = PyType_GenericNew(Starred_type, NULL, NULL); |
| 3043 | if (!result) goto failed; |
| 3044 | value = ast2obj_expr(o->v.Starred.value); |
| 3045 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3046 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 3047 | goto failed; |
| 3048 | Py_DECREF(value); |
| 3049 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 3050 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3051 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 3052 | goto failed; |
| 3053 | Py_DECREF(value); |
| 3054 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3055 | case Name_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3056 | result = PyType_GenericNew(Name_type, NULL, NULL); |
| 3057 | if (!result) goto failed; |
| 3058 | value = ast2obj_identifier(o->v.Name.id); |
| 3059 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3060 | if (_PyObject_SetAttrId(result, &PyId_id, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3061 | goto failed; |
| 3062 | Py_DECREF(value); |
| 3063 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 3064 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3065 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3066 | goto failed; |
| 3067 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3068 | break; |
| 3069 | case List_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3070 | result = PyType_GenericNew(List_type, NULL, NULL); |
| 3071 | if (!result) goto failed; |
| 3072 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 3073 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3074 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3075 | goto failed; |
| 3076 | Py_DECREF(value); |
| 3077 | value = ast2obj_expr_context(o->v.List.ctx); |
| 3078 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3079 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3080 | goto failed; |
| 3081 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3082 | break; |
| 3083 | case Tuple_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3084 | result = PyType_GenericNew(Tuple_type, NULL, NULL); |
| 3085 | if (!result) goto failed; |
| 3086 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 3087 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3088 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3089 | goto failed; |
| 3090 | Py_DECREF(value); |
| 3091 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 3092 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3093 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3094 | goto failed; |
| 3095 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3096 | break; |
| 3097 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 3098 | value = ast2obj_int(o->lineno); |
| 3099 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3100 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3101 | goto failed; |
| 3102 | Py_DECREF(value); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3103 | value = ast2obj_int(o->col_offset); |
| 3104 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3105 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3106 | goto failed; |
| 3107 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3108 | return result; |
| 3109 | failed: |
| 3110 | Py_XDECREF(value); |
| 3111 | Py_XDECREF(result); |
| 3112 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3113 | } |
| 3114 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3115 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3116 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3117 | switch(o) { |
| 3118 | case Load: |
| 3119 | Py_INCREF(Load_singleton); |
| 3120 | return Load_singleton; |
| 3121 | case Store: |
| 3122 | Py_INCREF(Store_singleton); |
| 3123 | return Store_singleton; |
| 3124 | case Del: |
| 3125 | Py_INCREF(Del_singleton); |
| 3126 | return Del_singleton; |
| 3127 | case AugLoad: |
| 3128 | Py_INCREF(AugLoad_singleton); |
| 3129 | return AugLoad_singleton; |
| 3130 | case AugStore: |
| 3131 | Py_INCREF(AugStore_singleton); |
| 3132 | return AugStore_singleton; |
| 3133 | case Param: |
| 3134 | Py_INCREF(Param_singleton); |
| 3135 | return Param_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3136 | default: |
| 3137 | /* should never happen, but just in case ... */ |
| 3138 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 3139 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3140 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3141 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3142 | PyObject* |
| 3143 | ast2obj_slice(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3144 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3145 | slice_ty o = (slice_ty)_o; |
| 3146 | PyObject *result = NULL, *value = NULL; |
| 3147 | if (!o) { |
| 3148 | Py_INCREF(Py_None); |
| 3149 | return Py_None; |
| 3150 | } |
| 3151 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3152 | switch (o->kind) { |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3153 | case Slice_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3154 | result = PyType_GenericNew(Slice_type, NULL, NULL); |
| 3155 | if (!result) goto failed; |
| 3156 | value = ast2obj_expr(o->v.Slice.lower); |
| 3157 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3158 | if (_PyObject_SetAttrId(result, &PyId_lower, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3159 | goto failed; |
| 3160 | Py_DECREF(value); |
| 3161 | value = ast2obj_expr(o->v.Slice.upper); |
| 3162 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3163 | if (_PyObject_SetAttrId(result, &PyId_upper, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3164 | goto failed; |
| 3165 | Py_DECREF(value); |
| 3166 | value = ast2obj_expr(o->v.Slice.step); |
| 3167 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3168 | if (_PyObject_SetAttrId(result, &PyId_step, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3169 | goto failed; |
| 3170 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3171 | break; |
| 3172 | case ExtSlice_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3173 | result = PyType_GenericNew(ExtSlice_type, NULL, NULL); |
| 3174 | if (!result) goto failed; |
| 3175 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 3176 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3177 | if (_PyObject_SetAttrId(result, &PyId_dims, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3178 | goto failed; |
| 3179 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3180 | break; |
| 3181 | case Index_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3182 | result = PyType_GenericNew(Index_type, NULL, NULL); |
| 3183 | if (!result) goto failed; |
| 3184 | value = ast2obj_expr(o->v.Index.value); |
| 3185 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3186 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3187 | goto failed; |
| 3188 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3189 | break; |
| 3190 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3191 | return result; |
| 3192 | failed: |
| 3193 | Py_XDECREF(value); |
| 3194 | Py_XDECREF(result); |
| 3195 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3196 | } |
| 3197 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3198 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3199 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3200 | switch(o) { |
| 3201 | case And: |
| 3202 | Py_INCREF(And_singleton); |
| 3203 | return And_singleton; |
| 3204 | case Or: |
| 3205 | Py_INCREF(Or_singleton); |
| 3206 | return Or_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3207 | default: |
| 3208 | /* should never happen, but just in case ... */ |
| 3209 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 3210 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3211 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3212 | } |
| 3213 | PyObject* ast2obj_operator(operator_ty o) |
| 3214 | { |
| 3215 | switch(o) { |
| 3216 | case Add: |
| 3217 | Py_INCREF(Add_singleton); |
| 3218 | return Add_singleton; |
| 3219 | case Sub: |
| 3220 | Py_INCREF(Sub_singleton); |
| 3221 | return Sub_singleton; |
| 3222 | case Mult: |
| 3223 | Py_INCREF(Mult_singleton); |
| 3224 | return Mult_singleton; |
| 3225 | case Div: |
| 3226 | Py_INCREF(Div_singleton); |
| 3227 | return Div_singleton; |
| 3228 | case Mod: |
| 3229 | Py_INCREF(Mod_singleton); |
| 3230 | return Mod_singleton; |
| 3231 | case Pow: |
| 3232 | Py_INCREF(Pow_singleton); |
| 3233 | return Pow_singleton; |
| 3234 | case LShift: |
| 3235 | Py_INCREF(LShift_singleton); |
| 3236 | return LShift_singleton; |
| 3237 | case RShift: |
| 3238 | Py_INCREF(RShift_singleton); |
| 3239 | return RShift_singleton; |
| 3240 | case BitOr: |
| 3241 | Py_INCREF(BitOr_singleton); |
| 3242 | return BitOr_singleton; |
| 3243 | case BitXor: |
| 3244 | Py_INCREF(BitXor_singleton); |
| 3245 | return BitXor_singleton; |
| 3246 | case BitAnd: |
| 3247 | Py_INCREF(BitAnd_singleton); |
| 3248 | return BitAnd_singleton; |
| 3249 | case FloorDiv: |
| 3250 | Py_INCREF(FloorDiv_singleton); |
| 3251 | return FloorDiv_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3252 | default: |
| 3253 | /* should never happen, but just in case ... */ |
| 3254 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 3255 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3256 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3257 | } |
| 3258 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 3259 | { |
| 3260 | switch(o) { |
| 3261 | case Invert: |
| 3262 | Py_INCREF(Invert_singleton); |
| 3263 | return Invert_singleton; |
| 3264 | case Not: |
| 3265 | Py_INCREF(Not_singleton); |
| 3266 | return Not_singleton; |
| 3267 | case UAdd: |
| 3268 | Py_INCREF(UAdd_singleton); |
| 3269 | return UAdd_singleton; |
| 3270 | case USub: |
| 3271 | Py_INCREF(USub_singleton); |
| 3272 | return USub_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3273 | default: |
| 3274 | /* should never happen, but just in case ... */ |
| 3275 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 3276 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3277 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3278 | } |
| 3279 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 3280 | { |
| 3281 | switch(o) { |
| 3282 | case Eq: |
| 3283 | Py_INCREF(Eq_singleton); |
| 3284 | return Eq_singleton; |
| 3285 | case NotEq: |
| 3286 | Py_INCREF(NotEq_singleton); |
| 3287 | return NotEq_singleton; |
| 3288 | case Lt: |
| 3289 | Py_INCREF(Lt_singleton); |
| 3290 | return Lt_singleton; |
| 3291 | case LtE: |
| 3292 | Py_INCREF(LtE_singleton); |
| 3293 | return LtE_singleton; |
| 3294 | case Gt: |
| 3295 | Py_INCREF(Gt_singleton); |
| 3296 | return Gt_singleton; |
| 3297 | case GtE: |
| 3298 | Py_INCREF(GtE_singleton); |
| 3299 | return GtE_singleton; |
| 3300 | case Is: |
| 3301 | Py_INCREF(Is_singleton); |
| 3302 | return Is_singleton; |
| 3303 | case IsNot: |
| 3304 | Py_INCREF(IsNot_singleton); |
| 3305 | return IsNot_singleton; |
| 3306 | case In: |
| 3307 | Py_INCREF(In_singleton); |
| 3308 | return In_singleton; |
| 3309 | case NotIn: |
| 3310 | Py_INCREF(NotIn_singleton); |
| 3311 | return NotIn_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3312 | default: |
| 3313 | /* should never happen, but just in case ... */ |
| 3314 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 3315 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3316 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3317 | } |
| 3318 | PyObject* |
| 3319 | ast2obj_comprehension(void* _o) |
| 3320 | { |
| 3321 | comprehension_ty o = (comprehension_ty)_o; |
| 3322 | PyObject *result = NULL, *value = NULL; |
| 3323 | if (!o) { |
| 3324 | Py_INCREF(Py_None); |
| 3325 | return Py_None; |
| 3326 | } |
| 3327 | |
| 3328 | result = PyType_GenericNew(comprehension_type, NULL, NULL); |
| 3329 | if (!result) return NULL; |
| 3330 | value = ast2obj_expr(o->target); |
| 3331 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3332 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3333 | goto failed; |
| 3334 | Py_DECREF(value); |
| 3335 | value = ast2obj_expr(o->iter); |
| 3336 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3337 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3338 | goto failed; |
| 3339 | Py_DECREF(value); |
| 3340 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 3341 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3342 | if (_PyObject_SetAttrId(result, &PyId_ifs, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3343 | goto failed; |
| 3344 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3345 | return result; |
| 3346 | failed: |
| 3347 | Py_XDECREF(value); |
| 3348 | Py_XDECREF(result); |
| 3349 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3350 | } |
| 3351 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3352 | PyObject* |
| 3353 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3354 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3355 | excepthandler_ty o = (excepthandler_ty)_o; |
| 3356 | PyObject *result = NULL, *value = NULL; |
| 3357 | if (!o) { |
| 3358 | Py_INCREF(Py_None); |
| 3359 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3360 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3361 | |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3362 | switch (o->kind) { |
| 3363 | case ExceptHandler_kind: |
| 3364 | result = PyType_GenericNew(ExceptHandler_type, NULL, NULL); |
| 3365 | if (!result) goto failed; |
| 3366 | value = ast2obj_expr(o->v.ExceptHandler.type); |
| 3367 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3368 | if (_PyObject_SetAttrId(result, &PyId_type, value) == -1) |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3369 | goto failed; |
| 3370 | Py_DECREF(value); |
| 3371 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
| 3372 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3373 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3374 | goto failed; |
| 3375 | Py_DECREF(value); |
| 3376 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 3377 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3378 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3379 | goto failed; |
| 3380 | Py_DECREF(value); |
| 3381 | break; |
| 3382 | } |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3383 | value = ast2obj_int(o->lineno); |
| 3384 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3385 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3386 | goto failed; |
| 3387 | Py_DECREF(value); |
| 3388 | value = ast2obj_int(o->col_offset); |
| 3389 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3390 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3391 | goto failed; |
| 3392 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3393 | return result; |
| 3394 | failed: |
| 3395 | Py_XDECREF(value); |
| 3396 | Py_XDECREF(result); |
| 3397 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3398 | } |
| 3399 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3400 | PyObject* |
| 3401 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3402 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3403 | arguments_ty o = (arguments_ty)_o; |
| 3404 | PyObject *result = NULL, *value = NULL; |
| 3405 | if (!o) { |
| 3406 | Py_INCREF(Py_None); |
| 3407 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3408 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3409 | |
| 3410 | result = PyType_GenericNew(arguments_type, NULL, NULL); |
| 3411 | if (!result) return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3412 | value = ast2obj_list(o->args, ast2obj_arg); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3413 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3414 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3415 | goto failed; |
| 3416 | Py_DECREF(value); |
| 3417 | value = ast2obj_identifier(o->vararg); |
| 3418 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3419 | if (_PyObject_SetAttrId(result, &PyId_vararg, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3420 | goto failed; |
| 3421 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3422 | value = ast2obj_expr(o->varargannotation); |
| 3423 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3424 | if (_PyObject_SetAttrId(result, &PyId_varargannotation, value) == -1) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3425 | goto failed; |
| 3426 | Py_DECREF(value); |
| 3427 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 3428 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3429 | if (_PyObject_SetAttrId(result, &PyId_kwonlyargs, value) == -1) |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 3430 | goto failed; |
| 3431 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3432 | value = ast2obj_identifier(o->kwarg); |
| 3433 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3434 | if (_PyObject_SetAttrId(result, &PyId_kwarg, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3435 | goto failed; |
| 3436 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3437 | value = ast2obj_expr(o->kwargannotation); |
| 3438 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3439 | if (_PyObject_SetAttrId(result, &PyId_kwargannotation, value) == -1) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3440 | goto failed; |
| 3441 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3442 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 3443 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3444 | if (_PyObject_SetAttrId(result, &PyId_defaults, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3445 | goto failed; |
| 3446 | Py_DECREF(value); |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 3447 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
| 3448 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3449 | if (_PyObject_SetAttrId(result, &PyId_kw_defaults, value) == -1) |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 3450 | goto failed; |
| 3451 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3452 | return result; |
| 3453 | failed: |
| 3454 | Py_XDECREF(value); |
| 3455 | Py_XDECREF(result); |
| 3456 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3457 | } |
| 3458 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3459 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3460 | ast2obj_arg(void* _o) |
| 3461 | { |
| 3462 | arg_ty o = (arg_ty)_o; |
| 3463 | PyObject *result = NULL, *value = NULL; |
| 3464 | if (!o) { |
| 3465 | Py_INCREF(Py_None); |
| 3466 | return Py_None; |
| 3467 | } |
| 3468 | |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 3469 | result = PyType_GenericNew(arg_type, NULL, NULL); |
| 3470 | if (!result) return NULL; |
| 3471 | value = ast2obj_identifier(o->arg); |
| 3472 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3473 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 3474 | goto failed; |
| 3475 | Py_DECREF(value); |
| 3476 | value = ast2obj_expr(o->annotation); |
| 3477 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3478 | if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 3479 | goto failed; |
| 3480 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3481 | return result; |
| 3482 | failed: |
| 3483 | Py_XDECREF(value); |
| 3484 | Py_XDECREF(result); |
| 3485 | return NULL; |
| 3486 | } |
| 3487 | |
| 3488 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3489 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3490 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3491 | keyword_ty o = (keyword_ty)_o; |
| 3492 | PyObject *result = NULL, *value = NULL; |
| 3493 | if (!o) { |
| 3494 | Py_INCREF(Py_None); |
| 3495 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3496 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3497 | |
| 3498 | result = PyType_GenericNew(keyword_type, NULL, NULL); |
| 3499 | if (!result) return NULL; |
| 3500 | value = ast2obj_identifier(o->arg); |
| 3501 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3502 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3503 | goto failed; |
| 3504 | Py_DECREF(value); |
| 3505 | value = ast2obj_expr(o->value); |
| 3506 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3507 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3508 | goto failed; |
| 3509 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3510 | return result; |
| 3511 | failed: |
| 3512 | Py_XDECREF(value); |
| 3513 | Py_XDECREF(result); |
| 3514 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3515 | } |
| 3516 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3517 | PyObject* |
| 3518 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3519 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3520 | alias_ty o = (alias_ty)_o; |
| 3521 | PyObject *result = NULL, *value = NULL; |
| 3522 | if (!o) { |
| 3523 | Py_INCREF(Py_None); |
| 3524 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3525 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3526 | |
| 3527 | result = PyType_GenericNew(alias_type, NULL, NULL); |
| 3528 | if (!result) return NULL; |
| 3529 | value = ast2obj_identifier(o->name); |
| 3530 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3531 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3532 | goto failed; |
| 3533 | Py_DECREF(value); |
| 3534 | value = ast2obj_identifier(o->asname); |
| 3535 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3536 | if (_PyObject_SetAttrId(result, &PyId_asname, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3537 | goto failed; |
| 3538 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3539 | return result; |
| 3540 | failed: |
| 3541 | Py_XDECREF(value); |
| 3542 | Py_XDECREF(result); |
| 3543 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3544 | } |
| 3545 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3546 | PyObject* |
| 3547 | ast2obj_withitem(void* _o) |
| 3548 | { |
| 3549 | withitem_ty o = (withitem_ty)_o; |
| 3550 | PyObject *result = NULL, *value = NULL; |
| 3551 | if (!o) { |
| 3552 | Py_INCREF(Py_None); |
| 3553 | return Py_None; |
| 3554 | } |
| 3555 | |
| 3556 | result = PyType_GenericNew(withitem_type, NULL, NULL); |
| 3557 | if (!result) return NULL; |
| 3558 | value = ast2obj_expr(o->context_expr); |
| 3559 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3560 | if (_PyObject_SetAttrId(result, &PyId_context_expr, value) == -1) |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3561 | goto failed; |
| 3562 | Py_DECREF(value); |
| 3563 | value = ast2obj_expr(o->optional_vars); |
| 3564 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3565 | if (_PyObject_SetAttrId(result, &PyId_optional_vars, value) == -1) |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3566 | goto failed; |
| 3567 | Py_DECREF(value); |
| 3568 | return result; |
| 3569 | failed: |
| 3570 | Py_XDECREF(value); |
| 3571 | Py_XDECREF(result); |
| 3572 | return NULL; |
| 3573 | } |
| 3574 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3575 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3576 | int |
| 3577 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 3578 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3579 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3580 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 3581 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3582 | |
| 3583 | if (obj == Py_None) { |
| 3584 | *out = NULL; |
| 3585 | return 0; |
| 3586 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3587 | isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type); |
| 3588 | if (isinstance == -1) { |
| 3589 | return 1; |
| 3590 | } |
| 3591 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3592 | asdl_seq* body; |
| 3593 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3594 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3595 | int res; |
| 3596 | Py_ssize_t len; |
| 3597 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3598 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3599 | if (tmp == NULL) goto failed; |
| 3600 | if (!PyList_Check(tmp)) { |
| 3601 | PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3602 | goto failed; |
| 3603 | } |
| 3604 | len = PyList_GET_SIZE(tmp); |
| 3605 | body = asdl_seq_new(len, arena); |
| 3606 | if (body == NULL) goto failed; |
| 3607 | for (i = 0; i < len; i++) { |
| 3608 | stmt_ty value; |
| 3609 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3610 | if (res != 0) goto failed; |
| 3611 | asdl_seq_SET(body, i, value); |
| 3612 | } |
| 3613 | Py_XDECREF(tmp); |
| 3614 | tmp = NULL; |
| 3615 | } else { |
| 3616 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 3617 | return 1; |
| 3618 | } |
| 3619 | *out = Module(body, arena); |
| 3620 | if (*out == NULL) goto failed; |
| 3621 | return 0; |
| 3622 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3623 | isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type); |
| 3624 | if (isinstance == -1) { |
| 3625 | return 1; |
| 3626 | } |
| 3627 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3628 | asdl_seq* body; |
| 3629 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3630 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3631 | int res; |
| 3632 | Py_ssize_t len; |
| 3633 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3634 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3635 | if (tmp == NULL) goto failed; |
| 3636 | if (!PyList_Check(tmp)) { |
| 3637 | PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3638 | goto failed; |
| 3639 | } |
| 3640 | len = PyList_GET_SIZE(tmp); |
| 3641 | body = asdl_seq_new(len, arena); |
| 3642 | if (body == NULL) goto failed; |
| 3643 | for (i = 0; i < len; i++) { |
| 3644 | stmt_ty value; |
| 3645 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3646 | if (res != 0) goto failed; |
| 3647 | asdl_seq_SET(body, i, value); |
| 3648 | } |
| 3649 | Py_XDECREF(tmp); |
| 3650 | tmp = NULL; |
| 3651 | } else { |
| 3652 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 3653 | return 1; |
| 3654 | } |
| 3655 | *out = Interactive(body, arena); |
| 3656 | if (*out == NULL) goto failed; |
| 3657 | return 0; |
| 3658 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3659 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type); |
| 3660 | if (isinstance == -1) { |
| 3661 | return 1; |
| 3662 | } |
| 3663 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3664 | expr_ty body; |
| 3665 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3666 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3667 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3668 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3669 | if (tmp == NULL) goto failed; |
| 3670 | res = obj2ast_expr(tmp, &body, arena); |
| 3671 | if (res != 0) goto failed; |
| 3672 | Py_XDECREF(tmp); |
| 3673 | tmp = NULL; |
| 3674 | } else { |
| 3675 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 3676 | return 1; |
| 3677 | } |
| 3678 | *out = Expression(body, arena); |
| 3679 | if (*out == NULL) goto failed; |
| 3680 | return 0; |
| 3681 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3682 | isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type); |
| 3683 | if (isinstance == -1) { |
| 3684 | return 1; |
| 3685 | } |
| 3686 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3687 | asdl_seq* body; |
| 3688 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3689 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3690 | int res; |
| 3691 | Py_ssize_t len; |
| 3692 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3693 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3694 | if (tmp == NULL) goto failed; |
| 3695 | if (!PyList_Check(tmp)) { |
| 3696 | PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3697 | goto failed; |
| 3698 | } |
| 3699 | len = PyList_GET_SIZE(tmp); |
| 3700 | body = asdl_seq_new(len, arena); |
| 3701 | if (body == NULL) goto failed; |
| 3702 | for (i = 0; i < len; i++) { |
| 3703 | stmt_ty value; |
| 3704 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3705 | if (res != 0) goto failed; |
| 3706 | asdl_seq_SET(body, i, value); |
| 3707 | } |
| 3708 | Py_XDECREF(tmp); |
| 3709 | tmp = NULL; |
| 3710 | } else { |
| 3711 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite"); |
| 3712 | return 1; |
| 3713 | } |
| 3714 | *out = Suite(body, arena); |
| 3715 | if (*out == NULL) goto failed; |
| 3716 | return 0; |
| 3717 | } |
| 3718 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 3719 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
| 3720 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 3721 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3722 | return 1; |
| 3723 | } |
| 3724 | |
| 3725 | int |
| 3726 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 3727 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3728 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3729 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 3730 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3731 | int lineno; |
| 3732 | int col_offset; |
| 3733 | |
| 3734 | if (obj == Py_None) { |
| 3735 | *out = NULL; |
| 3736 | return 0; |
| 3737 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3738 | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3739 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3740 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3741 | if (tmp == NULL) goto failed; |
| 3742 | res = obj2ast_int(tmp, &lineno, arena); |
| 3743 | if (res != 0) goto failed; |
| 3744 | Py_XDECREF(tmp); |
| 3745 | tmp = NULL; |
| 3746 | } else { |
| 3747 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 3748 | return 1; |
| 3749 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3750 | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3751 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3752 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3753 | if (tmp == NULL) goto failed; |
| 3754 | res = obj2ast_int(tmp, &col_offset, arena); |
| 3755 | if (res != 0) goto failed; |
| 3756 | Py_XDECREF(tmp); |
| 3757 | tmp = NULL; |
| 3758 | } else { |
| 3759 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 3760 | return 1; |
| 3761 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3762 | isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type); |
| 3763 | if (isinstance == -1) { |
| 3764 | return 1; |
| 3765 | } |
| 3766 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3767 | identifier name; |
| 3768 | arguments_ty args; |
| 3769 | asdl_seq* body; |
| 3770 | asdl_seq* decorator_list; |
| 3771 | expr_ty returns; |
| 3772 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3773 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3774 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3775 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3776 | if (tmp == NULL) goto failed; |
| 3777 | res = obj2ast_identifier(tmp, &name, arena); |
| 3778 | if (res != 0) goto failed; |
| 3779 | Py_XDECREF(tmp); |
| 3780 | tmp = NULL; |
| 3781 | } else { |
| 3782 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 3783 | return 1; |
| 3784 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3785 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3786 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3787 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3788 | if (tmp == NULL) goto failed; |
| 3789 | res = obj2ast_arguments(tmp, &args, arena); |
| 3790 | if (res != 0) goto failed; |
| 3791 | Py_XDECREF(tmp); |
| 3792 | tmp = NULL; |
| 3793 | } else { |
| 3794 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 3795 | return 1; |
| 3796 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3797 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3798 | int res; |
| 3799 | Py_ssize_t len; |
| 3800 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3801 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3802 | if (tmp == NULL) goto failed; |
| 3803 | if (!PyList_Check(tmp)) { |
| 3804 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3805 | goto failed; |
| 3806 | } |
| 3807 | len = PyList_GET_SIZE(tmp); |
| 3808 | body = asdl_seq_new(len, arena); |
| 3809 | if (body == NULL) goto failed; |
| 3810 | for (i = 0; i < len; i++) { |
| 3811 | stmt_ty value; |
| 3812 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3813 | if (res != 0) goto failed; |
| 3814 | asdl_seq_SET(body, i, value); |
| 3815 | } |
| 3816 | Py_XDECREF(tmp); |
| 3817 | tmp = NULL; |
| 3818 | } else { |
| 3819 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 3820 | return 1; |
| 3821 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3822 | if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3823 | int res; |
| 3824 | Py_ssize_t len; |
| 3825 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3826 | tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3827 | if (tmp == NULL) goto failed; |
| 3828 | if (!PyList_Check(tmp)) { |
| 3829 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3830 | goto failed; |
| 3831 | } |
| 3832 | len = PyList_GET_SIZE(tmp); |
| 3833 | decorator_list = asdl_seq_new(len, arena); |
| 3834 | if (decorator_list == NULL) goto failed; |
| 3835 | for (i = 0; i < len; i++) { |
| 3836 | expr_ty value; |
| 3837 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3838 | if (res != 0) goto failed; |
| 3839 | asdl_seq_SET(decorator_list, i, value); |
| 3840 | } |
| 3841 | Py_XDECREF(tmp); |
| 3842 | tmp = NULL; |
| 3843 | } else { |
| 3844 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 3845 | return 1; |
| 3846 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3847 | if (_PyObject_HasAttrId(obj, &PyId_returns)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3848 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3849 | tmp = _PyObject_GetAttrId(obj, &PyId_returns); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3850 | if (tmp == NULL) goto failed; |
| 3851 | res = obj2ast_expr(tmp, &returns, arena); |
| 3852 | if (res != 0) goto failed; |
| 3853 | Py_XDECREF(tmp); |
| 3854 | tmp = NULL; |
| 3855 | } else { |
| 3856 | returns = NULL; |
| 3857 | } |
| 3858 | *out = FunctionDef(name, args, body, decorator_list, returns, |
| 3859 | lineno, col_offset, arena); |
| 3860 | if (*out == NULL) goto failed; |
| 3861 | return 0; |
| 3862 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3863 | isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type); |
| 3864 | if (isinstance == -1) { |
| 3865 | return 1; |
| 3866 | } |
| 3867 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3868 | identifier name; |
| 3869 | asdl_seq* bases; |
| 3870 | asdl_seq* keywords; |
| 3871 | expr_ty starargs; |
| 3872 | expr_ty kwargs; |
| 3873 | asdl_seq* body; |
| 3874 | asdl_seq* decorator_list; |
| 3875 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3876 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3877 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3878 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3879 | if (tmp == NULL) goto failed; |
| 3880 | res = obj2ast_identifier(tmp, &name, arena); |
| 3881 | if (res != 0) goto failed; |
| 3882 | Py_XDECREF(tmp); |
| 3883 | tmp = NULL; |
| 3884 | } else { |
| 3885 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 3886 | return 1; |
| 3887 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3888 | if (_PyObject_HasAttrId(obj, &PyId_bases)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3889 | int res; |
| 3890 | Py_ssize_t len; |
| 3891 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3892 | tmp = _PyObject_GetAttrId(obj, &PyId_bases); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3893 | if (tmp == NULL) goto failed; |
| 3894 | if (!PyList_Check(tmp)) { |
| 3895 | PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3896 | goto failed; |
| 3897 | } |
| 3898 | len = PyList_GET_SIZE(tmp); |
| 3899 | bases = asdl_seq_new(len, arena); |
| 3900 | if (bases == NULL) goto failed; |
| 3901 | for (i = 0; i < len; i++) { |
| 3902 | expr_ty value; |
| 3903 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3904 | if (res != 0) goto failed; |
| 3905 | asdl_seq_SET(bases, i, value); |
| 3906 | } |
| 3907 | Py_XDECREF(tmp); |
| 3908 | tmp = NULL; |
| 3909 | } else { |
| 3910 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 3911 | return 1; |
| 3912 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3913 | if (_PyObject_HasAttrId(obj, &PyId_keywords)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3914 | int res; |
| 3915 | Py_ssize_t len; |
| 3916 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3917 | tmp = _PyObject_GetAttrId(obj, &PyId_keywords); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3918 | if (tmp == NULL) goto failed; |
| 3919 | if (!PyList_Check(tmp)) { |
| 3920 | PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3921 | goto failed; |
| 3922 | } |
| 3923 | len = PyList_GET_SIZE(tmp); |
| 3924 | keywords = asdl_seq_new(len, arena); |
| 3925 | if (keywords == NULL) goto failed; |
| 3926 | for (i = 0; i < len; i++) { |
| 3927 | keyword_ty value; |
| 3928 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3929 | if (res != 0) goto failed; |
| 3930 | asdl_seq_SET(keywords, i, value); |
| 3931 | } |
| 3932 | Py_XDECREF(tmp); |
| 3933 | tmp = NULL; |
| 3934 | } else { |
| 3935 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 3936 | return 1; |
| 3937 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3938 | if (_PyObject_HasAttrId(obj, &PyId_starargs)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3939 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3940 | tmp = _PyObject_GetAttrId(obj, &PyId_starargs); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3941 | if (tmp == NULL) goto failed; |
| 3942 | res = obj2ast_expr(tmp, &starargs, arena); |
| 3943 | if (res != 0) goto failed; |
| 3944 | Py_XDECREF(tmp); |
| 3945 | tmp = NULL; |
| 3946 | } else { |
| 3947 | starargs = NULL; |
| 3948 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3949 | if (_PyObject_HasAttrId(obj, &PyId_kwargs)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3950 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3951 | tmp = _PyObject_GetAttrId(obj, &PyId_kwargs); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3952 | if (tmp == NULL) goto failed; |
| 3953 | res = obj2ast_expr(tmp, &kwargs, arena); |
| 3954 | if (res != 0) goto failed; |
| 3955 | Py_XDECREF(tmp); |
| 3956 | tmp = NULL; |
| 3957 | } else { |
| 3958 | kwargs = NULL; |
| 3959 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3960 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3961 | int res; |
| 3962 | Py_ssize_t len; |
| 3963 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3964 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3965 | if (tmp == NULL) goto failed; |
| 3966 | if (!PyList_Check(tmp)) { |
| 3967 | PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3968 | goto failed; |
| 3969 | } |
| 3970 | len = PyList_GET_SIZE(tmp); |
| 3971 | body = asdl_seq_new(len, arena); |
| 3972 | if (body == NULL) goto failed; |
| 3973 | for (i = 0; i < len; i++) { |
| 3974 | stmt_ty value; |
| 3975 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3976 | if (res != 0) goto failed; |
| 3977 | asdl_seq_SET(body, i, value); |
| 3978 | } |
| 3979 | Py_XDECREF(tmp); |
| 3980 | tmp = NULL; |
| 3981 | } else { |
| 3982 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 3983 | return 1; |
| 3984 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3985 | if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3986 | int res; |
| 3987 | Py_ssize_t len; |
| 3988 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3989 | tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3990 | if (tmp == NULL) goto failed; |
| 3991 | if (!PyList_Check(tmp)) { |
| 3992 | PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3993 | goto failed; |
| 3994 | } |
| 3995 | len = PyList_GET_SIZE(tmp); |
| 3996 | decorator_list = asdl_seq_new(len, arena); |
| 3997 | if (decorator_list == NULL) goto failed; |
| 3998 | for (i = 0; i < len; i++) { |
| 3999 | expr_ty value; |
| 4000 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4001 | if (res != 0) goto failed; |
| 4002 | asdl_seq_SET(decorator_list, i, value); |
| 4003 | } |
| 4004 | Py_XDECREF(tmp); |
| 4005 | tmp = NULL; |
| 4006 | } else { |
| 4007 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 4008 | return 1; |
| 4009 | } |
| 4010 | *out = ClassDef(name, bases, keywords, starargs, kwargs, body, |
| 4011 | decorator_list, lineno, col_offset, arena); |
| 4012 | if (*out == NULL) goto failed; |
| 4013 | return 0; |
| 4014 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4015 | isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type); |
| 4016 | if (isinstance == -1) { |
| 4017 | return 1; |
| 4018 | } |
| 4019 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4020 | expr_ty value; |
| 4021 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4022 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4023 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4024 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4025 | if (tmp == NULL) goto failed; |
| 4026 | res = obj2ast_expr(tmp, &value, arena); |
| 4027 | if (res != 0) goto failed; |
| 4028 | Py_XDECREF(tmp); |
| 4029 | tmp = NULL; |
| 4030 | } else { |
| 4031 | value = NULL; |
| 4032 | } |
| 4033 | *out = Return(value, lineno, col_offset, arena); |
| 4034 | if (*out == NULL) goto failed; |
| 4035 | return 0; |
| 4036 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4037 | isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type); |
| 4038 | if (isinstance == -1) { |
| 4039 | return 1; |
| 4040 | } |
| 4041 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4042 | asdl_seq* targets; |
| 4043 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4044 | if (_PyObject_HasAttrId(obj, &PyId_targets)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4045 | int res; |
| 4046 | Py_ssize_t len; |
| 4047 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4048 | tmp = _PyObject_GetAttrId(obj, &PyId_targets); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4049 | if (tmp == NULL) goto failed; |
| 4050 | if (!PyList_Check(tmp)) { |
| 4051 | PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4052 | goto failed; |
| 4053 | } |
| 4054 | len = PyList_GET_SIZE(tmp); |
| 4055 | targets = asdl_seq_new(len, arena); |
| 4056 | if (targets == NULL) goto failed; |
| 4057 | for (i = 0; i < len; i++) { |
| 4058 | expr_ty value; |
| 4059 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4060 | if (res != 0) goto failed; |
| 4061 | asdl_seq_SET(targets, i, value); |
| 4062 | } |
| 4063 | Py_XDECREF(tmp); |
| 4064 | tmp = NULL; |
| 4065 | } else { |
| 4066 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 4067 | return 1; |
| 4068 | } |
| 4069 | *out = Delete(targets, lineno, col_offset, arena); |
| 4070 | if (*out == NULL) goto failed; |
| 4071 | return 0; |
| 4072 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4073 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type); |
| 4074 | if (isinstance == -1) { |
| 4075 | return 1; |
| 4076 | } |
| 4077 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4078 | asdl_seq* targets; |
| 4079 | expr_ty value; |
| 4080 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4081 | if (_PyObject_HasAttrId(obj, &PyId_targets)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4082 | int res; |
| 4083 | Py_ssize_t len; |
| 4084 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4085 | tmp = _PyObject_GetAttrId(obj, &PyId_targets); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4086 | if (tmp == NULL) goto failed; |
| 4087 | if (!PyList_Check(tmp)) { |
| 4088 | PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4089 | goto failed; |
| 4090 | } |
| 4091 | len = PyList_GET_SIZE(tmp); |
| 4092 | targets = asdl_seq_new(len, arena); |
| 4093 | if (targets == NULL) goto failed; |
| 4094 | for (i = 0; i < len; i++) { |
| 4095 | expr_ty value; |
| 4096 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4097 | if (res != 0) goto failed; |
| 4098 | asdl_seq_SET(targets, i, value); |
| 4099 | } |
| 4100 | Py_XDECREF(tmp); |
| 4101 | tmp = NULL; |
| 4102 | } else { |
| 4103 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 4104 | return 1; |
| 4105 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4106 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4107 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4108 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4109 | if (tmp == NULL) goto failed; |
| 4110 | res = obj2ast_expr(tmp, &value, arena); |
| 4111 | if (res != 0) goto failed; |
| 4112 | Py_XDECREF(tmp); |
| 4113 | tmp = NULL; |
| 4114 | } else { |
| 4115 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 4116 | return 1; |
| 4117 | } |
| 4118 | *out = Assign(targets, value, lineno, col_offset, arena); |
| 4119 | if (*out == NULL) goto failed; |
| 4120 | return 0; |
| 4121 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4122 | isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type); |
| 4123 | if (isinstance == -1) { |
| 4124 | return 1; |
| 4125 | } |
| 4126 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4127 | expr_ty target; |
| 4128 | operator_ty op; |
| 4129 | expr_ty value; |
| 4130 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4131 | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4132 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4133 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4134 | if (tmp == NULL) goto failed; |
| 4135 | res = obj2ast_expr(tmp, &target, arena); |
| 4136 | if (res != 0) goto failed; |
| 4137 | Py_XDECREF(tmp); |
| 4138 | tmp = NULL; |
| 4139 | } else { |
| 4140 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 4141 | return 1; |
| 4142 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4143 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4144 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4145 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4146 | if (tmp == NULL) goto failed; |
| 4147 | res = obj2ast_operator(tmp, &op, arena); |
| 4148 | if (res != 0) goto failed; |
| 4149 | Py_XDECREF(tmp); |
| 4150 | tmp = NULL; |
| 4151 | } else { |
| 4152 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 4153 | return 1; |
| 4154 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4155 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4156 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4157 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4158 | if (tmp == NULL) goto failed; |
| 4159 | res = obj2ast_expr(tmp, &value, arena); |
| 4160 | if (res != 0) goto failed; |
| 4161 | Py_XDECREF(tmp); |
| 4162 | tmp = NULL; |
| 4163 | } else { |
| 4164 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 4165 | return 1; |
| 4166 | } |
| 4167 | *out = AugAssign(target, op, value, lineno, col_offset, arena); |
| 4168 | if (*out == NULL) goto failed; |
| 4169 | return 0; |
| 4170 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4171 | isinstance = PyObject_IsInstance(obj, (PyObject*)For_type); |
| 4172 | if (isinstance == -1) { |
| 4173 | return 1; |
| 4174 | } |
| 4175 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4176 | expr_ty target; |
| 4177 | expr_ty iter; |
| 4178 | asdl_seq* body; |
| 4179 | asdl_seq* orelse; |
| 4180 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4181 | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4182 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4183 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4184 | if (tmp == NULL) goto failed; |
| 4185 | res = obj2ast_expr(tmp, &target, arena); |
| 4186 | if (res != 0) goto failed; |
| 4187 | Py_XDECREF(tmp); |
| 4188 | tmp = NULL; |
| 4189 | } else { |
| 4190 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 4191 | return 1; |
| 4192 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4193 | if (_PyObject_HasAttrId(obj, &PyId_iter)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4194 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4195 | tmp = _PyObject_GetAttrId(obj, &PyId_iter); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4196 | if (tmp == NULL) goto failed; |
| 4197 | res = obj2ast_expr(tmp, &iter, arena); |
| 4198 | if (res != 0) goto failed; |
| 4199 | Py_XDECREF(tmp); |
| 4200 | tmp = NULL; |
| 4201 | } else { |
| 4202 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 4203 | return 1; |
| 4204 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4205 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4206 | int res; |
| 4207 | Py_ssize_t len; |
| 4208 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4209 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4210 | if (tmp == NULL) goto failed; |
| 4211 | if (!PyList_Check(tmp)) { |
| 4212 | PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4213 | goto failed; |
| 4214 | } |
| 4215 | len = PyList_GET_SIZE(tmp); |
| 4216 | body = asdl_seq_new(len, arena); |
| 4217 | if (body == NULL) goto failed; |
| 4218 | for (i = 0; i < len; i++) { |
| 4219 | stmt_ty value; |
| 4220 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4221 | if (res != 0) goto failed; |
| 4222 | asdl_seq_SET(body, i, value); |
| 4223 | } |
| 4224 | Py_XDECREF(tmp); |
| 4225 | tmp = NULL; |
| 4226 | } else { |
| 4227 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 4228 | return 1; |
| 4229 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4230 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4231 | int res; |
| 4232 | Py_ssize_t len; |
| 4233 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4234 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4235 | if (tmp == NULL) goto failed; |
| 4236 | if (!PyList_Check(tmp)) { |
| 4237 | PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4238 | goto failed; |
| 4239 | } |
| 4240 | len = PyList_GET_SIZE(tmp); |
| 4241 | orelse = asdl_seq_new(len, arena); |
| 4242 | if (orelse == NULL) goto failed; |
| 4243 | for (i = 0; i < len; i++) { |
| 4244 | stmt_ty value; |
| 4245 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4246 | if (res != 0) goto failed; |
| 4247 | asdl_seq_SET(orelse, i, value); |
| 4248 | } |
| 4249 | Py_XDECREF(tmp); |
| 4250 | tmp = NULL; |
| 4251 | } else { |
| 4252 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 4253 | return 1; |
| 4254 | } |
| 4255 | *out = For(target, iter, body, orelse, lineno, col_offset, |
| 4256 | arena); |
| 4257 | if (*out == NULL) goto failed; |
| 4258 | return 0; |
| 4259 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4260 | isinstance = PyObject_IsInstance(obj, (PyObject*)While_type); |
| 4261 | if (isinstance == -1) { |
| 4262 | return 1; |
| 4263 | } |
| 4264 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4265 | expr_ty test; |
| 4266 | asdl_seq* body; |
| 4267 | asdl_seq* orelse; |
| 4268 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4269 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4270 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4271 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4272 | if (tmp == NULL) goto failed; |
| 4273 | res = obj2ast_expr(tmp, &test, arena); |
| 4274 | if (res != 0) goto failed; |
| 4275 | Py_XDECREF(tmp); |
| 4276 | tmp = NULL; |
| 4277 | } else { |
| 4278 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 4279 | return 1; |
| 4280 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4281 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4282 | int res; |
| 4283 | Py_ssize_t len; |
| 4284 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4285 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4286 | if (tmp == NULL) goto failed; |
| 4287 | if (!PyList_Check(tmp)) { |
| 4288 | PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4289 | goto failed; |
| 4290 | } |
| 4291 | len = PyList_GET_SIZE(tmp); |
| 4292 | body = asdl_seq_new(len, arena); |
| 4293 | if (body == NULL) goto failed; |
| 4294 | for (i = 0; i < len; i++) { |
| 4295 | stmt_ty value; |
| 4296 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4297 | if (res != 0) goto failed; |
| 4298 | asdl_seq_SET(body, i, value); |
| 4299 | } |
| 4300 | Py_XDECREF(tmp); |
| 4301 | tmp = NULL; |
| 4302 | } else { |
| 4303 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 4304 | return 1; |
| 4305 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4306 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4307 | int res; |
| 4308 | Py_ssize_t len; |
| 4309 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4310 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4311 | if (tmp == NULL) goto failed; |
| 4312 | if (!PyList_Check(tmp)) { |
| 4313 | PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4314 | goto failed; |
| 4315 | } |
| 4316 | len = PyList_GET_SIZE(tmp); |
| 4317 | orelse = asdl_seq_new(len, arena); |
| 4318 | if (orelse == NULL) goto failed; |
| 4319 | for (i = 0; i < len; i++) { |
| 4320 | stmt_ty value; |
| 4321 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4322 | if (res != 0) goto failed; |
| 4323 | asdl_seq_SET(orelse, i, value); |
| 4324 | } |
| 4325 | Py_XDECREF(tmp); |
| 4326 | tmp = NULL; |
| 4327 | } else { |
| 4328 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 4329 | return 1; |
| 4330 | } |
| 4331 | *out = While(test, body, orelse, lineno, col_offset, arena); |
| 4332 | if (*out == NULL) goto failed; |
| 4333 | return 0; |
| 4334 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4335 | isinstance = PyObject_IsInstance(obj, (PyObject*)If_type); |
| 4336 | if (isinstance == -1) { |
| 4337 | return 1; |
| 4338 | } |
| 4339 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4340 | expr_ty test; |
| 4341 | asdl_seq* body; |
| 4342 | asdl_seq* orelse; |
| 4343 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4344 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4345 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4346 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4347 | if (tmp == NULL) goto failed; |
| 4348 | res = obj2ast_expr(tmp, &test, arena); |
| 4349 | if (res != 0) goto failed; |
| 4350 | Py_XDECREF(tmp); |
| 4351 | tmp = NULL; |
| 4352 | } else { |
| 4353 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 4354 | return 1; |
| 4355 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4356 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4357 | int res; |
| 4358 | Py_ssize_t len; |
| 4359 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4360 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4361 | if (tmp == NULL) goto failed; |
| 4362 | if (!PyList_Check(tmp)) { |
| 4363 | PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4364 | goto failed; |
| 4365 | } |
| 4366 | len = PyList_GET_SIZE(tmp); |
| 4367 | body = asdl_seq_new(len, arena); |
| 4368 | if (body == NULL) goto failed; |
| 4369 | for (i = 0; i < len; i++) { |
| 4370 | stmt_ty value; |
| 4371 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4372 | if (res != 0) goto failed; |
| 4373 | asdl_seq_SET(body, i, value); |
| 4374 | } |
| 4375 | Py_XDECREF(tmp); |
| 4376 | tmp = NULL; |
| 4377 | } else { |
| 4378 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 4379 | return 1; |
| 4380 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4381 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4382 | int res; |
| 4383 | Py_ssize_t len; |
| 4384 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4385 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4386 | if (tmp == NULL) goto failed; |
| 4387 | if (!PyList_Check(tmp)) { |
| 4388 | PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4389 | goto failed; |
| 4390 | } |
| 4391 | len = PyList_GET_SIZE(tmp); |
| 4392 | orelse = asdl_seq_new(len, arena); |
| 4393 | if (orelse == NULL) goto failed; |
| 4394 | for (i = 0; i < len; i++) { |
| 4395 | stmt_ty value; |
| 4396 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4397 | if (res != 0) goto failed; |
| 4398 | asdl_seq_SET(orelse, i, value); |
| 4399 | } |
| 4400 | Py_XDECREF(tmp); |
| 4401 | tmp = NULL; |
| 4402 | } else { |
| 4403 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 4404 | return 1; |
| 4405 | } |
| 4406 | *out = If(test, body, orelse, lineno, col_offset, arena); |
| 4407 | if (*out == NULL) goto failed; |
| 4408 | return 0; |
| 4409 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4410 | isinstance = PyObject_IsInstance(obj, (PyObject*)With_type); |
| 4411 | if (isinstance == -1) { |
| 4412 | return 1; |
| 4413 | } |
| 4414 | if (isinstance) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4415 | asdl_seq* items; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4416 | asdl_seq* body; |
| 4417 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4418 | if (_PyObject_HasAttrId(obj, &PyId_items)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4419 | int res; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4420 | Py_ssize_t len; |
| 4421 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4422 | tmp = _PyObject_GetAttrId(obj, &PyId_items); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4423 | if (tmp == NULL) goto failed; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4424 | if (!PyList_Check(tmp)) { |
| 4425 | PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4426 | goto failed; |
| 4427 | } |
| 4428 | len = PyList_GET_SIZE(tmp); |
| 4429 | items = asdl_seq_new(len, arena); |
| 4430 | if (items == NULL) goto failed; |
| 4431 | for (i = 0; i < len; i++) { |
| 4432 | withitem_ty value; |
| 4433 | res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4434 | if (res != 0) goto failed; |
| 4435 | asdl_seq_SET(items, i, value); |
| 4436 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4437 | Py_XDECREF(tmp); |
| 4438 | tmp = NULL; |
| 4439 | } else { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4440 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4441 | return 1; |
| 4442 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4443 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4444 | int res; |
| 4445 | Py_ssize_t len; |
| 4446 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4447 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4448 | if (tmp == NULL) goto failed; |
| 4449 | if (!PyList_Check(tmp)) { |
| 4450 | PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4451 | goto failed; |
| 4452 | } |
| 4453 | len = PyList_GET_SIZE(tmp); |
| 4454 | body = asdl_seq_new(len, arena); |
| 4455 | if (body == NULL) goto failed; |
| 4456 | for (i = 0; i < len; i++) { |
| 4457 | stmt_ty value; |
| 4458 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4459 | if (res != 0) goto failed; |
| 4460 | asdl_seq_SET(body, i, value); |
| 4461 | } |
| 4462 | Py_XDECREF(tmp); |
| 4463 | tmp = NULL; |
| 4464 | } else { |
| 4465 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 4466 | return 1; |
| 4467 | } |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4468 | *out = With(items, body, lineno, col_offset, arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4469 | if (*out == NULL) goto failed; |
| 4470 | return 0; |
| 4471 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4472 | isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type); |
| 4473 | if (isinstance == -1) { |
| 4474 | return 1; |
| 4475 | } |
| 4476 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4477 | expr_ty exc; |
| 4478 | expr_ty cause; |
| 4479 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4480 | if (_PyObject_HasAttrId(obj, &PyId_exc)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4481 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4482 | tmp = _PyObject_GetAttrId(obj, &PyId_exc); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4483 | if (tmp == NULL) goto failed; |
| 4484 | res = obj2ast_expr(tmp, &exc, arena); |
| 4485 | if (res != 0) goto failed; |
| 4486 | Py_XDECREF(tmp); |
| 4487 | tmp = NULL; |
| 4488 | } else { |
| 4489 | exc = NULL; |
| 4490 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4491 | if (_PyObject_HasAttrId(obj, &PyId_cause)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4492 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4493 | tmp = _PyObject_GetAttrId(obj, &PyId_cause); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4494 | if (tmp == NULL) goto failed; |
| 4495 | res = obj2ast_expr(tmp, &cause, arena); |
| 4496 | if (res != 0) goto failed; |
| 4497 | Py_XDECREF(tmp); |
| 4498 | tmp = NULL; |
| 4499 | } else { |
| 4500 | cause = NULL; |
| 4501 | } |
| 4502 | *out = Raise(exc, cause, lineno, col_offset, arena); |
| 4503 | if (*out == NULL) goto failed; |
| 4504 | return 0; |
| 4505 | } |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4506 | isinstance = PyObject_IsInstance(obj, (PyObject*)Try_type); |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4507 | if (isinstance == -1) { |
| 4508 | return 1; |
| 4509 | } |
| 4510 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4511 | asdl_seq* body; |
| 4512 | asdl_seq* handlers; |
| 4513 | asdl_seq* orelse; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4514 | asdl_seq* finalbody; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4515 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4516 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4517 | int res; |
| 4518 | Py_ssize_t len; |
| 4519 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4520 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4521 | if (tmp == NULL) goto failed; |
| 4522 | if (!PyList_Check(tmp)) { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4523 | 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] | 4524 | goto failed; |
| 4525 | } |
| 4526 | len = PyList_GET_SIZE(tmp); |
| 4527 | body = asdl_seq_new(len, arena); |
| 4528 | if (body == NULL) goto failed; |
| 4529 | for (i = 0; i < len; i++) { |
| 4530 | stmt_ty value; |
| 4531 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4532 | if (res != 0) goto failed; |
| 4533 | asdl_seq_SET(body, i, value); |
| 4534 | } |
| 4535 | Py_XDECREF(tmp); |
| 4536 | tmp = NULL; |
| 4537 | } else { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4538 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4539 | return 1; |
| 4540 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4541 | if (_PyObject_HasAttrId(obj, &PyId_handlers)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4542 | int res; |
| 4543 | Py_ssize_t len; |
| 4544 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4545 | tmp = _PyObject_GetAttrId(obj, &PyId_handlers); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4546 | if (tmp == NULL) goto failed; |
| 4547 | if (!PyList_Check(tmp)) { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4548 | 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] | 4549 | goto failed; |
| 4550 | } |
| 4551 | len = PyList_GET_SIZE(tmp); |
| 4552 | handlers = asdl_seq_new(len, arena); |
| 4553 | if (handlers == NULL) goto failed; |
| 4554 | for (i = 0; i < len; i++) { |
| 4555 | excepthandler_ty value; |
| 4556 | res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4557 | if (res != 0) goto failed; |
| 4558 | asdl_seq_SET(handlers, i, value); |
| 4559 | } |
| 4560 | Py_XDECREF(tmp); |
| 4561 | tmp = NULL; |
| 4562 | } else { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4563 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4564 | return 1; |
| 4565 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4566 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4567 | int res; |
| 4568 | Py_ssize_t len; |
| 4569 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4570 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4571 | if (tmp == NULL) goto failed; |
| 4572 | if (!PyList_Check(tmp)) { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4573 | 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] | 4574 | goto failed; |
| 4575 | } |
| 4576 | len = PyList_GET_SIZE(tmp); |
| 4577 | orelse = asdl_seq_new(len, arena); |
| 4578 | if (orelse == NULL) goto failed; |
| 4579 | for (i = 0; i < len; i++) { |
| 4580 | stmt_ty value; |
| 4581 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4582 | if (res != 0) goto failed; |
| 4583 | asdl_seq_SET(orelse, i, value); |
| 4584 | } |
| 4585 | Py_XDECREF(tmp); |
| 4586 | tmp = NULL; |
| 4587 | } else { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4588 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4589 | return 1; |
| 4590 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4591 | if (_PyObject_HasAttrId(obj, &PyId_finalbody)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4592 | int res; |
| 4593 | Py_ssize_t len; |
| 4594 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4595 | tmp = _PyObject_GetAttrId(obj, &PyId_finalbody); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4596 | if (tmp == NULL) goto failed; |
| 4597 | if (!PyList_Check(tmp)) { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4598 | 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] | 4599 | goto failed; |
| 4600 | } |
| 4601 | len = PyList_GET_SIZE(tmp); |
| 4602 | finalbody = asdl_seq_new(len, arena); |
| 4603 | if (finalbody == NULL) goto failed; |
| 4604 | for (i = 0; i < len; i++) { |
| 4605 | stmt_ty value; |
| 4606 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4607 | if (res != 0) goto failed; |
| 4608 | asdl_seq_SET(finalbody, i, value); |
| 4609 | } |
| 4610 | Py_XDECREF(tmp); |
| 4611 | tmp = NULL; |
| 4612 | } else { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4613 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4614 | return 1; |
| 4615 | } |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4616 | *out = Try(body, handlers, orelse, finalbody, lineno, |
| 4617 | col_offset, arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4618 | if (*out == NULL) goto failed; |
| 4619 | return 0; |
| 4620 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4621 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type); |
| 4622 | if (isinstance == -1) { |
| 4623 | return 1; |
| 4624 | } |
| 4625 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4626 | expr_ty test; |
| 4627 | expr_ty msg; |
| 4628 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4629 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4630 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4631 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4632 | if (tmp == NULL) goto failed; |
| 4633 | res = obj2ast_expr(tmp, &test, arena); |
| 4634 | if (res != 0) goto failed; |
| 4635 | Py_XDECREF(tmp); |
| 4636 | tmp = NULL; |
| 4637 | } else { |
| 4638 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 4639 | return 1; |
| 4640 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4641 | if (_PyObject_HasAttrId(obj, &PyId_msg)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4642 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4643 | tmp = _PyObject_GetAttrId(obj, &PyId_msg); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4644 | if (tmp == NULL) goto failed; |
| 4645 | res = obj2ast_expr(tmp, &msg, arena); |
| 4646 | if (res != 0) goto failed; |
| 4647 | Py_XDECREF(tmp); |
| 4648 | tmp = NULL; |
| 4649 | } else { |
| 4650 | msg = NULL; |
| 4651 | } |
| 4652 | *out = Assert(test, msg, lineno, col_offset, arena); |
| 4653 | if (*out == NULL) goto failed; |
| 4654 | return 0; |
| 4655 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4656 | isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type); |
| 4657 | if (isinstance == -1) { |
| 4658 | return 1; |
| 4659 | } |
| 4660 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4661 | asdl_seq* names; |
| 4662 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4663 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4664 | int res; |
| 4665 | Py_ssize_t len; |
| 4666 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4667 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4668 | if (tmp == NULL) goto failed; |
| 4669 | if (!PyList_Check(tmp)) { |
| 4670 | PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4671 | goto failed; |
| 4672 | } |
| 4673 | len = PyList_GET_SIZE(tmp); |
| 4674 | names = asdl_seq_new(len, arena); |
| 4675 | if (names == NULL) goto failed; |
| 4676 | for (i = 0; i < len; i++) { |
| 4677 | alias_ty value; |
| 4678 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4679 | if (res != 0) goto failed; |
| 4680 | asdl_seq_SET(names, i, value); |
| 4681 | } |
| 4682 | Py_XDECREF(tmp); |
| 4683 | tmp = NULL; |
| 4684 | } else { |
| 4685 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 4686 | return 1; |
| 4687 | } |
| 4688 | *out = Import(names, lineno, col_offset, arena); |
| 4689 | if (*out == NULL) goto failed; |
| 4690 | return 0; |
| 4691 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4692 | isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type); |
| 4693 | if (isinstance == -1) { |
| 4694 | return 1; |
| 4695 | } |
| 4696 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4697 | identifier module; |
| 4698 | asdl_seq* names; |
| 4699 | int level; |
| 4700 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4701 | if (_PyObject_HasAttrId(obj, &PyId_module)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4702 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4703 | tmp = _PyObject_GetAttrId(obj, &PyId_module); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4704 | if (tmp == NULL) goto failed; |
| 4705 | res = obj2ast_identifier(tmp, &module, arena); |
| 4706 | if (res != 0) goto failed; |
| 4707 | Py_XDECREF(tmp); |
| 4708 | tmp = NULL; |
| 4709 | } else { |
Benjamin Peterson | 78565b2 | 2009-06-28 19:19:51 +0000 | [diff] [blame] | 4710 | module = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4711 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4712 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4713 | int res; |
| 4714 | Py_ssize_t len; |
| 4715 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4716 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4717 | if (tmp == NULL) goto failed; |
| 4718 | if (!PyList_Check(tmp)) { |
| 4719 | PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4720 | goto failed; |
| 4721 | } |
| 4722 | len = PyList_GET_SIZE(tmp); |
| 4723 | names = asdl_seq_new(len, arena); |
| 4724 | if (names == NULL) goto failed; |
| 4725 | for (i = 0; i < len; i++) { |
| 4726 | alias_ty value; |
| 4727 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4728 | if (res != 0) goto failed; |
| 4729 | asdl_seq_SET(names, i, value); |
| 4730 | } |
| 4731 | Py_XDECREF(tmp); |
| 4732 | tmp = NULL; |
| 4733 | } else { |
| 4734 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 4735 | return 1; |
| 4736 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4737 | if (_PyObject_HasAttrId(obj, &PyId_level)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4738 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4739 | tmp = _PyObject_GetAttrId(obj, &PyId_level); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4740 | if (tmp == NULL) goto failed; |
| 4741 | res = obj2ast_int(tmp, &level, arena); |
| 4742 | if (res != 0) goto failed; |
| 4743 | Py_XDECREF(tmp); |
| 4744 | tmp = NULL; |
| 4745 | } else { |
| 4746 | level = 0; |
| 4747 | } |
| 4748 | *out = ImportFrom(module, names, level, lineno, col_offset, |
| 4749 | arena); |
| 4750 | if (*out == NULL) goto failed; |
| 4751 | return 0; |
| 4752 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4753 | isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type); |
| 4754 | if (isinstance == -1) { |
| 4755 | return 1; |
| 4756 | } |
| 4757 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4758 | asdl_seq* names; |
| 4759 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4760 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4761 | int res; |
| 4762 | Py_ssize_t len; |
| 4763 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4764 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4765 | if (tmp == NULL) goto failed; |
| 4766 | if (!PyList_Check(tmp)) { |
| 4767 | PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4768 | goto failed; |
| 4769 | } |
| 4770 | len = PyList_GET_SIZE(tmp); |
| 4771 | names = asdl_seq_new(len, arena); |
| 4772 | if (names == NULL) goto failed; |
| 4773 | for (i = 0; i < len; i++) { |
| 4774 | identifier value; |
| 4775 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4776 | if (res != 0) goto failed; |
| 4777 | asdl_seq_SET(names, i, value); |
| 4778 | } |
| 4779 | Py_XDECREF(tmp); |
| 4780 | tmp = NULL; |
| 4781 | } else { |
| 4782 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 4783 | return 1; |
| 4784 | } |
| 4785 | *out = Global(names, lineno, col_offset, arena); |
| 4786 | if (*out == NULL) goto failed; |
| 4787 | return 0; |
| 4788 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4789 | isinstance = PyObject_IsInstance(obj, (PyObject*)Nonlocal_type); |
| 4790 | if (isinstance == -1) { |
| 4791 | return 1; |
| 4792 | } |
| 4793 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4794 | asdl_seq* names; |
| 4795 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4796 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4797 | int res; |
| 4798 | Py_ssize_t len; |
| 4799 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4800 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4801 | if (tmp == NULL) goto failed; |
| 4802 | if (!PyList_Check(tmp)) { |
| 4803 | PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4804 | goto failed; |
| 4805 | } |
| 4806 | len = PyList_GET_SIZE(tmp); |
| 4807 | names = asdl_seq_new(len, arena); |
| 4808 | if (names == NULL) goto failed; |
| 4809 | for (i = 0; i < len; i++) { |
| 4810 | identifier value; |
| 4811 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4812 | if (res != 0) goto failed; |
| 4813 | asdl_seq_SET(names, i, value); |
| 4814 | } |
| 4815 | Py_XDECREF(tmp); |
| 4816 | tmp = NULL; |
| 4817 | } else { |
| 4818 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 4819 | return 1; |
| 4820 | } |
| 4821 | *out = Nonlocal(names, lineno, col_offset, arena); |
| 4822 | if (*out == NULL) goto failed; |
| 4823 | return 0; |
| 4824 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4825 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type); |
| 4826 | if (isinstance == -1) { |
| 4827 | return 1; |
| 4828 | } |
| 4829 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4830 | expr_ty value; |
| 4831 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4832 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4833 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4834 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4835 | if (tmp == NULL) goto failed; |
| 4836 | res = obj2ast_expr(tmp, &value, arena); |
| 4837 | if (res != 0) goto failed; |
| 4838 | Py_XDECREF(tmp); |
| 4839 | tmp = NULL; |
| 4840 | } else { |
| 4841 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 4842 | return 1; |
| 4843 | } |
| 4844 | *out = Expr(value, lineno, col_offset, arena); |
| 4845 | if (*out == NULL) goto failed; |
| 4846 | return 0; |
| 4847 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4848 | isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type); |
| 4849 | if (isinstance == -1) { |
| 4850 | return 1; |
| 4851 | } |
| 4852 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4853 | |
| 4854 | *out = Pass(lineno, col_offset, arena); |
| 4855 | if (*out == NULL) goto failed; |
| 4856 | return 0; |
| 4857 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4858 | isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type); |
| 4859 | if (isinstance == -1) { |
| 4860 | return 1; |
| 4861 | } |
| 4862 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4863 | |
| 4864 | *out = Break(lineno, col_offset, arena); |
| 4865 | if (*out == NULL) goto failed; |
| 4866 | return 0; |
| 4867 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4868 | isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type); |
| 4869 | if (isinstance == -1) { |
| 4870 | return 1; |
| 4871 | } |
| 4872 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4873 | |
| 4874 | *out = Continue(lineno, col_offset, arena); |
| 4875 | if (*out == NULL) goto failed; |
| 4876 | return 0; |
| 4877 | } |
| 4878 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 4879 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
| 4880 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 4881 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4882 | return 1; |
| 4883 | } |
| 4884 | |
| 4885 | int |
| 4886 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 4887 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4888 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4889 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 4890 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4891 | int lineno; |
| 4892 | int col_offset; |
| 4893 | |
| 4894 | if (obj == Py_None) { |
| 4895 | *out = NULL; |
| 4896 | return 0; |
| 4897 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4898 | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
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_lineno); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4901 | if (tmp == NULL) goto failed; |
| 4902 | res = obj2ast_int(tmp, &lineno, arena); |
| 4903 | if (res != 0) goto failed; |
| 4904 | Py_XDECREF(tmp); |
| 4905 | tmp = NULL; |
| 4906 | } else { |
| 4907 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 4908 | return 1; |
| 4909 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4910 | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4911 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4912 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4913 | if (tmp == NULL) goto failed; |
| 4914 | res = obj2ast_int(tmp, &col_offset, arena); |
| 4915 | if (res != 0) goto failed; |
| 4916 | Py_XDECREF(tmp); |
| 4917 | tmp = NULL; |
| 4918 | } else { |
| 4919 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 4920 | return 1; |
| 4921 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4922 | isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type); |
| 4923 | if (isinstance == -1) { |
| 4924 | return 1; |
| 4925 | } |
| 4926 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4927 | boolop_ty op; |
| 4928 | asdl_seq* values; |
| 4929 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4930 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4931 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4932 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4933 | if (tmp == NULL) goto failed; |
| 4934 | res = obj2ast_boolop(tmp, &op, arena); |
| 4935 | if (res != 0) goto failed; |
| 4936 | Py_XDECREF(tmp); |
| 4937 | tmp = NULL; |
| 4938 | } else { |
| 4939 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 4940 | return 1; |
| 4941 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4942 | if (_PyObject_HasAttrId(obj, &PyId_values)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4943 | int res; |
| 4944 | Py_ssize_t len; |
| 4945 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4946 | tmp = _PyObject_GetAttrId(obj, &PyId_values); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4947 | if (tmp == NULL) goto failed; |
| 4948 | if (!PyList_Check(tmp)) { |
| 4949 | PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4950 | goto failed; |
| 4951 | } |
| 4952 | len = PyList_GET_SIZE(tmp); |
| 4953 | values = asdl_seq_new(len, arena); |
| 4954 | if (values == NULL) goto failed; |
| 4955 | for (i = 0; i < len; i++) { |
| 4956 | expr_ty value; |
| 4957 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4958 | if (res != 0) goto failed; |
| 4959 | asdl_seq_SET(values, i, value); |
| 4960 | } |
| 4961 | Py_XDECREF(tmp); |
| 4962 | tmp = NULL; |
| 4963 | } else { |
| 4964 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 4965 | return 1; |
| 4966 | } |
| 4967 | *out = BoolOp(op, values, lineno, col_offset, arena); |
| 4968 | if (*out == NULL) goto failed; |
| 4969 | return 0; |
| 4970 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4971 | isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type); |
| 4972 | if (isinstance == -1) { |
| 4973 | return 1; |
| 4974 | } |
| 4975 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4976 | expr_ty left; |
| 4977 | operator_ty op; |
| 4978 | expr_ty right; |
| 4979 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4980 | if (_PyObject_HasAttrId(obj, &PyId_left)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4981 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4982 | tmp = _PyObject_GetAttrId(obj, &PyId_left); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4983 | if (tmp == NULL) goto failed; |
| 4984 | res = obj2ast_expr(tmp, &left, arena); |
| 4985 | if (res != 0) goto failed; |
| 4986 | Py_XDECREF(tmp); |
| 4987 | tmp = NULL; |
| 4988 | } else { |
| 4989 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 4990 | return 1; |
| 4991 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4992 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4993 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4994 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4995 | if (tmp == NULL) goto failed; |
| 4996 | res = obj2ast_operator(tmp, &op, arena); |
| 4997 | if (res != 0) goto failed; |
| 4998 | Py_XDECREF(tmp); |
| 4999 | tmp = NULL; |
| 5000 | } else { |
| 5001 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 5002 | return 1; |
| 5003 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5004 | if (_PyObject_HasAttrId(obj, &PyId_right)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5005 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5006 | tmp = _PyObject_GetAttrId(obj, &PyId_right); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5007 | if (tmp == NULL) goto failed; |
| 5008 | res = obj2ast_expr(tmp, &right, arena); |
| 5009 | if (res != 0) goto failed; |
| 5010 | Py_XDECREF(tmp); |
| 5011 | tmp = NULL; |
| 5012 | } else { |
| 5013 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 5014 | return 1; |
| 5015 | } |
| 5016 | *out = BinOp(left, op, right, lineno, col_offset, arena); |
| 5017 | if (*out == NULL) goto failed; |
| 5018 | return 0; |
| 5019 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5020 | isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type); |
| 5021 | if (isinstance == -1) { |
| 5022 | return 1; |
| 5023 | } |
| 5024 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5025 | unaryop_ty op; |
| 5026 | expr_ty operand; |
| 5027 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5028 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5029 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5030 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5031 | if (tmp == NULL) goto failed; |
| 5032 | res = obj2ast_unaryop(tmp, &op, arena); |
| 5033 | if (res != 0) goto failed; |
| 5034 | Py_XDECREF(tmp); |
| 5035 | tmp = NULL; |
| 5036 | } else { |
| 5037 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 5038 | return 1; |
| 5039 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5040 | if (_PyObject_HasAttrId(obj, &PyId_operand)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5041 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5042 | tmp = _PyObject_GetAttrId(obj, &PyId_operand); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5043 | if (tmp == NULL) goto failed; |
| 5044 | res = obj2ast_expr(tmp, &operand, arena); |
| 5045 | if (res != 0) goto failed; |
| 5046 | Py_XDECREF(tmp); |
| 5047 | tmp = NULL; |
| 5048 | } else { |
| 5049 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 5050 | return 1; |
| 5051 | } |
| 5052 | *out = UnaryOp(op, operand, lineno, col_offset, arena); |
| 5053 | if (*out == NULL) goto failed; |
| 5054 | return 0; |
| 5055 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5056 | isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type); |
| 5057 | if (isinstance == -1) { |
| 5058 | return 1; |
| 5059 | } |
| 5060 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5061 | arguments_ty args; |
| 5062 | expr_ty body; |
| 5063 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5064 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5065 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5066 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5067 | if (tmp == NULL) goto failed; |
| 5068 | res = obj2ast_arguments(tmp, &args, arena); |
| 5069 | if (res != 0) goto failed; |
| 5070 | Py_XDECREF(tmp); |
| 5071 | tmp = NULL; |
| 5072 | } else { |
| 5073 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 5074 | return 1; |
| 5075 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5076 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5077 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5078 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5079 | if (tmp == NULL) goto failed; |
| 5080 | res = obj2ast_expr(tmp, &body, arena); |
| 5081 | if (res != 0) goto failed; |
| 5082 | Py_XDECREF(tmp); |
| 5083 | tmp = NULL; |
| 5084 | } else { |
| 5085 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 5086 | return 1; |
| 5087 | } |
| 5088 | *out = Lambda(args, body, lineno, col_offset, arena); |
| 5089 | if (*out == NULL) goto failed; |
| 5090 | return 0; |
| 5091 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5092 | isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type); |
| 5093 | if (isinstance == -1) { |
| 5094 | return 1; |
| 5095 | } |
| 5096 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5097 | expr_ty test; |
| 5098 | expr_ty body; |
| 5099 | expr_ty orelse; |
| 5100 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5101 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5102 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5103 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5104 | if (tmp == NULL) goto failed; |
| 5105 | res = obj2ast_expr(tmp, &test, arena); |
| 5106 | if (res != 0) goto failed; |
| 5107 | Py_XDECREF(tmp); |
| 5108 | tmp = NULL; |
| 5109 | } else { |
| 5110 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 5111 | return 1; |
| 5112 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5113 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5114 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5115 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5116 | if (tmp == NULL) goto failed; |
| 5117 | res = obj2ast_expr(tmp, &body, arena); |
| 5118 | if (res != 0) goto failed; |
| 5119 | Py_XDECREF(tmp); |
| 5120 | tmp = NULL; |
| 5121 | } else { |
| 5122 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 5123 | return 1; |
| 5124 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5125 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5126 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5127 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5128 | if (tmp == NULL) goto failed; |
| 5129 | res = obj2ast_expr(tmp, &orelse, arena); |
| 5130 | if (res != 0) goto failed; |
| 5131 | Py_XDECREF(tmp); |
| 5132 | tmp = NULL; |
| 5133 | } else { |
| 5134 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 5135 | return 1; |
| 5136 | } |
| 5137 | *out = IfExp(test, body, orelse, lineno, col_offset, arena); |
| 5138 | if (*out == NULL) goto failed; |
| 5139 | return 0; |
| 5140 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5141 | isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type); |
| 5142 | if (isinstance == -1) { |
| 5143 | return 1; |
| 5144 | } |
| 5145 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5146 | asdl_seq* keys; |
| 5147 | asdl_seq* values; |
| 5148 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5149 | if (_PyObject_HasAttrId(obj, &PyId_keys)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5150 | int res; |
| 5151 | Py_ssize_t len; |
| 5152 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5153 | tmp = _PyObject_GetAttrId(obj, &PyId_keys); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5154 | if (tmp == NULL) goto failed; |
| 5155 | if (!PyList_Check(tmp)) { |
| 5156 | PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5157 | goto failed; |
| 5158 | } |
| 5159 | len = PyList_GET_SIZE(tmp); |
| 5160 | keys = asdl_seq_new(len, arena); |
| 5161 | if (keys == NULL) goto failed; |
| 5162 | for (i = 0; i < len; i++) { |
| 5163 | expr_ty value; |
| 5164 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5165 | if (res != 0) goto failed; |
| 5166 | asdl_seq_SET(keys, i, value); |
| 5167 | } |
| 5168 | Py_XDECREF(tmp); |
| 5169 | tmp = NULL; |
| 5170 | } else { |
| 5171 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 5172 | return 1; |
| 5173 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5174 | if (_PyObject_HasAttrId(obj, &PyId_values)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5175 | int res; |
| 5176 | Py_ssize_t len; |
| 5177 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5178 | tmp = _PyObject_GetAttrId(obj, &PyId_values); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5179 | if (tmp == NULL) goto failed; |
| 5180 | if (!PyList_Check(tmp)) { |
| 5181 | PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5182 | goto failed; |
| 5183 | } |
| 5184 | len = PyList_GET_SIZE(tmp); |
| 5185 | values = asdl_seq_new(len, arena); |
| 5186 | if (values == NULL) goto failed; |
| 5187 | for (i = 0; i < len; i++) { |
| 5188 | expr_ty value; |
| 5189 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5190 | if (res != 0) goto failed; |
| 5191 | asdl_seq_SET(values, i, value); |
| 5192 | } |
| 5193 | Py_XDECREF(tmp); |
| 5194 | tmp = NULL; |
| 5195 | } else { |
| 5196 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 5197 | return 1; |
| 5198 | } |
| 5199 | *out = Dict(keys, values, lineno, col_offset, arena); |
| 5200 | if (*out == NULL) goto failed; |
| 5201 | return 0; |
| 5202 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5203 | isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type); |
| 5204 | if (isinstance == -1) { |
| 5205 | return 1; |
| 5206 | } |
| 5207 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5208 | asdl_seq* elts; |
| 5209 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5210 | if (_PyObject_HasAttrId(obj, &PyId_elts)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5211 | int res; |
| 5212 | Py_ssize_t len; |
| 5213 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5214 | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5215 | if (tmp == NULL) goto failed; |
| 5216 | if (!PyList_Check(tmp)) { |
| 5217 | PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5218 | goto failed; |
| 5219 | } |
| 5220 | len = PyList_GET_SIZE(tmp); |
| 5221 | elts = asdl_seq_new(len, arena); |
| 5222 | if (elts == NULL) goto failed; |
| 5223 | for (i = 0; i < len; i++) { |
| 5224 | expr_ty value; |
| 5225 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5226 | if (res != 0) goto failed; |
| 5227 | asdl_seq_SET(elts, i, value); |
| 5228 | } |
| 5229 | Py_XDECREF(tmp); |
| 5230 | tmp = NULL; |
| 5231 | } else { |
| 5232 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 5233 | return 1; |
| 5234 | } |
| 5235 | *out = Set(elts, lineno, col_offset, arena); |
| 5236 | if (*out == NULL) goto failed; |
| 5237 | return 0; |
| 5238 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5239 | isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type); |
| 5240 | if (isinstance == -1) { |
| 5241 | return 1; |
| 5242 | } |
| 5243 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5244 | expr_ty elt; |
| 5245 | asdl_seq* generators; |
| 5246 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5247 | if (_PyObject_HasAttrId(obj, &PyId_elt)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5248 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5249 | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5250 | if (tmp == NULL) goto failed; |
| 5251 | res = obj2ast_expr(tmp, &elt, arena); |
| 5252 | if (res != 0) goto failed; |
| 5253 | Py_XDECREF(tmp); |
| 5254 | tmp = NULL; |
| 5255 | } else { |
| 5256 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 5257 | return 1; |
| 5258 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5259 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5260 | int res; |
| 5261 | Py_ssize_t len; |
| 5262 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5263 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5264 | if (tmp == NULL) goto failed; |
| 5265 | if (!PyList_Check(tmp)) { |
| 5266 | PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5267 | goto failed; |
| 5268 | } |
| 5269 | len = PyList_GET_SIZE(tmp); |
| 5270 | generators = asdl_seq_new(len, arena); |
| 5271 | if (generators == NULL) goto failed; |
| 5272 | for (i = 0; i < len; i++) { |
| 5273 | comprehension_ty value; |
| 5274 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5275 | if (res != 0) goto failed; |
| 5276 | asdl_seq_SET(generators, i, value); |
| 5277 | } |
| 5278 | Py_XDECREF(tmp); |
| 5279 | tmp = NULL; |
| 5280 | } else { |
| 5281 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 5282 | return 1; |
| 5283 | } |
| 5284 | *out = ListComp(elt, generators, lineno, col_offset, arena); |
| 5285 | if (*out == NULL) goto failed; |
| 5286 | return 0; |
| 5287 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5288 | isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type); |
| 5289 | if (isinstance == -1) { |
| 5290 | return 1; |
| 5291 | } |
| 5292 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5293 | expr_ty elt; |
| 5294 | asdl_seq* generators; |
| 5295 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5296 | if (_PyObject_HasAttrId(obj, &PyId_elt)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5297 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5298 | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5299 | if (tmp == NULL) goto failed; |
| 5300 | res = obj2ast_expr(tmp, &elt, arena); |
| 5301 | if (res != 0) goto failed; |
| 5302 | Py_XDECREF(tmp); |
| 5303 | tmp = NULL; |
| 5304 | } else { |
| 5305 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 5306 | return 1; |
| 5307 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5308 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5309 | int res; |
| 5310 | Py_ssize_t len; |
| 5311 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5312 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5313 | if (tmp == NULL) goto failed; |
| 5314 | if (!PyList_Check(tmp)) { |
| 5315 | PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5316 | goto failed; |
| 5317 | } |
| 5318 | len = PyList_GET_SIZE(tmp); |
| 5319 | generators = asdl_seq_new(len, arena); |
| 5320 | if (generators == NULL) goto failed; |
| 5321 | for (i = 0; i < len; i++) { |
| 5322 | comprehension_ty value; |
| 5323 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5324 | if (res != 0) goto failed; |
| 5325 | asdl_seq_SET(generators, i, value); |
| 5326 | } |
| 5327 | Py_XDECREF(tmp); |
| 5328 | tmp = NULL; |
| 5329 | } else { |
| 5330 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 5331 | return 1; |
| 5332 | } |
| 5333 | *out = SetComp(elt, generators, lineno, col_offset, arena); |
| 5334 | if (*out == NULL) goto failed; |
| 5335 | return 0; |
| 5336 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5337 | isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type); |
| 5338 | if (isinstance == -1) { |
| 5339 | return 1; |
| 5340 | } |
| 5341 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5342 | expr_ty key; |
| 5343 | expr_ty value; |
| 5344 | asdl_seq* generators; |
| 5345 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5346 | if (_PyObject_HasAttrId(obj, &PyId_key)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5347 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5348 | tmp = _PyObject_GetAttrId(obj, &PyId_key); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5349 | if (tmp == NULL) goto failed; |
| 5350 | res = obj2ast_expr(tmp, &key, arena); |
| 5351 | if (res != 0) goto failed; |
| 5352 | Py_XDECREF(tmp); |
| 5353 | tmp = NULL; |
| 5354 | } else { |
| 5355 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 5356 | return 1; |
| 5357 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5358 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5359 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5360 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5361 | if (tmp == NULL) goto failed; |
| 5362 | res = obj2ast_expr(tmp, &value, arena); |
| 5363 | if (res != 0) goto failed; |
| 5364 | Py_XDECREF(tmp); |
| 5365 | tmp = NULL; |
| 5366 | } else { |
| 5367 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 5368 | return 1; |
| 5369 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5370 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5371 | int res; |
| 5372 | Py_ssize_t len; |
| 5373 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5374 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5375 | if (tmp == NULL) goto failed; |
| 5376 | if (!PyList_Check(tmp)) { |
| 5377 | PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5378 | goto failed; |
| 5379 | } |
| 5380 | len = PyList_GET_SIZE(tmp); |
| 5381 | generators = asdl_seq_new(len, arena); |
| 5382 | if (generators == NULL) goto failed; |
| 5383 | for (i = 0; i < len; i++) { |
| 5384 | comprehension_ty value; |
| 5385 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5386 | if (res != 0) goto failed; |
| 5387 | asdl_seq_SET(generators, i, value); |
| 5388 | } |
| 5389 | Py_XDECREF(tmp); |
| 5390 | tmp = NULL; |
| 5391 | } else { |
| 5392 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 5393 | return 1; |
| 5394 | } |
| 5395 | *out = DictComp(key, value, generators, lineno, col_offset, |
| 5396 | arena); |
| 5397 | if (*out == NULL) goto failed; |
| 5398 | return 0; |
| 5399 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5400 | isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type); |
| 5401 | if (isinstance == -1) { |
| 5402 | return 1; |
| 5403 | } |
| 5404 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5405 | expr_ty elt; |
| 5406 | asdl_seq* generators; |
| 5407 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5408 | if (_PyObject_HasAttrId(obj, &PyId_elt)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5409 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5410 | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5411 | if (tmp == NULL) goto failed; |
| 5412 | res = obj2ast_expr(tmp, &elt, arena); |
| 5413 | if (res != 0) goto failed; |
| 5414 | Py_XDECREF(tmp); |
| 5415 | tmp = NULL; |
| 5416 | } else { |
| 5417 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 5418 | return 1; |
| 5419 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5420 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5421 | int res; |
| 5422 | Py_ssize_t len; |
| 5423 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5424 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5425 | if (tmp == NULL) goto failed; |
| 5426 | if (!PyList_Check(tmp)) { |
| 5427 | PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5428 | goto failed; |
| 5429 | } |
| 5430 | len = PyList_GET_SIZE(tmp); |
| 5431 | generators = asdl_seq_new(len, arena); |
| 5432 | if (generators == NULL) goto failed; |
| 5433 | for (i = 0; i < len; i++) { |
| 5434 | comprehension_ty value; |
| 5435 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5436 | if (res != 0) goto failed; |
| 5437 | asdl_seq_SET(generators, i, value); |
| 5438 | } |
| 5439 | Py_XDECREF(tmp); |
| 5440 | tmp = NULL; |
| 5441 | } else { |
| 5442 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 5443 | return 1; |
| 5444 | } |
| 5445 | *out = GeneratorExp(elt, generators, lineno, col_offset, arena); |
| 5446 | if (*out == NULL) goto failed; |
| 5447 | return 0; |
| 5448 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5449 | isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); |
| 5450 | if (isinstance == -1) { |
| 5451 | return 1; |
| 5452 | } |
| 5453 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5454 | expr_ty value; |
| 5455 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5456 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5457 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5458 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5459 | if (tmp == NULL) goto failed; |
| 5460 | res = obj2ast_expr(tmp, &value, arena); |
| 5461 | if (res != 0) goto failed; |
| 5462 | Py_XDECREF(tmp); |
| 5463 | tmp = NULL; |
| 5464 | } else { |
| 5465 | value = NULL; |
| 5466 | } |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 5467 | *out = Yield(value, lineno, col_offset, arena); |
| 5468 | if (*out == NULL) goto failed; |
| 5469 | return 0; |
| 5470 | } |
| 5471 | isinstance = PyObject_IsInstance(obj, (PyObject*)YieldFrom_type); |
| 5472 | if (isinstance == -1) { |
| 5473 | return 1; |
| 5474 | } |
| 5475 | if (isinstance) { |
| 5476 | expr_ty value; |
| 5477 | |
| 5478 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 5479 | int res; |
| 5480 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 5481 | if (tmp == NULL) goto failed; |
| 5482 | res = obj2ast_expr(tmp, &value, arena); |
| 5483 | if (res != 0) goto failed; |
| 5484 | Py_XDECREF(tmp); |
| 5485 | tmp = NULL; |
| 5486 | } else { |
Mark Dickinson | ded35ae | 2012-11-25 14:36:26 +0000 | [diff] [blame] | 5487 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom"); |
| 5488 | return 1; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 5489 | } |
| 5490 | *out = YieldFrom(value, lineno, col_offset, arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5491 | if (*out == NULL) goto failed; |
| 5492 | return 0; |
| 5493 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5494 | isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); |
| 5495 | if (isinstance == -1) { |
| 5496 | return 1; |
| 5497 | } |
| 5498 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5499 | expr_ty left; |
| 5500 | asdl_int_seq* ops; |
| 5501 | asdl_seq* comparators; |
| 5502 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5503 | if (_PyObject_HasAttrId(obj, &PyId_left)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5504 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5505 | tmp = _PyObject_GetAttrId(obj, &PyId_left); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5506 | if (tmp == NULL) goto failed; |
| 5507 | res = obj2ast_expr(tmp, &left, arena); |
| 5508 | if (res != 0) goto failed; |
| 5509 | Py_XDECREF(tmp); |
| 5510 | tmp = NULL; |
| 5511 | } else { |
| 5512 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 5513 | return 1; |
| 5514 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5515 | if (_PyObject_HasAttrId(obj, &PyId_ops)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5516 | int res; |
| 5517 | Py_ssize_t len; |
| 5518 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5519 | tmp = _PyObject_GetAttrId(obj, &PyId_ops); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5520 | if (tmp == NULL) goto failed; |
| 5521 | if (!PyList_Check(tmp)) { |
| 5522 | PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5523 | goto failed; |
| 5524 | } |
| 5525 | len = PyList_GET_SIZE(tmp); |
| 5526 | ops = asdl_int_seq_new(len, arena); |
| 5527 | if (ops == NULL) goto failed; |
| 5528 | for (i = 0; i < len; i++) { |
| 5529 | cmpop_ty value; |
| 5530 | res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5531 | if (res != 0) goto failed; |
| 5532 | asdl_seq_SET(ops, i, value); |
| 5533 | } |
| 5534 | Py_XDECREF(tmp); |
| 5535 | tmp = NULL; |
| 5536 | } else { |
| 5537 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 5538 | return 1; |
| 5539 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5540 | if (_PyObject_HasAttrId(obj, &PyId_comparators)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5541 | int res; |
| 5542 | Py_ssize_t len; |
| 5543 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5544 | tmp = _PyObject_GetAttrId(obj, &PyId_comparators); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5545 | if (tmp == NULL) goto failed; |
| 5546 | if (!PyList_Check(tmp)) { |
| 5547 | PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5548 | goto failed; |
| 5549 | } |
| 5550 | len = PyList_GET_SIZE(tmp); |
| 5551 | comparators = asdl_seq_new(len, arena); |
| 5552 | if (comparators == NULL) goto failed; |
| 5553 | for (i = 0; i < len; i++) { |
| 5554 | expr_ty value; |
| 5555 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5556 | if (res != 0) goto failed; |
| 5557 | asdl_seq_SET(comparators, i, value); |
| 5558 | } |
| 5559 | Py_XDECREF(tmp); |
| 5560 | tmp = NULL; |
| 5561 | } else { |
| 5562 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 5563 | return 1; |
| 5564 | } |
| 5565 | *out = Compare(left, ops, comparators, lineno, col_offset, |
| 5566 | arena); |
| 5567 | if (*out == NULL) goto failed; |
| 5568 | return 0; |
| 5569 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5570 | isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type); |
| 5571 | if (isinstance == -1) { |
| 5572 | return 1; |
| 5573 | } |
| 5574 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5575 | expr_ty func; |
| 5576 | asdl_seq* args; |
| 5577 | asdl_seq* keywords; |
| 5578 | expr_ty starargs; |
| 5579 | expr_ty kwargs; |
| 5580 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5581 | if (_PyObject_HasAttrId(obj, &PyId_func)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5582 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5583 | tmp = _PyObject_GetAttrId(obj, &PyId_func); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5584 | if (tmp == NULL) goto failed; |
| 5585 | res = obj2ast_expr(tmp, &func, arena); |
| 5586 | if (res != 0) goto failed; |
| 5587 | Py_XDECREF(tmp); |
| 5588 | tmp = NULL; |
| 5589 | } else { |
| 5590 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 5591 | return 1; |
| 5592 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5593 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5594 | int res; |
| 5595 | Py_ssize_t len; |
| 5596 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5597 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5598 | if (tmp == NULL) goto failed; |
| 5599 | if (!PyList_Check(tmp)) { |
| 5600 | PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5601 | goto failed; |
| 5602 | } |
| 5603 | len = PyList_GET_SIZE(tmp); |
| 5604 | args = asdl_seq_new(len, arena); |
| 5605 | if (args == NULL) goto failed; |
| 5606 | for (i = 0; i < len; i++) { |
| 5607 | expr_ty value; |
| 5608 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5609 | if (res != 0) goto failed; |
| 5610 | asdl_seq_SET(args, i, value); |
| 5611 | } |
| 5612 | Py_XDECREF(tmp); |
| 5613 | tmp = NULL; |
| 5614 | } else { |
| 5615 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 5616 | return 1; |
| 5617 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5618 | if (_PyObject_HasAttrId(obj, &PyId_keywords)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5619 | int res; |
| 5620 | Py_ssize_t len; |
| 5621 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5622 | tmp = _PyObject_GetAttrId(obj, &PyId_keywords); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5623 | if (tmp == NULL) goto failed; |
| 5624 | if (!PyList_Check(tmp)) { |
| 5625 | PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5626 | goto failed; |
| 5627 | } |
| 5628 | len = PyList_GET_SIZE(tmp); |
| 5629 | keywords = asdl_seq_new(len, arena); |
| 5630 | if (keywords == NULL) goto failed; |
| 5631 | for (i = 0; i < len; i++) { |
| 5632 | keyword_ty value; |
| 5633 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5634 | if (res != 0) goto failed; |
| 5635 | asdl_seq_SET(keywords, i, value); |
| 5636 | } |
| 5637 | Py_XDECREF(tmp); |
| 5638 | tmp = NULL; |
| 5639 | } else { |
| 5640 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 5641 | return 1; |
| 5642 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5643 | if (_PyObject_HasAttrId(obj, &PyId_starargs)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5644 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5645 | tmp = _PyObject_GetAttrId(obj, &PyId_starargs); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5646 | if (tmp == NULL) goto failed; |
| 5647 | res = obj2ast_expr(tmp, &starargs, arena); |
| 5648 | if (res != 0) goto failed; |
| 5649 | Py_XDECREF(tmp); |
| 5650 | tmp = NULL; |
| 5651 | } else { |
| 5652 | starargs = NULL; |
| 5653 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5654 | if (_PyObject_HasAttrId(obj, &PyId_kwargs)) { |
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_kwargs); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5657 | if (tmp == NULL) goto failed; |
| 5658 | res = obj2ast_expr(tmp, &kwargs, arena); |
| 5659 | if (res != 0) goto failed; |
| 5660 | Py_XDECREF(tmp); |
| 5661 | tmp = NULL; |
| 5662 | } else { |
| 5663 | kwargs = NULL; |
| 5664 | } |
| 5665 | *out = Call(func, args, keywords, starargs, kwargs, lineno, |
| 5666 | col_offset, arena); |
| 5667 | if (*out == NULL) goto failed; |
| 5668 | return 0; |
| 5669 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5670 | isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type); |
| 5671 | if (isinstance == -1) { |
| 5672 | return 1; |
| 5673 | } |
| 5674 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5675 | object n; |
| 5676 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5677 | if (_PyObject_HasAttrId(obj, &PyId_n)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5678 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5679 | tmp = _PyObject_GetAttrId(obj, &PyId_n); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5680 | if (tmp == NULL) goto failed; |
| 5681 | res = obj2ast_object(tmp, &n, arena); |
| 5682 | if (res != 0) goto failed; |
| 5683 | Py_XDECREF(tmp); |
| 5684 | tmp = NULL; |
| 5685 | } else { |
| 5686 | PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num"); |
| 5687 | return 1; |
| 5688 | } |
| 5689 | *out = Num(n, lineno, col_offset, arena); |
| 5690 | if (*out == NULL) goto failed; |
| 5691 | return 0; |
| 5692 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5693 | isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type); |
| 5694 | if (isinstance == -1) { |
| 5695 | return 1; |
| 5696 | } |
| 5697 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5698 | string s; |
| 5699 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5700 | if (_PyObject_HasAttrId(obj, &PyId_s)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5701 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5702 | tmp = _PyObject_GetAttrId(obj, &PyId_s); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5703 | if (tmp == NULL) goto failed; |
| 5704 | res = obj2ast_string(tmp, &s, arena); |
| 5705 | if (res != 0) goto failed; |
| 5706 | Py_XDECREF(tmp); |
| 5707 | tmp = NULL; |
| 5708 | } else { |
| 5709 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str"); |
| 5710 | return 1; |
| 5711 | } |
| 5712 | *out = Str(s, lineno, col_offset, arena); |
| 5713 | if (*out == NULL) goto failed; |
| 5714 | return 0; |
| 5715 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5716 | isinstance = PyObject_IsInstance(obj, (PyObject*)Bytes_type); |
| 5717 | if (isinstance == -1) { |
| 5718 | return 1; |
| 5719 | } |
| 5720 | if (isinstance) { |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 5721 | bytes s; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5722 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5723 | if (_PyObject_HasAttrId(obj, &PyId_s)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5724 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5725 | tmp = _PyObject_GetAttrId(obj, &PyId_s); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5726 | if (tmp == NULL) goto failed; |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 5727 | res = obj2ast_bytes(tmp, &s, arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5728 | if (res != 0) goto failed; |
| 5729 | Py_XDECREF(tmp); |
| 5730 | tmp = NULL; |
| 5731 | } else { |
| 5732 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Bytes"); |
| 5733 | return 1; |
| 5734 | } |
| 5735 | *out = Bytes(s, lineno, col_offset, arena); |
| 5736 | if (*out == NULL) goto failed; |
| 5737 | return 0; |
| 5738 | } |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 5739 | isinstance = PyObject_IsInstance(obj, (PyObject*)NameConstant_type); |
| 5740 | if (isinstance == -1) { |
| 5741 | return 1; |
| 5742 | } |
| 5743 | if (isinstance) { |
| 5744 | singleton value; |
| 5745 | |
| 5746 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 5747 | int res; |
| 5748 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 5749 | if (tmp == NULL) goto failed; |
| 5750 | res = obj2ast_singleton(tmp, &value, arena); |
| 5751 | if (res != 0) goto failed; |
| 5752 | Py_XDECREF(tmp); |
| 5753 | tmp = NULL; |
| 5754 | } else { |
| 5755 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NameConstant"); |
| 5756 | return 1; |
| 5757 | } |
| 5758 | *out = NameConstant(value, lineno, col_offset, arena); |
| 5759 | if (*out == NULL) goto failed; |
| 5760 | return 0; |
| 5761 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5762 | isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type); |
| 5763 | if (isinstance == -1) { |
| 5764 | return 1; |
| 5765 | } |
| 5766 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5767 | |
| 5768 | *out = Ellipsis(lineno, col_offset, arena); |
| 5769 | if (*out == NULL) goto failed; |
| 5770 | return 0; |
| 5771 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5772 | isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type); |
| 5773 | if (isinstance == -1) { |
| 5774 | return 1; |
| 5775 | } |
| 5776 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5777 | expr_ty value; |
| 5778 | identifier attr; |
| 5779 | expr_context_ty ctx; |
| 5780 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5781 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5782 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5783 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5784 | if (tmp == NULL) goto failed; |
| 5785 | res = obj2ast_expr(tmp, &value, arena); |
| 5786 | if (res != 0) goto failed; |
| 5787 | Py_XDECREF(tmp); |
| 5788 | tmp = NULL; |
| 5789 | } else { |
| 5790 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 5791 | return 1; |
| 5792 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5793 | if (_PyObject_HasAttrId(obj, &PyId_attr)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5794 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5795 | tmp = _PyObject_GetAttrId(obj, &PyId_attr); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5796 | if (tmp == NULL) goto failed; |
| 5797 | res = obj2ast_identifier(tmp, &attr, arena); |
| 5798 | if (res != 0) goto failed; |
| 5799 | Py_XDECREF(tmp); |
| 5800 | tmp = NULL; |
| 5801 | } else { |
| 5802 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 5803 | return 1; |
| 5804 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5805 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5806 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5807 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5808 | if (tmp == NULL) goto failed; |
| 5809 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5810 | if (res != 0) goto failed; |
| 5811 | Py_XDECREF(tmp); |
| 5812 | tmp = NULL; |
| 5813 | } else { |
| 5814 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 5815 | return 1; |
| 5816 | } |
| 5817 | *out = Attribute(value, attr, ctx, lineno, col_offset, arena); |
| 5818 | if (*out == NULL) goto failed; |
| 5819 | return 0; |
| 5820 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5821 | isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type); |
| 5822 | if (isinstance == -1) { |
| 5823 | return 1; |
| 5824 | } |
| 5825 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5826 | expr_ty value; |
| 5827 | slice_ty slice; |
| 5828 | expr_context_ty ctx; |
| 5829 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5830 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5831 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5832 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5833 | if (tmp == NULL) goto failed; |
| 5834 | res = obj2ast_expr(tmp, &value, arena); |
| 5835 | if (res != 0) goto failed; |
| 5836 | Py_XDECREF(tmp); |
| 5837 | tmp = NULL; |
| 5838 | } else { |
| 5839 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 5840 | return 1; |
| 5841 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5842 | if (_PyObject_HasAttrId(obj, &PyId_slice)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5843 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5844 | tmp = _PyObject_GetAttrId(obj, &PyId_slice); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5845 | if (tmp == NULL) goto failed; |
| 5846 | res = obj2ast_slice(tmp, &slice, arena); |
| 5847 | if (res != 0) goto failed; |
| 5848 | Py_XDECREF(tmp); |
| 5849 | tmp = NULL; |
| 5850 | } else { |
| 5851 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 5852 | return 1; |
| 5853 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5854 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5855 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5856 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5857 | if (tmp == NULL) goto failed; |
| 5858 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5859 | if (res != 0) goto failed; |
| 5860 | Py_XDECREF(tmp); |
| 5861 | tmp = NULL; |
| 5862 | } else { |
| 5863 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 5864 | return 1; |
| 5865 | } |
| 5866 | *out = Subscript(value, slice, ctx, lineno, col_offset, arena); |
| 5867 | if (*out == NULL) goto failed; |
| 5868 | return 0; |
| 5869 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5870 | isinstance = PyObject_IsInstance(obj, (PyObject*)Starred_type); |
| 5871 | if (isinstance == -1) { |
| 5872 | return 1; |
| 5873 | } |
| 5874 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5875 | expr_ty value; |
| 5876 | expr_context_ty ctx; |
| 5877 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5878 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5879 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5880 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5881 | if (tmp == NULL) goto failed; |
| 5882 | res = obj2ast_expr(tmp, &value, arena); |
| 5883 | if (res != 0) goto failed; |
| 5884 | Py_XDECREF(tmp); |
| 5885 | tmp = NULL; |
| 5886 | } else { |
| 5887 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 5888 | return 1; |
| 5889 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5890 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5891 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5892 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5893 | if (tmp == NULL) goto failed; |
| 5894 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5895 | if (res != 0) goto failed; |
| 5896 | Py_XDECREF(tmp); |
| 5897 | tmp = NULL; |
| 5898 | } else { |
| 5899 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 5900 | return 1; |
| 5901 | } |
| 5902 | *out = Starred(value, ctx, lineno, col_offset, arena); |
| 5903 | if (*out == NULL) goto failed; |
| 5904 | return 0; |
| 5905 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5906 | isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type); |
| 5907 | if (isinstance == -1) { |
| 5908 | return 1; |
| 5909 | } |
| 5910 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5911 | identifier id; |
| 5912 | expr_context_ty ctx; |
| 5913 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5914 | if (_PyObject_HasAttrId(obj, &PyId_id)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5915 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5916 | tmp = _PyObject_GetAttrId(obj, &PyId_id); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5917 | if (tmp == NULL) goto failed; |
| 5918 | res = obj2ast_identifier(tmp, &id, arena); |
| 5919 | if (res != 0) goto failed; |
| 5920 | Py_XDECREF(tmp); |
| 5921 | tmp = NULL; |
| 5922 | } else { |
| 5923 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 5924 | return 1; |
| 5925 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5926 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5927 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5928 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5929 | if (tmp == NULL) goto failed; |
| 5930 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5931 | if (res != 0) goto failed; |
| 5932 | Py_XDECREF(tmp); |
| 5933 | tmp = NULL; |
| 5934 | } else { |
| 5935 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 5936 | return 1; |
| 5937 | } |
| 5938 | *out = Name(id, ctx, lineno, col_offset, arena); |
| 5939 | if (*out == NULL) goto failed; |
| 5940 | return 0; |
| 5941 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5942 | isinstance = PyObject_IsInstance(obj, (PyObject*)List_type); |
| 5943 | if (isinstance == -1) { |
| 5944 | return 1; |
| 5945 | } |
| 5946 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5947 | asdl_seq* elts; |
| 5948 | expr_context_ty ctx; |
| 5949 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5950 | if (_PyObject_HasAttrId(obj, &PyId_elts)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5951 | int res; |
| 5952 | Py_ssize_t len; |
| 5953 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5954 | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5955 | if (tmp == NULL) goto failed; |
| 5956 | if (!PyList_Check(tmp)) { |
| 5957 | PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5958 | goto failed; |
| 5959 | } |
| 5960 | len = PyList_GET_SIZE(tmp); |
| 5961 | elts = asdl_seq_new(len, arena); |
| 5962 | if (elts == NULL) goto failed; |
| 5963 | for (i = 0; i < len; i++) { |
| 5964 | expr_ty value; |
| 5965 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5966 | if (res != 0) goto failed; |
| 5967 | asdl_seq_SET(elts, i, value); |
| 5968 | } |
| 5969 | Py_XDECREF(tmp); |
| 5970 | tmp = NULL; |
| 5971 | } else { |
| 5972 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 5973 | return 1; |
| 5974 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5975 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5976 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5977 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5978 | if (tmp == NULL) goto failed; |
| 5979 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5980 | if (res != 0) goto failed; |
| 5981 | Py_XDECREF(tmp); |
| 5982 | tmp = NULL; |
| 5983 | } else { |
| 5984 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 5985 | return 1; |
| 5986 | } |
| 5987 | *out = List(elts, ctx, lineno, col_offset, arena); |
| 5988 | if (*out == NULL) goto failed; |
| 5989 | return 0; |
| 5990 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5991 | isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type); |
| 5992 | if (isinstance == -1) { |
| 5993 | return 1; |
| 5994 | } |
| 5995 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5996 | asdl_seq* elts; |
| 5997 | expr_context_ty ctx; |
| 5998 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5999 | if (_PyObject_HasAttrId(obj, &PyId_elts)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6000 | int res; |
| 6001 | Py_ssize_t len; |
| 6002 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6003 | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6004 | if (tmp == NULL) goto failed; |
| 6005 | if (!PyList_Check(tmp)) { |
| 6006 | PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6007 | goto failed; |
| 6008 | } |
| 6009 | len = PyList_GET_SIZE(tmp); |
| 6010 | elts = asdl_seq_new(len, arena); |
| 6011 | if (elts == NULL) goto failed; |
| 6012 | for (i = 0; i < len; i++) { |
| 6013 | expr_ty value; |
| 6014 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6015 | if (res != 0) goto failed; |
| 6016 | asdl_seq_SET(elts, i, value); |
| 6017 | } |
| 6018 | Py_XDECREF(tmp); |
| 6019 | tmp = NULL; |
| 6020 | } else { |
| 6021 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 6022 | return 1; |
| 6023 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6024 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6025 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6026 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6027 | if (tmp == NULL) goto failed; |
| 6028 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 6029 | if (res != 0) goto failed; |
| 6030 | Py_XDECREF(tmp); |
| 6031 | tmp = NULL; |
| 6032 | } else { |
| 6033 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 6034 | return 1; |
| 6035 | } |
| 6036 | *out = Tuple(elts, ctx, lineno, col_offset, arena); |
| 6037 | if (*out == NULL) goto failed; |
| 6038 | return 0; |
| 6039 | } |
| 6040 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6041 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
| 6042 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 6043 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6044 | return 1; |
| 6045 | } |
| 6046 | |
| 6047 | int |
| 6048 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 6049 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6050 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6051 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6052 | isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); |
| 6053 | if (isinstance == -1) { |
| 6054 | return 1; |
| 6055 | } |
| 6056 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6057 | *out = Load; |
| 6058 | return 0; |
| 6059 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6060 | isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type); |
| 6061 | if (isinstance == -1) { |
| 6062 | return 1; |
| 6063 | } |
| 6064 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6065 | *out = Store; |
| 6066 | return 0; |
| 6067 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6068 | isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type); |
| 6069 | if (isinstance == -1) { |
| 6070 | return 1; |
| 6071 | } |
| 6072 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6073 | *out = Del; |
| 6074 | return 0; |
| 6075 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6076 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type); |
| 6077 | if (isinstance == -1) { |
| 6078 | return 1; |
| 6079 | } |
| 6080 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6081 | *out = AugLoad; |
| 6082 | return 0; |
| 6083 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6084 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type); |
| 6085 | if (isinstance == -1) { |
| 6086 | return 1; |
| 6087 | } |
| 6088 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6089 | *out = AugStore; |
| 6090 | return 0; |
| 6091 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6092 | isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type); |
| 6093 | if (isinstance == -1) { |
| 6094 | return 1; |
| 6095 | } |
| 6096 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6097 | *out = Param; |
| 6098 | return 0; |
| 6099 | } |
| 6100 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6101 | 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] | 6102 | return 1; |
| 6103 | } |
| 6104 | |
| 6105 | int |
| 6106 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
| 6107 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6108 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6109 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 6110 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6111 | |
| 6112 | if (obj == Py_None) { |
| 6113 | *out = NULL; |
| 6114 | return 0; |
| 6115 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6116 | isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type); |
| 6117 | if (isinstance == -1) { |
| 6118 | return 1; |
| 6119 | } |
| 6120 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6121 | expr_ty lower; |
| 6122 | expr_ty upper; |
| 6123 | expr_ty step; |
| 6124 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6125 | if (_PyObject_HasAttrId(obj, &PyId_lower)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6126 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6127 | tmp = _PyObject_GetAttrId(obj, &PyId_lower); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6128 | if (tmp == NULL) goto failed; |
| 6129 | res = obj2ast_expr(tmp, &lower, arena); |
| 6130 | if (res != 0) goto failed; |
| 6131 | Py_XDECREF(tmp); |
| 6132 | tmp = NULL; |
| 6133 | } else { |
| 6134 | lower = NULL; |
| 6135 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6136 | if (_PyObject_HasAttrId(obj, &PyId_upper)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6137 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6138 | tmp = _PyObject_GetAttrId(obj, &PyId_upper); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6139 | if (tmp == NULL) goto failed; |
| 6140 | res = obj2ast_expr(tmp, &upper, arena); |
| 6141 | if (res != 0) goto failed; |
| 6142 | Py_XDECREF(tmp); |
| 6143 | tmp = NULL; |
| 6144 | } else { |
| 6145 | upper = NULL; |
| 6146 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6147 | if (_PyObject_HasAttrId(obj, &PyId_step)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6148 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6149 | tmp = _PyObject_GetAttrId(obj, &PyId_step); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6150 | if (tmp == NULL) goto failed; |
| 6151 | res = obj2ast_expr(tmp, &step, arena); |
| 6152 | if (res != 0) goto failed; |
| 6153 | Py_XDECREF(tmp); |
| 6154 | tmp = NULL; |
| 6155 | } else { |
| 6156 | step = NULL; |
| 6157 | } |
| 6158 | *out = Slice(lower, upper, step, arena); |
| 6159 | if (*out == NULL) goto failed; |
| 6160 | return 0; |
| 6161 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6162 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type); |
| 6163 | if (isinstance == -1) { |
| 6164 | return 1; |
| 6165 | } |
| 6166 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6167 | asdl_seq* dims; |
| 6168 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6169 | if (_PyObject_HasAttrId(obj, &PyId_dims)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6170 | int res; |
| 6171 | Py_ssize_t len; |
| 6172 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6173 | tmp = _PyObject_GetAttrId(obj, &PyId_dims); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6174 | if (tmp == NULL) goto failed; |
| 6175 | if (!PyList_Check(tmp)) { |
| 6176 | PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6177 | goto failed; |
| 6178 | } |
| 6179 | len = PyList_GET_SIZE(tmp); |
| 6180 | dims = asdl_seq_new(len, arena); |
| 6181 | if (dims == NULL) goto failed; |
| 6182 | for (i = 0; i < len; i++) { |
| 6183 | slice_ty value; |
| 6184 | res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6185 | if (res != 0) goto failed; |
| 6186 | asdl_seq_SET(dims, i, value); |
| 6187 | } |
| 6188 | Py_XDECREF(tmp); |
| 6189 | tmp = NULL; |
| 6190 | } else { |
| 6191 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
| 6192 | return 1; |
| 6193 | } |
| 6194 | *out = ExtSlice(dims, arena); |
| 6195 | if (*out == NULL) goto failed; |
| 6196 | return 0; |
| 6197 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6198 | isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type); |
| 6199 | if (isinstance == -1) { |
| 6200 | return 1; |
| 6201 | } |
| 6202 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6203 | expr_ty value; |
| 6204 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6205 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6206 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6207 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6208 | if (tmp == NULL) goto failed; |
| 6209 | res = obj2ast_expr(tmp, &value, arena); |
| 6210 | if (res != 0) goto failed; |
| 6211 | Py_XDECREF(tmp); |
| 6212 | tmp = NULL; |
| 6213 | } else { |
| 6214 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
| 6215 | return 1; |
| 6216 | } |
| 6217 | *out = Index(value, arena); |
| 6218 | if (*out == NULL) goto failed; |
| 6219 | return 0; |
| 6220 | } |
| 6221 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6222 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj); |
| 6223 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 6224 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6225 | return 1; |
| 6226 | } |
| 6227 | |
| 6228 | int |
| 6229 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 6230 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6231 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6232 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6233 | isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); |
| 6234 | if (isinstance == -1) { |
| 6235 | return 1; |
| 6236 | } |
| 6237 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6238 | *out = And; |
| 6239 | return 0; |
| 6240 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6241 | isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type); |
| 6242 | if (isinstance == -1) { |
| 6243 | return 1; |
| 6244 | } |
| 6245 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6246 | *out = Or; |
| 6247 | return 0; |
| 6248 | } |
| 6249 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6250 | 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] | 6251 | return 1; |
| 6252 | } |
| 6253 | |
| 6254 | int |
| 6255 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 6256 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6257 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6258 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6259 | isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); |
| 6260 | if (isinstance == -1) { |
| 6261 | return 1; |
| 6262 | } |
| 6263 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6264 | *out = Add; |
| 6265 | return 0; |
| 6266 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6267 | isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type); |
| 6268 | if (isinstance == -1) { |
| 6269 | return 1; |
| 6270 | } |
| 6271 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6272 | *out = Sub; |
| 6273 | return 0; |
| 6274 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6275 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type); |
| 6276 | if (isinstance == -1) { |
| 6277 | return 1; |
| 6278 | } |
| 6279 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6280 | *out = Mult; |
| 6281 | return 0; |
| 6282 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6283 | isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type); |
| 6284 | if (isinstance == -1) { |
| 6285 | return 1; |
| 6286 | } |
| 6287 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6288 | *out = Div; |
| 6289 | return 0; |
| 6290 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6291 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type); |
| 6292 | if (isinstance == -1) { |
| 6293 | return 1; |
| 6294 | } |
| 6295 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6296 | *out = Mod; |
| 6297 | return 0; |
| 6298 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6299 | isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type); |
| 6300 | if (isinstance == -1) { |
| 6301 | return 1; |
| 6302 | } |
| 6303 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6304 | *out = Pow; |
| 6305 | return 0; |
| 6306 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6307 | isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type); |
| 6308 | if (isinstance == -1) { |
| 6309 | return 1; |
| 6310 | } |
| 6311 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6312 | *out = LShift; |
| 6313 | return 0; |
| 6314 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6315 | isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type); |
| 6316 | if (isinstance == -1) { |
| 6317 | return 1; |
| 6318 | } |
| 6319 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6320 | *out = RShift; |
| 6321 | return 0; |
| 6322 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6323 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type); |
| 6324 | if (isinstance == -1) { |
| 6325 | return 1; |
| 6326 | } |
| 6327 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6328 | *out = BitOr; |
| 6329 | return 0; |
| 6330 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6331 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type); |
| 6332 | if (isinstance == -1) { |
| 6333 | return 1; |
| 6334 | } |
| 6335 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6336 | *out = BitXor; |
| 6337 | return 0; |
| 6338 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6339 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type); |
| 6340 | if (isinstance == -1) { |
| 6341 | return 1; |
| 6342 | } |
| 6343 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6344 | *out = BitAnd; |
| 6345 | return 0; |
| 6346 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6347 | isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type); |
| 6348 | if (isinstance == -1) { |
| 6349 | return 1; |
| 6350 | } |
| 6351 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6352 | *out = FloorDiv; |
| 6353 | return 0; |
| 6354 | } |
| 6355 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6356 | 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] | 6357 | return 1; |
| 6358 | } |
| 6359 | |
| 6360 | int |
| 6361 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 6362 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6363 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6364 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6365 | isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); |
| 6366 | if (isinstance == -1) { |
| 6367 | return 1; |
| 6368 | } |
| 6369 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6370 | *out = Invert; |
| 6371 | return 0; |
| 6372 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6373 | isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type); |
| 6374 | if (isinstance == -1) { |
| 6375 | return 1; |
| 6376 | } |
| 6377 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6378 | *out = Not; |
| 6379 | return 0; |
| 6380 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6381 | isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type); |
| 6382 | if (isinstance == -1) { |
| 6383 | return 1; |
| 6384 | } |
| 6385 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6386 | *out = UAdd; |
| 6387 | return 0; |
| 6388 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6389 | isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type); |
| 6390 | if (isinstance == -1) { |
| 6391 | return 1; |
| 6392 | } |
| 6393 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6394 | *out = USub; |
| 6395 | return 0; |
| 6396 | } |
| 6397 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6398 | 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] | 6399 | return 1; |
| 6400 | } |
| 6401 | |
| 6402 | int |
| 6403 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 6404 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6405 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6406 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6407 | isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); |
| 6408 | if (isinstance == -1) { |
| 6409 | return 1; |
| 6410 | } |
| 6411 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6412 | *out = Eq; |
| 6413 | return 0; |
| 6414 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6415 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type); |
| 6416 | if (isinstance == -1) { |
| 6417 | return 1; |
| 6418 | } |
| 6419 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6420 | *out = NotEq; |
| 6421 | return 0; |
| 6422 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6423 | isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type); |
| 6424 | if (isinstance == -1) { |
| 6425 | return 1; |
| 6426 | } |
| 6427 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6428 | *out = Lt; |
| 6429 | return 0; |
| 6430 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6431 | isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type); |
| 6432 | if (isinstance == -1) { |
| 6433 | return 1; |
| 6434 | } |
| 6435 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6436 | *out = LtE; |
| 6437 | return 0; |
| 6438 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6439 | isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type); |
| 6440 | if (isinstance == -1) { |
| 6441 | return 1; |
| 6442 | } |
| 6443 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6444 | *out = Gt; |
| 6445 | return 0; |
| 6446 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6447 | isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type); |
| 6448 | if (isinstance == -1) { |
| 6449 | return 1; |
| 6450 | } |
| 6451 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6452 | *out = GtE; |
| 6453 | return 0; |
| 6454 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6455 | isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type); |
| 6456 | if (isinstance == -1) { |
| 6457 | return 1; |
| 6458 | } |
| 6459 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6460 | *out = Is; |
| 6461 | return 0; |
| 6462 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6463 | isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type); |
| 6464 | if (isinstance == -1) { |
| 6465 | return 1; |
| 6466 | } |
| 6467 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6468 | *out = IsNot; |
| 6469 | return 0; |
| 6470 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6471 | isinstance = PyObject_IsInstance(obj, (PyObject *)In_type); |
| 6472 | if (isinstance == -1) { |
| 6473 | return 1; |
| 6474 | } |
| 6475 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6476 | *out = In; |
| 6477 | return 0; |
| 6478 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6479 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type); |
| 6480 | if (isinstance == -1) { |
| 6481 | return 1; |
| 6482 | } |
| 6483 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6484 | *out = NotIn; |
| 6485 | return 0; |
| 6486 | } |
| 6487 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6488 | 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] | 6489 | return 1; |
| 6490 | } |
| 6491 | |
| 6492 | int |
| 6493 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 6494 | { |
| 6495 | PyObject* tmp = NULL; |
| 6496 | expr_ty target; |
| 6497 | expr_ty iter; |
| 6498 | asdl_seq* ifs; |
| 6499 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6500 | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6501 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6502 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6503 | if (tmp == NULL) goto failed; |
| 6504 | res = obj2ast_expr(tmp, &target, arena); |
| 6505 | if (res != 0) goto failed; |
| 6506 | Py_XDECREF(tmp); |
| 6507 | tmp = NULL; |
| 6508 | } else { |
| 6509 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 6510 | return 1; |
| 6511 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6512 | if (_PyObject_HasAttrId(obj, &PyId_iter)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6513 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6514 | tmp = _PyObject_GetAttrId(obj, &PyId_iter); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6515 | if (tmp == NULL) goto failed; |
| 6516 | res = obj2ast_expr(tmp, &iter, arena); |
| 6517 | if (res != 0) goto failed; |
| 6518 | Py_XDECREF(tmp); |
| 6519 | tmp = NULL; |
| 6520 | } else { |
| 6521 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 6522 | return 1; |
| 6523 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6524 | if (_PyObject_HasAttrId(obj, &PyId_ifs)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6525 | int res; |
| 6526 | Py_ssize_t len; |
| 6527 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6528 | tmp = _PyObject_GetAttrId(obj, &PyId_ifs); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6529 | if (tmp == NULL) goto failed; |
| 6530 | if (!PyList_Check(tmp)) { |
| 6531 | PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6532 | goto failed; |
| 6533 | } |
| 6534 | len = PyList_GET_SIZE(tmp); |
| 6535 | ifs = asdl_seq_new(len, arena); |
| 6536 | if (ifs == NULL) goto failed; |
| 6537 | for (i = 0; i < len; i++) { |
| 6538 | expr_ty value; |
| 6539 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6540 | if (res != 0) goto failed; |
| 6541 | asdl_seq_SET(ifs, i, value); |
| 6542 | } |
| 6543 | Py_XDECREF(tmp); |
| 6544 | tmp = NULL; |
| 6545 | } else { |
| 6546 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 6547 | return 1; |
| 6548 | } |
| 6549 | *out = comprehension(target, iter, ifs, arena); |
| 6550 | return 0; |
| 6551 | failed: |
| 6552 | Py_XDECREF(tmp); |
| 6553 | return 1; |
| 6554 | } |
| 6555 | |
| 6556 | int |
| 6557 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 6558 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6559 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6560 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 6561 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6562 | int lineno; |
| 6563 | int col_offset; |
| 6564 | |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6565 | if (obj == Py_None) { |
| 6566 | *out = NULL; |
| 6567 | return 0; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6568 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6569 | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6570 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6571 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6572 | if (tmp == NULL) goto failed; |
| 6573 | res = obj2ast_int(tmp, &lineno, arena); |
| 6574 | if (res != 0) goto failed; |
| 6575 | Py_XDECREF(tmp); |
| 6576 | tmp = NULL; |
| 6577 | } else { |
| 6578 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 6579 | return 1; |
| 6580 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6581 | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6582 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6583 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6584 | if (tmp == NULL) goto failed; |
| 6585 | res = obj2ast_int(tmp, &col_offset, arena); |
| 6586 | if (res != 0) goto failed; |
| 6587 | Py_XDECREF(tmp); |
| 6588 | tmp = NULL; |
| 6589 | } else { |
| 6590 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 6591 | return 1; |
| 6592 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6593 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type); |
| 6594 | if (isinstance == -1) { |
| 6595 | return 1; |
| 6596 | } |
| 6597 | if (isinstance) { |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6598 | expr_ty type; |
| 6599 | identifier name; |
| 6600 | asdl_seq* body; |
| 6601 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6602 | if (_PyObject_HasAttrId(obj, &PyId_type)) { |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6603 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6604 | tmp = _PyObject_GetAttrId(obj, &PyId_type); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6605 | if (tmp == NULL) goto failed; |
| 6606 | res = obj2ast_expr(tmp, &type, arena); |
| 6607 | if (res != 0) goto failed; |
| 6608 | Py_XDECREF(tmp); |
| 6609 | tmp = NULL; |
| 6610 | } else { |
| 6611 | type = NULL; |
| 6612 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6613 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6614 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6615 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6616 | if (tmp == NULL) goto failed; |
| 6617 | res = obj2ast_identifier(tmp, &name, arena); |
| 6618 | if (res != 0) goto failed; |
| 6619 | Py_XDECREF(tmp); |
| 6620 | tmp = NULL; |
| 6621 | } else { |
| 6622 | name = NULL; |
| 6623 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6624 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6625 | int res; |
| 6626 | Py_ssize_t len; |
| 6627 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6628 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6629 | if (tmp == NULL) goto failed; |
| 6630 | if (!PyList_Check(tmp)) { |
| 6631 | PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6632 | goto failed; |
| 6633 | } |
| 6634 | len = PyList_GET_SIZE(tmp); |
| 6635 | body = asdl_seq_new(len, arena); |
| 6636 | if (body == NULL) goto failed; |
| 6637 | for (i = 0; i < len; i++) { |
| 6638 | stmt_ty value; |
| 6639 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6640 | if (res != 0) goto failed; |
| 6641 | asdl_seq_SET(body, i, value); |
| 6642 | } |
| 6643 | Py_XDECREF(tmp); |
| 6644 | tmp = NULL; |
| 6645 | } else { |
| 6646 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 6647 | return 1; |
| 6648 | } |
| 6649 | *out = ExceptHandler(type, name, body, lineno, col_offset, |
| 6650 | arena); |
| 6651 | if (*out == NULL) goto failed; |
| 6652 | return 0; |
| 6653 | } |
| 6654 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6655 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
| 6656 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 6657 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6658 | return 1; |
| 6659 | } |
| 6660 | |
| 6661 | int |
| 6662 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 6663 | { |
| 6664 | PyObject* tmp = NULL; |
| 6665 | asdl_seq* args; |
| 6666 | identifier vararg; |
| 6667 | expr_ty varargannotation; |
| 6668 | asdl_seq* kwonlyargs; |
| 6669 | identifier kwarg; |
| 6670 | expr_ty kwargannotation; |
| 6671 | asdl_seq* defaults; |
| 6672 | asdl_seq* kw_defaults; |
| 6673 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6674 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6675 | int res; |
| 6676 | Py_ssize_t len; |
| 6677 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6678 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6679 | if (tmp == NULL) goto failed; |
| 6680 | if (!PyList_Check(tmp)) { |
| 6681 | PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6682 | goto failed; |
| 6683 | } |
| 6684 | len = PyList_GET_SIZE(tmp); |
| 6685 | args = asdl_seq_new(len, arena); |
| 6686 | if (args == NULL) goto failed; |
| 6687 | for (i = 0; i < len; i++) { |
| 6688 | arg_ty value; |
| 6689 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6690 | if (res != 0) goto failed; |
| 6691 | asdl_seq_SET(args, i, value); |
| 6692 | } |
| 6693 | Py_XDECREF(tmp); |
| 6694 | tmp = NULL; |
| 6695 | } else { |
| 6696 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 6697 | return 1; |
| 6698 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6699 | if (_PyObject_HasAttrId(obj, &PyId_vararg)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6700 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6701 | tmp = _PyObject_GetAttrId(obj, &PyId_vararg); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6702 | if (tmp == NULL) goto failed; |
| 6703 | res = obj2ast_identifier(tmp, &vararg, arena); |
| 6704 | if (res != 0) goto failed; |
| 6705 | Py_XDECREF(tmp); |
| 6706 | tmp = NULL; |
| 6707 | } else { |
| 6708 | vararg = NULL; |
| 6709 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6710 | if (_PyObject_HasAttrId(obj, &PyId_varargannotation)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6711 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6712 | tmp = _PyObject_GetAttrId(obj, &PyId_varargannotation); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6713 | if (tmp == NULL) goto failed; |
| 6714 | res = obj2ast_expr(tmp, &varargannotation, arena); |
| 6715 | if (res != 0) goto failed; |
| 6716 | Py_XDECREF(tmp); |
| 6717 | tmp = NULL; |
| 6718 | } else { |
| 6719 | varargannotation = NULL; |
| 6720 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6721 | if (_PyObject_HasAttrId(obj, &PyId_kwonlyargs)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6722 | int res; |
| 6723 | Py_ssize_t len; |
| 6724 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6725 | tmp = _PyObject_GetAttrId(obj, &PyId_kwonlyargs); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6726 | if (tmp == NULL) goto failed; |
| 6727 | if (!PyList_Check(tmp)) { |
| 6728 | PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6729 | goto failed; |
| 6730 | } |
| 6731 | len = PyList_GET_SIZE(tmp); |
| 6732 | kwonlyargs = asdl_seq_new(len, arena); |
| 6733 | if (kwonlyargs == NULL) goto failed; |
| 6734 | for (i = 0; i < len; i++) { |
| 6735 | arg_ty value; |
| 6736 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6737 | if (res != 0) goto failed; |
| 6738 | asdl_seq_SET(kwonlyargs, i, value); |
| 6739 | } |
| 6740 | Py_XDECREF(tmp); |
| 6741 | tmp = NULL; |
| 6742 | } else { |
| 6743 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 6744 | return 1; |
| 6745 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6746 | if (_PyObject_HasAttrId(obj, &PyId_kwarg)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6747 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6748 | tmp = _PyObject_GetAttrId(obj, &PyId_kwarg); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6749 | if (tmp == NULL) goto failed; |
| 6750 | res = obj2ast_identifier(tmp, &kwarg, arena); |
| 6751 | if (res != 0) goto failed; |
| 6752 | Py_XDECREF(tmp); |
| 6753 | tmp = NULL; |
| 6754 | } else { |
| 6755 | kwarg = NULL; |
| 6756 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6757 | if (_PyObject_HasAttrId(obj, &PyId_kwargannotation)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6758 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6759 | tmp = _PyObject_GetAttrId(obj, &PyId_kwargannotation); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6760 | if (tmp == NULL) goto failed; |
| 6761 | res = obj2ast_expr(tmp, &kwargannotation, arena); |
| 6762 | if (res != 0) goto failed; |
| 6763 | Py_XDECREF(tmp); |
| 6764 | tmp = NULL; |
| 6765 | } else { |
| 6766 | kwargannotation = NULL; |
| 6767 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6768 | if (_PyObject_HasAttrId(obj, &PyId_defaults)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6769 | int res; |
| 6770 | Py_ssize_t len; |
| 6771 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6772 | tmp = _PyObject_GetAttrId(obj, &PyId_defaults); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6773 | if (tmp == NULL) goto failed; |
| 6774 | if (!PyList_Check(tmp)) { |
| 6775 | PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6776 | goto failed; |
| 6777 | } |
| 6778 | len = PyList_GET_SIZE(tmp); |
| 6779 | defaults = asdl_seq_new(len, arena); |
| 6780 | if (defaults == NULL) goto failed; |
| 6781 | for (i = 0; i < len; i++) { |
| 6782 | expr_ty value; |
| 6783 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6784 | if (res != 0) goto failed; |
| 6785 | asdl_seq_SET(defaults, i, value); |
| 6786 | } |
| 6787 | Py_XDECREF(tmp); |
| 6788 | tmp = NULL; |
| 6789 | } else { |
| 6790 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 6791 | return 1; |
| 6792 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6793 | if (_PyObject_HasAttrId(obj, &PyId_kw_defaults)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6794 | int res; |
| 6795 | Py_ssize_t len; |
| 6796 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6797 | tmp = _PyObject_GetAttrId(obj, &PyId_kw_defaults); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6798 | if (tmp == NULL) goto failed; |
| 6799 | if (!PyList_Check(tmp)) { |
| 6800 | PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6801 | goto failed; |
| 6802 | } |
| 6803 | len = PyList_GET_SIZE(tmp); |
| 6804 | kw_defaults = asdl_seq_new(len, arena); |
| 6805 | if (kw_defaults == NULL) goto failed; |
| 6806 | for (i = 0; i < len; i++) { |
| 6807 | expr_ty value; |
| 6808 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6809 | if (res != 0) goto failed; |
| 6810 | asdl_seq_SET(kw_defaults, i, value); |
| 6811 | } |
| 6812 | Py_XDECREF(tmp); |
| 6813 | tmp = NULL; |
| 6814 | } else { |
| 6815 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 6816 | return 1; |
| 6817 | } |
| 6818 | *out = arguments(args, vararg, varargannotation, kwonlyargs, kwarg, |
| 6819 | kwargannotation, defaults, kw_defaults, arena); |
| 6820 | return 0; |
| 6821 | failed: |
| 6822 | Py_XDECREF(tmp); |
| 6823 | return 1; |
| 6824 | } |
| 6825 | |
| 6826 | int |
| 6827 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 6828 | { |
| 6829 | PyObject* tmp = NULL; |
| 6830 | identifier arg; |
| 6831 | expr_ty annotation; |
| 6832 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6833 | if (_PyObject_HasAttrId(obj, &PyId_arg)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6834 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6835 | tmp = _PyObject_GetAttrId(obj, &PyId_arg); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6836 | if (tmp == NULL) goto failed; |
| 6837 | res = obj2ast_identifier(tmp, &arg, arena); |
| 6838 | if (res != 0) goto failed; |
| 6839 | Py_XDECREF(tmp); |
| 6840 | tmp = NULL; |
| 6841 | } else { |
| 6842 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
| 6843 | return 1; |
| 6844 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6845 | if (_PyObject_HasAttrId(obj, &PyId_annotation)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6846 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6847 | tmp = _PyObject_GetAttrId(obj, &PyId_annotation); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6848 | if (tmp == NULL) goto failed; |
| 6849 | res = obj2ast_expr(tmp, &annotation, arena); |
| 6850 | if (res != 0) goto failed; |
| 6851 | Py_XDECREF(tmp); |
| 6852 | tmp = NULL; |
| 6853 | } else { |
| 6854 | annotation = NULL; |
| 6855 | } |
| 6856 | *out = arg(arg, annotation, arena); |
| 6857 | return 0; |
| 6858 | failed: |
| 6859 | Py_XDECREF(tmp); |
| 6860 | return 1; |
| 6861 | } |
| 6862 | |
| 6863 | int |
| 6864 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 6865 | { |
| 6866 | PyObject* tmp = NULL; |
| 6867 | identifier arg; |
| 6868 | expr_ty value; |
| 6869 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6870 | if (_PyObject_HasAttrId(obj, &PyId_arg)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6871 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6872 | tmp = _PyObject_GetAttrId(obj, &PyId_arg); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6873 | if (tmp == NULL) goto failed; |
| 6874 | res = obj2ast_identifier(tmp, &arg, arena); |
| 6875 | if (res != 0) goto failed; |
| 6876 | Py_XDECREF(tmp); |
| 6877 | tmp = NULL; |
| 6878 | } else { |
| 6879 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from keyword"); |
| 6880 | return 1; |
| 6881 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6882 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6883 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6884 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6885 | if (tmp == NULL) goto failed; |
| 6886 | res = obj2ast_expr(tmp, &value, arena); |
| 6887 | if (res != 0) goto failed; |
| 6888 | Py_XDECREF(tmp); |
| 6889 | tmp = NULL; |
| 6890 | } else { |
| 6891 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 6892 | return 1; |
| 6893 | } |
| 6894 | *out = keyword(arg, value, arena); |
| 6895 | return 0; |
| 6896 | failed: |
| 6897 | Py_XDECREF(tmp); |
| 6898 | return 1; |
| 6899 | } |
| 6900 | |
| 6901 | int |
| 6902 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 6903 | { |
| 6904 | PyObject* tmp = NULL; |
| 6905 | identifier name; |
| 6906 | identifier asname; |
| 6907 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6908 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6909 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6910 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6911 | if (tmp == NULL) goto failed; |
| 6912 | res = obj2ast_identifier(tmp, &name, arena); |
| 6913 | if (res != 0) goto failed; |
| 6914 | Py_XDECREF(tmp); |
| 6915 | tmp = NULL; |
| 6916 | } else { |
| 6917 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 6918 | return 1; |
| 6919 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6920 | if (_PyObject_HasAttrId(obj, &PyId_asname)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6921 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6922 | tmp = _PyObject_GetAttrId(obj, &PyId_asname); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6923 | if (tmp == NULL) goto failed; |
| 6924 | res = obj2ast_identifier(tmp, &asname, arena); |
| 6925 | if (res != 0) goto failed; |
| 6926 | Py_XDECREF(tmp); |
| 6927 | tmp = NULL; |
| 6928 | } else { |
| 6929 | asname = NULL; |
| 6930 | } |
| 6931 | *out = alias(name, asname, arena); |
| 6932 | return 0; |
| 6933 | failed: |
| 6934 | Py_XDECREF(tmp); |
| 6935 | return 1; |
| 6936 | } |
| 6937 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6938 | int |
| 6939 | obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) |
| 6940 | { |
| 6941 | PyObject* tmp = NULL; |
| 6942 | expr_ty context_expr; |
| 6943 | expr_ty optional_vars; |
| 6944 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6945 | if (_PyObject_HasAttrId(obj, &PyId_context_expr)) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6946 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6947 | tmp = _PyObject_GetAttrId(obj, &PyId_context_expr); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6948 | if (tmp == NULL) goto failed; |
| 6949 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 6950 | if (res != 0) goto failed; |
| 6951 | Py_XDECREF(tmp); |
| 6952 | tmp = NULL; |
| 6953 | } else { |
| 6954 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); |
| 6955 | return 1; |
| 6956 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6957 | if (_PyObject_HasAttrId(obj, &PyId_optional_vars)) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6958 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6959 | tmp = _PyObject_GetAttrId(obj, &PyId_optional_vars); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6960 | if (tmp == NULL) goto failed; |
| 6961 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 6962 | if (res != 0) goto failed; |
| 6963 | Py_XDECREF(tmp); |
| 6964 | tmp = NULL; |
| 6965 | } else { |
| 6966 | optional_vars = NULL; |
| 6967 | } |
| 6968 | *out = withitem(context_expr, optional_vars, arena); |
| 6969 | return 0; |
| 6970 | failed: |
| 6971 | Py_XDECREF(tmp); |
| 6972 | return 1; |
| 6973 | } |
| 6974 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6975 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6976 | static struct PyModuleDef _astmodule = { |
| 6977 | PyModuleDef_HEAD_INIT, "_ast" |
| 6978 | }; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6979 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6980 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6981 | { |
| 6982 | PyObject *m, *d; |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6983 | if (!init_types()) return NULL; |
| 6984 | m = PyModule_Create(&_astmodule); |
| 6985 | if (!m) return NULL; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6986 | d = PyModule_GetDict(m); |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6987 | if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return |
| 6988 | NULL; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6989 | 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] | 6990 | return NULL; |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6991 | if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return |
| 6992 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6993 | if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6994 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6995 | if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6996 | < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6997 | if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6998 | 0) return NULL; |
| 6999 | if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return |
| 7000 | NULL; |
| 7001 | if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return |
| 7002 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7003 | if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7004 | < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7005 | if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7006 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7007 | if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7008 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7009 | if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7010 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7011 | if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7012 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7013 | if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7014 | 0) return NULL; |
| 7015 | if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return |
| 7016 | NULL; |
| 7017 | if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return |
| 7018 | NULL; |
| 7019 | if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return NULL; |
| 7020 | if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return |
| 7021 | NULL; |
| 7022 | if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return |
| 7023 | NULL; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 7024 | if (PyDict_SetItemString(d, "Try", (PyObject*)Try_type) < 0) return |
| 7025 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7026 | if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7027 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7028 | if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7029 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7030 | if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7031 | 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7032 | if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7033 | return NULL; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 7034 | if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7035 | return NULL; |
| 7036 | if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return |
| 7037 | NULL; |
| 7038 | if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return |
| 7039 | NULL; |
| 7040 | if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return |
| 7041 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7042 | if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7043 | return NULL; |
| 7044 | if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return |
| 7045 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7046 | if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7047 | return NULL; |
| 7048 | if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return |
| 7049 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7050 | if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7051 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7052 | if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7053 | return NULL; |
| 7054 | if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return |
| 7055 | NULL; |
| 7056 | if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return |
| 7057 | NULL; |
| 7058 | if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return |
| 7059 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7060 | if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7061 | return NULL; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 7062 | if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7063 | return NULL; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 7064 | if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7065 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7066 | if (PyDict_SetItemString(d, "GeneratorExp", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7067 | (PyObject*)GeneratorExp_type) < 0) return NULL; |
| 7068 | if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return |
| 7069 | NULL; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 7070 | if (PyDict_SetItemString(d, "YieldFrom", (PyObject*)YieldFrom_type) < |
| 7071 | 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7072 | if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7073 | return NULL; |
| 7074 | if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return |
| 7075 | NULL; |
| 7076 | if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return |
| 7077 | NULL; |
| 7078 | if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return |
| 7079 | NULL; |
| 7080 | if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return |
| 7081 | NULL; |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 7082 | if (PyDict_SetItemString(d, "NameConstant", |
| 7083 | (PyObject*)NameConstant_type) < 0) return NULL; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 7084 | if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7085 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7086 | if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7087 | 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7088 | if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7089 | 0) return NULL; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 7090 | if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7091 | return NULL; |
| 7092 | if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return |
| 7093 | NULL; |
| 7094 | if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return |
| 7095 | NULL; |
| 7096 | if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return |
| 7097 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7098 | if (PyDict_SetItemString(d, "expr_context", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7099 | (PyObject*)expr_context_type) < 0) return NULL; |
| 7100 | if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return |
| 7101 | NULL; |
| 7102 | if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return |
| 7103 | NULL; |
| 7104 | if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return |
| 7105 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7106 | if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7107 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7108 | if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7109 | return NULL; |
| 7110 | if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return |
| 7111 | NULL; |
| 7112 | if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return |
| 7113 | NULL; |
| 7114 | if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return |
| 7115 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7116 | if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7117 | return NULL; |
| 7118 | if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return |
| 7119 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7120 | if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7121 | return NULL; |
| 7122 | if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return |
| 7123 | NULL; |
| 7124 | if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7125 | if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7126 | return NULL; |
| 7127 | if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return |
| 7128 | NULL; |
| 7129 | if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return |
| 7130 | NULL; |
| 7131 | if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return |
| 7132 | NULL; |
| 7133 | if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return |
| 7134 | NULL; |
| 7135 | if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return |
| 7136 | NULL; |
| 7137 | if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return |
| 7138 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7139 | if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7140 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7141 | if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7142 | return NULL; |
| 7143 | if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return |
| 7144 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7145 | if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7146 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7147 | if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7148 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7149 | if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7150 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7151 | if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7152 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7153 | if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7154 | return NULL; |
| 7155 | if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return |
| 7156 | NULL; |
| 7157 | if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return |
| 7158 | NULL; |
| 7159 | if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return |
| 7160 | NULL; |
| 7161 | if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return |
| 7162 | NULL; |
| 7163 | if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return NULL; |
| 7164 | if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return |
| 7165 | NULL; |
| 7166 | if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return NULL; |
| 7167 | if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return |
| 7168 | NULL; |
| 7169 | if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return NULL; |
| 7170 | if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return |
| 7171 | NULL; |
| 7172 | if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return NULL; |
| 7173 | if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return |
| 7174 | NULL; |
| 7175 | if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return NULL; |
| 7176 | if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return |
| 7177 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7178 | if (PyDict_SetItemString(d, "comprehension", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7179 | (PyObject*)comprehension_type) < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7180 | if (PyDict_SetItemString(d, "excepthandler", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7181 | (PyObject*)excepthandler_type) < 0) return NULL; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 7182 | if (PyDict_SetItemString(d, "ExceptHandler", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7183 | (PyObject*)ExceptHandler_type) < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7184 | if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7185 | 0) return NULL; |
| 7186 | if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return |
| 7187 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7188 | if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7189 | return NULL; |
| 7190 | if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return |
| 7191 | NULL; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 7192 | if (PyDict_SetItemString(d, "withitem", (PyObject*)withitem_type) < 0) |
| 7193 | return NULL; |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7194 | return m; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 7195 | } |
| 7196 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 7197 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 7198 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 7199 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 7200 | init_types(); |
| 7201 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 7202 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 7203 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7204 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 7205 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7206 | { |
| 7207 | mod_ty res; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7208 | PyObject *req_type[] = {(PyObject*)Module_type, (PyObject*)Expression_type, |
| 7209 | (PyObject*)Interactive_type}; |
| 7210 | char *req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 7211 | int isinstance; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7212 | assert(0 <= mode && mode <= 2); |
| 7213 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7214 | init_types(); |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7215 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 7216 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 7217 | if (isinstance == -1) |
| 7218 | return NULL; |
| 7219 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7220 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
| 7221 | req_name[mode], Py_TYPE(ast)->tp_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7222 | return NULL; |
| 7223 | } |
| 7224 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 7225 | return NULL; |
| 7226 | else |
| 7227 | return res; |
| 7228 | } |
| 7229 | |
| 7230 | int PyAST_Check(PyObject* obj) |
| 7231 | { |
| 7232 | init_types(); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 7233 | return PyObject_IsInstance(obj, (PyObject*)&AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7234 | } |
| 7235 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 7236 | |