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); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 415 | _Py_IDENTIFIER(kwonlyargs); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 416 | _Py_IDENTIFIER(kw_defaults); |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 417 | _Py_IDENTIFIER(kwarg); |
| 418 | _Py_IDENTIFIER(defaults); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 419 | static char *arguments_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 420 | "args", |
| 421 | "vararg", |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 422 | "kwonlyargs", |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 423 | "kw_defaults", |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 424 | "kwarg", |
| 425 | "defaults", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 426 | }; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 427 | static PyTypeObject *arg_type; |
| 428 | static PyObject* ast2obj_arg(void*); |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 429 | static char *arg_attributes[] = { |
| 430 | "lineno", |
| 431 | "col_offset", |
| 432 | }; |
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 | |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 773 | static int exists_not_none(PyObject *obj, _Py_Identifier *id) |
| 774 | { |
Benjamin Peterson | 3a61943 | 2013-03-18 23:40:53 -0700 | [diff] [blame] | 775 | int isnone; |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 776 | PyObject *attr = _PyObject_GetAttrId(obj, id); |
| 777 | if (!attr) { |
| 778 | PyErr_Clear(); |
| 779 | return 0; |
| 780 | } |
Benjamin Peterson | 3a61943 | 2013-03-18 23:40:53 -0700 | [diff] [blame] | 781 | isnone = attr == Py_None; |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 782 | Py_DECREF(attr); |
| 783 | return !isnone; |
| 784 | } |
| 785 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 786 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 787 | static int init_types(void) |
| 788 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 789 | static int initialized; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 790 | if (initialized) return 1; |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 791 | if (add_ast_fields() < 0) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 792 | mod_type = make_type("mod", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 793 | if (!mod_type) return 0; |
| 794 | if (!add_attributes(mod_type, NULL, 0)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 795 | Module_type = make_type("Module", mod_type, Module_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 796 | if (!Module_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 797 | Interactive_type = make_type("Interactive", mod_type, |
| 798 | Interactive_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 799 | if (!Interactive_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 800 | Expression_type = make_type("Expression", mod_type, Expression_fields, |
| 801 | 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 802 | if (!Expression_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 803 | Suite_type = make_type("Suite", mod_type, Suite_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 804 | if (!Suite_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 805 | stmt_type = make_type("stmt", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 806 | if (!stmt_type) return 0; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 807 | if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 808 | FunctionDef_type = make_type("FunctionDef", stmt_type, |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 809 | FunctionDef_fields, 5); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 810 | if (!FunctionDef_type) return 0; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 811 | ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 7); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 812 | if (!ClassDef_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 813 | Return_type = make_type("Return", stmt_type, Return_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 814 | if (!Return_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 815 | Delete_type = make_type("Delete", stmt_type, Delete_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 816 | if (!Delete_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 817 | Assign_type = make_type("Assign", stmt_type, Assign_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 818 | if (!Assign_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 819 | AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 820 | if (!AugAssign_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 821 | For_type = make_type("For", stmt_type, For_fields, 4); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 822 | if (!For_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 823 | While_type = make_type("While", stmt_type, While_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 824 | if (!While_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 825 | If_type = make_type("If", stmt_type, If_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 826 | if (!If_type) return 0; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 827 | With_type = make_type("With", stmt_type, With_fields, 2); |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 828 | if (!With_type) return 0; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 829 | Raise_type = make_type("Raise", stmt_type, Raise_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 830 | if (!Raise_type) return 0; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 831 | Try_type = make_type("Try", stmt_type, Try_fields, 4); |
| 832 | if (!Try_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 833 | Assert_type = make_type("Assert", stmt_type, Assert_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 834 | if (!Assert_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 835 | Import_type = make_type("Import", stmt_type, Import_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 836 | if (!Import_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 837 | ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 838 | 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 839 | if (!ImportFrom_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 840 | Global_type = make_type("Global", stmt_type, Global_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 841 | if (!Global_type) return 0; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 842 | Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1); |
| 843 | if (!Nonlocal_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 844 | Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 845 | if (!Expr_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 846 | Pass_type = make_type("Pass", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 847 | if (!Pass_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 848 | Break_type = make_type("Break", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 849 | if (!Break_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 850 | Continue_type = make_type("Continue", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 851 | if (!Continue_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 852 | expr_type = make_type("expr", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 853 | if (!expr_type) return 0; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 854 | if (!add_attributes(expr_type, expr_attributes, 2)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 855 | BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 856 | if (!BoolOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 857 | BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 858 | if (!BinOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 859 | UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 860 | if (!UnaryOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 861 | Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 862 | if (!Lambda_type) return 0; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 863 | IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 864 | if (!IfExp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 865 | Dict_type = make_type("Dict", expr_type, Dict_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 866 | if (!Dict_type) return 0; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 867 | Set_type = make_type("Set", expr_type, Set_fields, 1); |
| 868 | if (!Set_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 869 | ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 870 | if (!ListComp_type) return 0; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 871 | SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2); |
| 872 | if (!SetComp_type) return 0; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 873 | DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3); |
| 874 | if (!DictComp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 875 | GeneratorExp_type = make_type("GeneratorExp", expr_type, |
| 876 | GeneratorExp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 877 | if (!GeneratorExp_type) return 0; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 878 | Yield_type = make_type("Yield", expr_type, Yield_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 879 | if (!Yield_type) return 0; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 880 | YieldFrom_type = make_type("YieldFrom", expr_type, YieldFrom_fields, 1); |
| 881 | if (!YieldFrom_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 882 | Compare_type = make_type("Compare", expr_type, Compare_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 883 | if (!Compare_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 884 | Call_type = make_type("Call", expr_type, Call_fields, 5); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 885 | if (!Call_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 886 | Num_type = make_type("Num", expr_type, Num_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 887 | if (!Num_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 888 | Str_type = make_type("Str", expr_type, Str_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 889 | if (!Str_type) return 0; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 890 | Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1); |
| 891 | if (!Bytes_type) return 0; |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 892 | NameConstant_type = make_type("NameConstant", expr_type, |
| 893 | NameConstant_fields, 1); |
| 894 | if (!NameConstant_type) return 0; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 895 | Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0); |
| 896 | if (!Ellipsis_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 897 | Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 898 | if (!Attribute_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 899 | Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 900 | if (!Subscript_type) return 0; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 901 | Starred_type = make_type("Starred", expr_type, Starred_fields, 2); |
| 902 | if (!Starred_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 903 | Name_type = make_type("Name", expr_type, Name_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 904 | if (!Name_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 905 | List_type = make_type("List", expr_type, List_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 906 | if (!List_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 907 | Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 908 | if (!Tuple_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 909 | 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] | 910 | if (!expr_context_type) return 0; |
| 911 | if (!add_attributes(expr_context_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 912 | Load_type = make_type("Load", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 913 | if (!Load_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 914 | Load_singleton = PyType_GenericNew(Load_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 915 | if (!Load_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 916 | Store_type = make_type("Store", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 917 | if (!Store_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 918 | Store_singleton = PyType_GenericNew(Store_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 919 | if (!Store_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 920 | Del_type = make_type("Del", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 921 | if (!Del_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 922 | Del_singleton = PyType_GenericNew(Del_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 923 | if (!Del_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 924 | AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 925 | if (!AugLoad_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 926 | AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 927 | if (!AugLoad_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 928 | AugStore_type = make_type("AugStore", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 929 | if (!AugStore_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 930 | AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 931 | if (!AugStore_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 932 | Param_type = make_type("Param", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 933 | if (!Param_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 934 | Param_singleton = PyType_GenericNew(Param_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 935 | if (!Param_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 936 | slice_type = make_type("slice", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 937 | if (!slice_type) return 0; |
| 938 | if (!add_attributes(slice_type, NULL, 0)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 939 | Slice_type = make_type("Slice", slice_type, Slice_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 940 | if (!Slice_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 941 | ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 942 | if (!ExtSlice_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 943 | Index_type = make_type("Index", slice_type, Index_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 944 | if (!Index_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 945 | boolop_type = make_type("boolop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 946 | if (!boolop_type) return 0; |
| 947 | if (!add_attributes(boolop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 948 | And_type = make_type("And", boolop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 949 | if (!And_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 950 | And_singleton = PyType_GenericNew(And_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 951 | if (!And_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 952 | Or_type = make_type("Or", boolop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 953 | if (!Or_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 954 | Or_singleton = PyType_GenericNew(Or_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 955 | if (!Or_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 956 | operator_type = make_type("operator", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 957 | if (!operator_type) return 0; |
| 958 | if (!add_attributes(operator_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 959 | Add_type = make_type("Add", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 960 | if (!Add_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 961 | Add_singleton = PyType_GenericNew(Add_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 962 | if (!Add_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 963 | Sub_type = make_type("Sub", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 964 | if (!Sub_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 965 | Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 966 | if (!Sub_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 967 | Mult_type = make_type("Mult", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 968 | if (!Mult_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 969 | Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 970 | if (!Mult_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 971 | Div_type = make_type("Div", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 972 | if (!Div_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 973 | Div_singleton = PyType_GenericNew(Div_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 974 | if (!Div_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 975 | Mod_type = make_type("Mod", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 976 | if (!Mod_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 977 | Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 978 | if (!Mod_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 979 | Pow_type = make_type("Pow", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 980 | if (!Pow_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 981 | Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 982 | if (!Pow_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 983 | LShift_type = make_type("LShift", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 984 | if (!LShift_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 985 | LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 986 | if (!LShift_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 987 | RShift_type = make_type("RShift", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 988 | if (!RShift_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 989 | RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 990 | if (!RShift_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 991 | BitOr_type = make_type("BitOr", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 992 | if (!BitOr_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 993 | BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 994 | if (!BitOr_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 995 | BitXor_type = make_type("BitXor", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 996 | if (!BitXor_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 997 | BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 998 | if (!BitXor_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 999 | BitAnd_type = make_type("BitAnd", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1000 | if (!BitAnd_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1001 | BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1002 | if (!BitAnd_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1003 | FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1004 | if (!FloorDiv_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1005 | FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1006 | if (!FloorDiv_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1007 | unaryop_type = make_type("unaryop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1008 | if (!unaryop_type) return 0; |
| 1009 | if (!add_attributes(unaryop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1010 | Invert_type = make_type("Invert", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1011 | if (!Invert_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1012 | Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1013 | if (!Invert_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1014 | Not_type = make_type("Not", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1015 | if (!Not_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1016 | Not_singleton = PyType_GenericNew(Not_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1017 | if (!Not_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1018 | UAdd_type = make_type("UAdd", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1019 | if (!UAdd_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1020 | UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1021 | if (!UAdd_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1022 | USub_type = make_type("USub", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1023 | if (!USub_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1024 | USub_singleton = PyType_GenericNew(USub_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1025 | if (!USub_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1026 | cmpop_type = make_type("cmpop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1027 | if (!cmpop_type) return 0; |
| 1028 | if (!add_attributes(cmpop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1029 | Eq_type = make_type("Eq", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1030 | if (!Eq_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1031 | Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1032 | if (!Eq_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1033 | NotEq_type = make_type("NotEq", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1034 | if (!NotEq_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1035 | NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1036 | if (!NotEq_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1037 | Lt_type = make_type("Lt", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1038 | if (!Lt_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1039 | Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1040 | if (!Lt_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1041 | LtE_type = make_type("LtE", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1042 | if (!LtE_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1043 | LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1044 | if (!LtE_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1045 | Gt_type = make_type("Gt", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1046 | if (!Gt_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1047 | Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1048 | if (!Gt_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1049 | GtE_type = make_type("GtE", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1050 | if (!GtE_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1051 | GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1052 | if (!GtE_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1053 | Is_type = make_type("Is", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1054 | if (!Is_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1055 | Is_singleton = PyType_GenericNew(Is_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1056 | if (!Is_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1057 | IsNot_type = make_type("IsNot", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1058 | if (!IsNot_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1059 | IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1060 | if (!IsNot_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1061 | In_type = make_type("In", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1062 | if (!In_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1063 | In_singleton = PyType_GenericNew(In_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1064 | if (!In_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 1065 | NotIn_type = make_type("NotIn", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1066 | if (!NotIn_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1067 | NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1068 | if (!NotIn_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1069 | comprehension_type = make_type("comprehension", &AST_type, |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1070 | comprehension_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1071 | if (!comprehension_type) return 0; |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 1072 | if (!add_attributes(comprehension_type, NULL, 0)) return 0; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 1073 | excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1074 | if (!excepthandler_type) return 0; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 1075 | if (!add_attributes(excepthandler_type, excepthandler_attributes, 2)) |
| 1076 | return 0; |
| 1077 | ExceptHandler_type = make_type("ExceptHandler", excepthandler_type, |
| 1078 | ExceptHandler_fields, 3); |
| 1079 | if (!ExceptHandler_type) return 0; |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 1080 | arguments_type = make_type("arguments", &AST_type, arguments_fields, 6); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1081 | if (!arguments_type) return 0; |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 1082 | if (!add_attributes(arguments_type, NULL, 0)) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1083 | arg_type = make_type("arg", &AST_type, arg_fields, 2); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1084 | if (!arg_type) return 0; |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 1085 | if (!add_attributes(arg_type, arg_attributes, 2)) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1086 | keyword_type = make_type("keyword", &AST_type, keyword_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1087 | if (!keyword_type) return 0; |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 1088 | if (!add_attributes(keyword_type, NULL, 0)) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1089 | alias_type = make_type("alias", &AST_type, alias_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1090 | if (!alias_type) return 0; |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 1091 | if (!add_attributes(alias_type, NULL, 0)) return 0; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1092 | withitem_type = make_type("withitem", &AST_type, withitem_fields, 2); |
| 1093 | if (!withitem_type) return 0; |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 1094 | if (!add_attributes(withitem_type, NULL, 0)) return 0; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1095 | initialized = 1; |
| 1096 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1097 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 1098 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1099 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 1100 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 1101 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 1102 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 1103 | arena); |
| 1104 | static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena); |
| 1105 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 1106 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 1107 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 1108 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 1109 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 1110 | arena); |
| 1111 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 1112 | arena); |
| 1113 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 1114 | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
| 1115 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 1116 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1117 | 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] | 1118 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1119 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1120 | Module(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1121 | { |
| 1122 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1123 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1124 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1125 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1126 | p->kind = Module_kind; |
| 1127 | p->v.Module.body = body; |
| 1128 | return p; |
| 1129 | } |
| 1130 | |
| 1131 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1132 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1133 | { |
| 1134 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1135 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1136 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1137 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1138 | p->kind = Interactive_kind; |
| 1139 | p->v.Interactive.body = body; |
| 1140 | return p; |
| 1141 | } |
| 1142 | |
| 1143 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1144 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1145 | { |
| 1146 | mod_ty p; |
| 1147 | if (!body) { |
| 1148 | PyErr_SetString(PyExc_ValueError, |
| 1149 | "field body is required for Expression"); |
| 1150 | return NULL; |
| 1151 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1152 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1153 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1154 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1155 | p->kind = Expression_kind; |
| 1156 | p->v.Expression.body = body; |
| 1157 | return p; |
| 1158 | } |
| 1159 | |
| 1160 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1161 | Suite(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1162 | { |
| 1163 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1164 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1165 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1166 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1167 | p->kind = Suite_kind; |
| 1168 | p->v.Suite.body = body; |
| 1169 | return p; |
| 1170 | } |
| 1171 | |
| 1172 | stmt_ty |
| 1173 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1174 | decorator_list, expr_ty returns, int lineno, int col_offset, |
| 1175 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1176 | { |
| 1177 | stmt_ty p; |
| 1178 | if (!name) { |
| 1179 | PyErr_SetString(PyExc_ValueError, |
| 1180 | "field name is required for FunctionDef"); |
| 1181 | return NULL; |
| 1182 | } |
| 1183 | if (!args) { |
| 1184 | PyErr_SetString(PyExc_ValueError, |
| 1185 | "field args is required for FunctionDef"); |
| 1186 | return NULL; |
| 1187 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1188 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1189 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1190 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1191 | p->kind = FunctionDef_kind; |
| 1192 | p->v.FunctionDef.name = name; |
| 1193 | p->v.FunctionDef.args = args; |
| 1194 | p->v.FunctionDef.body = body; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1195 | p->v.FunctionDef.decorator_list = decorator_list; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1196 | p->v.FunctionDef.returns = returns; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1197 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1198 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1199 | return p; |
| 1200 | } |
| 1201 | |
| 1202 | stmt_ty |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 1203 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, expr_ty |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1204 | starargs, expr_ty kwargs, asdl_seq * body, asdl_seq * decorator_list, |
| 1205 | int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1206 | { |
| 1207 | stmt_ty p; |
| 1208 | if (!name) { |
| 1209 | PyErr_SetString(PyExc_ValueError, |
| 1210 | "field name is required for ClassDef"); |
| 1211 | return NULL; |
| 1212 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1213 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1214 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1215 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1216 | p->kind = ClassDef_kind; |
| 1217 | p->v.ClassDef.name = name; |
| 1218 | p->v.ClassDef.bases = bases; |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 1219 | p->v.ClassDef.keywords = keywords; |
| 1220 | p->v.ClassDef.starargs = starargs; |
| 1221 | p->v.ClassDef.kwargs = kwargs; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1222 | p->v.ClassDef.body = body; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1223 | p->v.ClassDef.decorator_list = decorator_list; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1224 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1225 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1226 | return p; |
| 1227 | } |
| 1228 | |
| 1229 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1230 | Return(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1231 | { |
| 1232 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1233 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1234 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1235 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1236 | p->kind = Return_kind; |
| 1237 | p->v.Return.value = value; |
| 1238 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1239 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1240 | return p; |
| 1241 | } |
| 1242 | |
| 1243 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1244 | Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1245 | { |
| 1246 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1247 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1248 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1249 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1250 | p->kind = Delete_kind; |
| 1251 | p->v.Delete.targets = targets; |
| 1252 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1253 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1254 | return p; |
| 1255 | } |
| 1256 | |
| 1257 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1258 | Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena |
| 1259 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1260 | { |
| 1261 | stmt_ty p; |
| 1262 | if (!value) { |
| 1263 | PyErr_SetString(PyExc_ValueError, |
| 1264 | "field value is required for Assign"); |
| 1265 | return NULL; |
| 1266 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1267 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1268 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1269 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1270 | p->kind = Assign_kind; |
| 1271 | p->v.Assign.targets = targets; |
| 1272 | p->v.Assign.value = value; |
| 1273 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1274 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1275 | return p; |
| 1276 | } |
| 1277 | |
| 1278 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1279 | AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int |
| 1280 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1281 | { |
| 1282 | stmt_ty p; |
| 1283 | if (!target) { |
| 1284 | PyErr_SetString(PyExc_ValueError, |
| 1285 | "field target is required for AugAssign"); |
| 1286 | return NULL; |
| 1287 | } |
| 1288 | if (!op) { |
| 1289 | PyErr_SetString(PyExc_ValueError, |
| 1290 | "field op is required for AugAssign"); |
| 1291 | return NULL; |
| 1292 | } |
| 1293 | if (!value) { |
| 1294 | PyErr_SetString(PyExc_ValueError, |
| 1295 | "field value is required for AugAssign"); |
| 1296 | return NULL; |
| 1297 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1298 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1299 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1300 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1301 | p->kind = AugAssign_kind; |
| 1302 | p->v.AugAssign.target = target; |
| 1303 | p->v.AugAssign.op = op; |
| 1304 | p->v.AugAssign.value = value; |
| 1305 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1306 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1307 | return p; |
| 1308 | } |
| 1309 | |
| 1310 | stmt_ty |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1311 | 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] | 1312 | lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1313 | { |
| 1314 | stmt_ty p; |
| 1315 | if (!target) { |
| 1316 | PyErr_SetString(PyExc_ValueError, |
| 1317 | "field target is required for For"); |
| 1318 | return NULL; |
| 1319 | } |
| 1320 | if (!iter) { |
| 1321 | PyErr_SetString(PyExc_ValueError, |
| 1322 | "field iter is required for For"); |
| 1323 | return NULL; |
| 1324 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1325 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1326 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1327 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1328 | p->kind = For_kind; |
| 1329 | p->v.For.target = target; |
| 1330 | p->v.For.iter = iter; |
| 1331 | p->v.For.body = body; |
| 1332 | p->v.For.orelse = orelse; |
| 1333 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1334 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1335 | return p; |
| 1336 | } |
| 1337 | |
| 1338 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1339 | While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1340 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1341 | { |
| 1342 | stmt_ty p; |
| 1343 | if (!test) { |
| 1344 | PyErr_SetString(PyExc_ValueError, |
| 1345 | "field test is required for While"); |
| 1346 | return NULL; |
| 1347 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1348 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1349 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1350 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1351 | p->kind = While_kind; |
| 1352 | p->v.While.test = test; |
| 1353 | p->v.While.body = body; |
| 1354 | p->v.While.orelse = orelse; |
| 1355 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1356 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1357 | return p; |
| 1358 | } |
| 1359 | |
| 1360 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1361 | If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1362 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1363 | { |
| 1364 | stmt_ty p; |
| 1365 | if (!test) { |
| 1366 | PyErr_SetString(PyExc_ValueError, |
| 1367 | "field test is required for If"); |
| 1368 | return NULL; |
| 1369 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1370 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1371 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1372 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1373 | p->kind = If_kind; |
| 1374 | p->v.If.test = test; |
| 1375 | p->v.If.body = body; |
| 1376 | p->v.If.orelse = orelse; |
| 1377 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1378 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1379 | return p; |
| 1380 | } |
| 1381 | |
| 1382 | stmt_ty |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1383 | With(asdl_seq * items, asdl_seq * body, int lineno, int col_offset, PyArena |
| 1384 | *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1385 | { |
| 1386 | stmt_ty p; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1387 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1388 | if (!p) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1389 | return NULL; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1390 | p->kind = With_kind; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1391 | p->v.With.items = items; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1392 | p->v.With.body = body; |
| 1393 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1394 | p->col_offset = col_offset; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1395 | return p; |
| 1396 | } |
| 1397 | |
| 1398 | stmt_ty |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 1399 | 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] | 1400 | { |
| 1401 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1402 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1403 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1404 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1405 | p->kind = Raise_kind; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 1406 | p->v.Raise.exc = exc; |
| 1407 | p->v.Raise.cause = cause; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1408 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1409 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1410 | return p; |
| 1411 | } |
| 1412 | |
| 1413 | stmt_ty |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 1414 | Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * |
| 1415 | finalbody, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1416 | { |
| 1417 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1418 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1419 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1420 | return NULL; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 1421 | p->kind = Try_kind; |
| 1422 | p->v.Try.body = body; |
| 1423 | p->v.Try.handlers = handlers; |
| 1424 | p->v.Try.orelse = orelse; |
| 1425 | p->v.Try.finalbody = finalbody; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1426 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1427 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1428 | return p; |
| 1429 | } |
| 1430 | |
| 1431 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1432 | 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] | 1433 | { |
| 1434 | stmt_ty p; |
| 1435 | if (!test) { |
| 1436 | PyErr_SetString(PyExc_ValueError, |
| 1437 | "field test is required for Assert"); |
| 1438 | return NULL; |
| 1439 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1440 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1441 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1442 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1443 | p->kind = Assert_kind; |
| 1444 | p->v.Assert.test = test; |
| 1445 | p->v.Assert.msg = msg; |
| 1446 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1447 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1448 | return p; |
| 1449 | } |
| 1450 | |
| 1451 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1452 | Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1453 | { |
| 1454 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1455 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1456 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1457 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1458 | p->kind = Import_kind; |
| 1459 | p->v.Import.names = names; |
| 1460 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1461 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1462 | return p; |
| 1463 | } |
| 1464 | |
| 1465 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1466 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
| 1467 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1468 | { |
| 1469 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1470 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1471 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1472 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1473 | p->kind = ImportFrom_kind; |
| 1474 | p->v.ImportFrom.module = module; |
| 1475 | p->v.ImportFrom.names = names; |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 1476 | p->v.ImportFrom.level = level; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1477 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1478 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1479 | return p; |
| 1480 | } |
| 1481 | |
| 1482 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1483 | Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1484 | { |
| 1485 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1486 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1487 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1488 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1489 | p->kind = Global_kind; |
| 1490 | p->v.Global.names = names; |
| 1491 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1492 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1493 | return p; |
| 1494 | } |
| 1495 | |
| 1496 | stmt_ty |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 1497 | Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
| 1498 | { |
| 1499 | stmt_ty p; |
| 1500 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1501 | if (!p) |
| 1502 | return NULL; |
| 1503 | p->kind = Nonlocal_kind; |
| 1504 | p->v.Nonlocal.names = names; |
| 1505 | p->lineno = lineno; |
| 1506 | p->col_offset = col_offset; |
| 1507 | return p; |
| 1508 | } |
| 1509 | |
| 1510 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1511 | Expr(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1512 | { |
| 1513 | stmt_ty p; |
| 1514 | if (!value) { |
| 1515 | PyErr_SetString(PyExc_ValueError, |
| 1516 | "field value is required for Expr"); |
| 1517 | return NULL; |
| 1518 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1519 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1520 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1521 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1522 | p->kind = Expr_kind; |
| 1523 | p->v.Expr.value = value; |
| 1524 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1525 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1526 | return p; |
| 1527 | } |
| 1528 | |
| 1529 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1530 | Pass(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1531 | { |
| 1532 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1533 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1534 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1535 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1536 | p->kind = Pass_kind; |
| 1537 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1538 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1539 | return p; |
| 1540 | } |
| 1541 | |
| 1542 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1543 | Break(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1544 | { |
| 1545 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1546 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1547 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1548 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1549 | p->kind = Break_kind; |
| 1550 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1551 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1552 | return p; |
| 1553 | } |
| 1554 | |
| 1555 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1556 | Continue(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1557 | { |
| 1558 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1559 | p = (stmt_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 = Continue_kind; |
| 1563 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1564 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1565 | return p; |
| 1566 | } |
| 1567 | |
| 1568 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1569 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1570 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1571 | { |
| 1572 | expr_ty p; |
| 1573 | if (!op) { |
| 1574 | PyErr_SetString(PyExc_ValueError, |
| 1575 | "field op is required for BoolOp"); |
| 1576 | return NULL; |
| 1577 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1578 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1579 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1580 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1581 | p->kind = BoolOp_kind; |
| 1582 | p->v.BoolOp.op = op; |
| 1583 | p->v.BoolOp.values = values; |
| 1584 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1585 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1586 | return p; |
| 1587 | } |
| 1588 | |
| 1589 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1590 | BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset, |
| 1591 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1592 | { |
| 1593 | expr_ty p; |
| 1594 | if (!left) { |
| 1595 | PyErr_SetString(PyExc_ValueError, |
| 1596 | "field left is required for BinOp"); |
| 1597 | return NULL; |
| 1598 | } |
| 1599 | if (!op) { |
| 1600 | PyErr_SetString(PyExc_ValueError, |
| 1601 | "field op is required for BinOp"); |
| 1602 | return NULL; |
| 1603 | } |
| 1604 | if (!right) { |
| 1605 | PyErr_SetString(PyExc_ValueError, |
| 1606 | "field right is required for BinOp"); |
| 1607 | return NULL; |
| 1608 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1609 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1610 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1611 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1612 | p->kind = BinOp_kind; |
| 1613 | p->v.BinOp.left = left; |
| 1614 | p->v.BinOp.op = op; |
| 1615 | p->v.BinOp.right = right; |
| 1616 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1617 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1618 | return p; |
| 1619 | } |
| 1620 | |
| 1621 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1622 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena |
| 1623 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1624 | { |
| 1625 | expr_ty p; |
| 1626 | if (!op) { |
| 1627 | PyErr_SetString(PyExc_ValueError, |
| 1628 | "field op is required for UnaryOp"); |
| 1629 | return NULL; |
| 1630 | } |
| 1631 | if (!operand) { |
| 1632 | PyErr_SetString(PyExc_ValueError, |
| 1633 | "field operand is required for UnaryOp"); |
| 1634 | return NULL; |
| 1635 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1636 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1637 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1638 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1639 | p->kind = UnaryOp_kind; |
| 1640 | p->v.UnaryOp.op = op; |
| 1641 | p->v.UnaryOp.operand = operand; |
| 1642 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1643 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1644 | return p; |
| 1645 | } |
| 1646 | |
| 1647 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1648 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena |
| 1649 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1650 | { |
| 1651 | expr_ty p; |
| 1652 | if (!args) { |
| 1653 | PyErr_SetString(PyExc_ValueError, |
| 1654 | "field args is required for Lambda"); |
| 1655 | return NULL; |
| 1656 | } |
| 1657 | if (!body) { |
| 1658 | PyErr_SetString(PyExc_ValueError, |
| 1659 | "field body is required for Lambda"); |
| 1660 | return NULL; |
| 1661 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1662 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1663 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1664 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1665 | p->kind = Lambda_kind; |
| 1666 | p->v.Lambda.args = args; |
| 1667 | p->v.Lambda.body = body; |
| 1668 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1669 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1670 | return p; |
| 1671 | } |
| 1672 | |
| 1673 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1674 | IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset, |
| 1675 | PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1676 | { |
| 1677 | expr_ty p; |
| 1678 | if (!test) { |
| 1679 | PyErr_SetString(PyExc_ValueError, |
| 1680 | "field test is required for IfExp"); |
| 1681 | return NULL; |
| 1682 | } |
| 1683 | if (!body) { |
| 1684 | PyErr_SetString(PyExc_ValueError, |
| 1685 | "field body is required for IfExp"); |
| 1686 | return NULL; |
| 1687 | } |
| 1688 | if (!orelse) { |
| 1689 | PyErr_SetString(PyExc_ValueError, |
| 1690 | "field orelse is required for IfExp"); |
| 1691 | return NULL; |
| 1692 | } |
| 1693 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1694 | if (!p) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1695 | return NULL; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1696 | p->kind = IfExp_kind; |
| 1697 | p->v.IfExp.test = test; |
| 1698 | p->v.IfExp.body = body; |
| 1699 | p->v.IfExp.orelse = orelse; |
| 1700 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1701 | p->col_offset = col_offset; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1702 | return p; |
| 1703 | } |
| 1704 | |
| 1705 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1706 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1707 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1708 | { |
| 1709 | expr_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1710 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1711 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1712 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1713 | p->kind = Dict_kind; |
| 1714 | p->v.Dict.keys = keys; |
| 1715 | p->v.Dict.values = values; |
| 1716 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1717 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1718 | return p; |
| 1719 | } |
| 1720 | |
| 1721 | expr_ty |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1722 | Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena) |
| 1723 | { |
| 1724 | expr_ty p; |
| 1725 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1726 | if (!p) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1727 | return NULL; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1728 | p->kind = Set_kind; |
| 1729 | p->v.Set.elts = elts; |
| 1730 | p->lineno = lineno; |
| 1731 | p->col_offset = col_offset; |
| 1732 | return p; |
| 1733 | } |
| 1734 | |
| 1735 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1736 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1737 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1738 | { |
| 1739 | expr_ty p; |
| 1740 | if (!elt) { |
| 1741 | PyErr_SetString(PyExc_ValueError, |
| 1742 | "field elt is required for ListComp"); |
| 1743 | return NULL; |
| 1744 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1745 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1746 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1747 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1748 | p->kind = ListComp_kind; |
| 1749 | p->v.ListComp.elt = elt; |
| 1750 | p->v.ListComp.generators = generators; |
| 1751 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1752 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1753 | return p; |
| 1754 | } |
| 1755 | |
| 1756 | expr_ty |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 1757 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena |
| 1758 | *arena) |
| 1759 | { |
| 1760 | expr_ty p; |
| 1761 | if (!elt) { |
| 1762 | PyErr_SetString(PyExc_ValueError, |
| 1763 | "field elt is required for SetComp"); |
| 1764 | return NULL; |
| 1765 | } |
| 1766 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1767 | if (!p) |
| 1768 | return NULL; |
| 1769 | p->kind = SetComp_kind; |
| 1770 | p->v.SetComp.elt = elt; |
| 1771 | p->v.SetComp.generators = generators; |
| 1772 | p->lineno = lineno; |
| 1773 | p->col_offset = col_offset; |
| 1774 | return p; |
| 1775 | } |
| 1776 | |
| 1777 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 1778 | DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int |
| 1779 | col_offset, PyArena *arena) |
| 1780 | { |
| 1781 | expr_ty p; |
| 1782 | if (!key) { |
| 1783 | PyErr_SetString(PyExc_ValueError, |
| 1784 | "field key is required for DictComp"); |
| 1785 | return NULL; |
| 1786 | } |
| 1787 | if (!value) { |
| 1788 | PyErr_SetString(PyExc_ValueError, |
| 1789 | "field value is required for DictComp"); |
| 1790 | return NULL; |
| 1791 | } |
| 1792 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1793 | if (!p) |
| 1794 | return NULL; |
| 1795 | p->kind = DictComp_kind; |
| 1796 | p->v.DictComp.key = key; |
| 1797 | p->v.DictComp.value = value; |
| 1798 | p->v.DictComp.generators = generators; |
| 1799 | p->lineno = lineno; |
| 1800 | p->col_offset = col_offset; |
| 1801 | return p; |
| 1802 | } |
| 1803 | |
| 1804 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1805 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1806 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1807 | { |
| 1808 | expr_ty p; |
| 1809 | if (!elt) { |
| 1810 | PyErr_SetString(PyExc_ValueError, |
| 1811 | "field elt is required for GeneratorExp"); |
| 1812 | return NULL; |
| 1813 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1814 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1815 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1816 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1817 | p->kind = GeneratorExp_kind; |
| 1818 | p->v.GeneratorExp.elt = elt; |
| 1819 | p->v.GeneratorExp.generators = generators; |
| 1820 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1821 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1822 | return p; |
| 1823 | } |
| 1824 | |
| 1825 | expr_ty |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 1826 | Yield(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1827 | { |
| 1828 | expr_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1829 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1830 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1831 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1832 | p->kind = Yield_kind; |
| 1833 | p->v.Yield.value = value; |
| 1834 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1835 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1836 | return p; |
| 1837 | } |
| 1838 | |
| 1839 | expr_ty |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 1840 | YieldFrom(expr_ty value, int lineno, int col_offset, PyArena *arena) |
| 1841 | { |
| 1842 | expr_ty p; |
Mark Dickinson | ded35ae | 2012-11-25 14:36:26 +0000 | [diff] [blame] | 1843 | if (!value) { |
| 1844 | PyErr_SetString(PyExc_ValueError, |
| 1845 | "field value is required for YieldFrom"); |
| 1846 | return NULL; |
| 1847 | } |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 1848 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1849 | if (!p) |
| 1850 | return NULL; |
| 1851 | p->kind = YieldFrom_kind; |
| 1852 | p->v.YieldFrom.value = value; |
| 1853 | p->lineno = lineno; |
| 1854 | p->col_offset = col_offset; |
| 1855 | return p; |
| 1856 | } |
| 1857 | |
| 1858 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1859 | Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno, |
| 1860 | int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1861 | { |
| 1862 | expr_ty p; |
| 1863 | if (!left) { |
| 1864 | PyErr_SetString(PyExc_ValueError, |
| 1865 | "field left is required for Compare"); |
| 1866 | return NULL; |
| 1867 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1868 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1869 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1870 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1871 | p->kind = Compare_kind; |
| 1872 | p->v.Compare.left = left; |
| 1873 | p->v.Compare.ops = ops; |
| 1874 | p->v.Compare.comparators = comparators; |
| 1875 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1876 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1877 | return p; |
| 1878 | } |
| 1879 | |
| 1880 | expr_ty |
| 1881 | 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] | 1882 | expr_ty kwargs, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1883 | { |
| 1884 | expr_ty p; |
| 1885 | if (!func) { |
| 1886 | PyErr_SetString(PyExc_ValueError, |
| 1887 | "field func is required for Call"); |
| 1888 | return NULL; |
| 1889 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1890 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1891 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1892 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1893 | p->kind = Call_kind; |
| 1894 | p->v.Call.func = func; |
| 1895 | p->v.Call.args = args; |
| 1896 | p->v.Call.keywords = keywords; |
| 1897 | p->v.Call.starargs = starargs; |
| 1898 | p->v.Call.kwargs = kwargs; |
| 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 | Num(object n, 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 (!n) { |
| 1909 | PyErr_SetString(PyExc_ValueError, |
| 1910 | "field n is required for Num"); |
| 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 = Num_kind; |
| 1917 | p->v.Num.n = n; |
| 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 |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1924 | Str(string s, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1925 | { |
| 1926 | expr_ty p; |
| 1927 | if (!s) { |
| 1928 | PyErr_SetString(PyExc_ValueError, |
| 1929 | "field s is required for Str"); |
| 1930 | return NULL; |
| 1931 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1932 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1933 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1934 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1935 | p->kind = Str_kind; |
| 1936 | p->v.Str.s = s; |
| 1937 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1938 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1939 | return p; |
| 1940 | } |
| 1941 | |
| 1942 | expr_ty |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 1943 | Bytes(bytes s, int lineno, int col_offset, PyArena *arena) |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1944 | { |
| 1945 | expr_ty p; |
| 1946 | if (!s) { |
| 1947 | PyErr_SetString(PyExc_ValueError, |
| 1948 | "field s is required for Bytes"); |
| 1949 | return NULL; |
| 1950 | } |
| 1951 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1952 | if (!p) |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1953 | return NULL; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1954 | p->kind = Bytes_kind; |
| 1955 | p->v.Bytes.s = s; |
| 1956 | p->lineno = lineno; |
| 1957 | p->col_offset = col_offset; |
| 1958 | return p; |
| 1959 | } |
| 1960 | |
| 1961 | expr_ty |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 1962 | NameConstant(singleton value, int lineno, int col_offset, PyArena *arena) |
| 1963 | { |
| 1964 | expr_ty p; |
| 1965 | if (!value) { |
| 1966 | PyErr_SetString(PyExc_ValueError, |
| 1967 | "field value is required for NameConstant"); |
| 1968 | return NULL; |
| 1969 | } |
| 1970 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1971 | if (!p) |
| 1972 | return NULL; |
| 1973 | p->kind = NameConstant_kind; |
| 1974 | p->v.NameConstant.value = value; |
| 1975 | p->lineno = lineno; |
| 1976 | p->col_offset = col_offset; |
| 1977 | return p; |
| 1978 | } |
| 1979 | |
| 1980 | expr_ty |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1981 | Ellipsis(int lineno, int col_offset, PyArena *arena) |
| 1982 | { |
| 1983 | expr_ty p; |
| 1984 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1985 | if (!p) |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1986 | return NULL; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1987 | p->kind = Ellipsis_kind; |
| 1988 | p->lineno = lineno; |
| 1989 | p->col_offset = col_offset; |
| 1990 | return p; |
| 1991 | } |
| 1992 | |
| 1993 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1994 | Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int |
| 1995 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1996 | { |
| 1997 | expr_ty p; |
| 1998 | if (!value) { |
| 1999 | PyErr_SetString(PyExc_ValueError, |
| 2000 | "field value is required for Attribute"); |
| 2001 | return NULL; |
| 2002 | } |
| 2003 | if (!attr) { |
| 2004 | PyErr_SetString(PyExc_ValueError, |
| 2005 | "field attr is required for Attribute"); |
| 2006 | return NULL; |
| 2007 | } |
| 2008 | if (!ctx) { |
| 2009 | PyErr_SetString(PyExc_ValueError, |
| 2010 | "field ctx is required for Attribute"); |
| 2011 | return NULL; |
| 2012 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2013 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2014 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2015 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2016 | p->kind = Attribute_kind; |
| 2017 | p->v.Attribute.value = value; |
| 2018 | p->v.Attribute.attr = attr; |
| 2019 | p->v.Attribute.ctx = ctx; |
| 2020 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2021 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2022 | return p; |
| 2023 | } |
| 2024 | |
| 2025 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2026 | Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int |
| 2027 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2028 | { |
| 2029 | expr_ty p; |
| 2030 | if (!value) { |
| 2031 | PyErr_SetString(PyExc_ValueError, |
| 2032 | "field value is required for Subscript"); |
| 2033 | return NULL; |
| 2034 | } |
| 2035 | if (!slice) { |
| 2036 | PyErr_SetString(PyExc_ValueError, |
| 2037 | "field slice is required for Subscript"); |
| 2038 | return NULL; |
| 2039 | } |
| 2040 | if (!ctx) { |
| 2041 | PyErr_SetString(PyExc_ValueError, |
| 2042 | "field ctx is required for Subscript"); |
| 2043 | return NULL; |
| 2044 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2045 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2046 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2047 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2048 | p->kind = Subscript_kind; |
| 2049 | p->v.Subscript.value = value; |
| 2050 | p->v.Subscript.slice = slice; |
| 2051 | p->v.Subscript.ctx = ctx; |
| 2052 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2053 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2054 | return p; |
| 2055 | } |
| 2056 | |
| 2057 | expr_ty |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2058 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 2059 | *arena) |
| 2060 | { |
| 2061 | expr_ty p; |
| 2062 | if (!value) { |
| 2063 | PyErr_SetString(PyExc_ValueError, |
| 2064 | "field value is required for Starred"); |
| 2065 | return NULL; |
| 2066 | } |
| 2067 | if (!ctx) { |
| 2068 | PyErr_SetString(PyExc_ValueError, |
| 2069 | "field ctx is required for Starred"); |
| 2070 | return NULL; |
| 2071 | } |
| 2072 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2073 | if (!p) |
| 2074 | return NULL; |
| 2075 | p->kind = Starred_kind; |
| 2076 | p->v.Starred.value = value; |
| 2077 | p->v.Starred.ctx = ctx; |
| 2078 | p->lineno = lineno; |
| 2079 | p->col_offset = col_offset; |
| 2080 | return p; |
| 2081 | } |
| 2082 | |
| 2083 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2084 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 2085 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2086 | { |
| 2087 | expr_ty p; |
| 2088 | if (!id) { |
| 2089 | PyErr_SetString(PyExc_ValueError, |
| 2090 | "field id is required for Name"); |
| 2091 | return NULL; |
| 2092 | } |
| 2093 | if (!ctx) { |
| 2094 | PyErr_SetString(PyExc_ValueError, |
| 2095 | "field ctx is required for Name"); |
| 2096 | return NULL; |
| 2097 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2098 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2099 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2100 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2101 | p->kind = Name_kind; |
| 2102 | p->v.Name.id = id; |
| 2103 | p->v.Name.ctx = ctx; |
| 2104 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2105 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2106 | return p; |
| 2107 | } |
| 2108 | |
| 2109 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2110 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 2111 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2112 | { |
| 2113 | expr_ty p; |
| 2114 | if (!ctx) { |
| 2115 | PyErr_SetString(PyExc_ValueError, |
| 2116 | "field ctx is required for List"); |
| 2117 | return NULL; |
| 2118 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2119 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2120 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2121 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2122 | p->kind = List_kind; |
| 2123 | p->v.List.elts = elts; |
| 2124 | p->v.List.ctx = ctx; |
| 2125 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2126 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2127 | return p; |
| 2128 | } |
| 2129 | |
| 2130 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2131 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 2132 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2133 | { |
| 2134 | expr_ty p; |
| 2135 | if (!ctx) { |
| 2136 | PyErr_SetString(PyExc_ValueError, |
| 2137 | "field ctx is required for Tuple"); |
| 2138 | return NULL; |
| 2139 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2140 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2141 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2142 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2143 | p->kind = Tuple_kind; |
| 2144 | p->v.Tuple.elts = elts; |
| 2145 | p->v.Tuple.ctx = ctx; |
| 2146 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2147 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2148 | return p; |
| 2149 | } |
| 2150 | |
| 2151 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2152 | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2153 | { |
| 2154 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2155 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2156 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2157 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2158 | p->kind = Slice_kind; |
| 2159 | p->v.Slice.lower = lower; |
| 2160 | p->v.Slice.upper = upper; |
| 2161 | p->v.Slice.step = step; |
| 2162 | return p; |
| 2163 | } |
| 2164 | |
| 2165 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2166 | ExtSlice(asdl_seq * dims, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2167 | { |
| 2168 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2169 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2170 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2171 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2172 | p->kind = ExtSlice_kind; |
| 2173 | p->v.ExtSlice.dims = dims; |
| 2174 | return p; |
| 2175 | } |
| 2176 | |
| 2177 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2178 | Index(expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2179 | { |
| 2180 | slice_ty p; |
| 2181 | if (!value) { |
| 2182 | PyErr_SetString(PyExc_ValueError, |
| 2183 | "field value is required for Index"); |
| 2184 | return NULL; |
| 2185 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2186 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2187 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2188 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2189 | p->kind = Index_kind; |
| 2190 | p->v.Index.value = value; |
| 2191 | return p; |
| 2192 | } |
| 2193 | |
| 2194 | comprehension_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2195 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2196 | { |
| 2197 | comprehension_ty p; |
| 2198 | if (!target) { |
| 2199 | PyErr_SetString(PyExc_ValueError, |
| 2200 | "field target is required for comprehension"); |
| 2201 | return NULL; |
| 2202 | } |
| 2203 | if (!iter) { |
| 2204 | PyErr_SetString(PyExc_ValueError, |
| 2205 | "field iter is required for comprehension"); |
| 2206 | return NULL; |
| 2207 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2208 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2209 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2210 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2211 | p->target = target; |
| 2212 | p->iter = iter; |
| 2213 | p->ifs = ifs; |
| 2214 | return p; |
| 2215 | } |
| 2216 | |
| 2217 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 2218 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2219 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2220 | { |
| 2221 | excepthandler_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2222 | p = (excepthandler_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; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 2225 | p->kind = ExceptHandler_kind; |
| 2226 | p->v.ExceptHandler.type = type; |
| 2227 | p->v.ExceptHandler.name = name; |
| 2228 | p->v.ExceptHandler.body = body; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2229 | p->lineno = lineno; |
| 2230 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2231 | return p; |
| 2232 | } |
| 2233 | |
| 2234 | arguments_ty |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 2235 | arguments(asdl_seq * args, arg_ty vararg, asdl_seq * kwonlyargs, asdl_seq * |
| 2236 | kw_defaults, arg_ty kwarg, asdl_seq * defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2237 | { |
| 2238 | arguments_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2239 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2240 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2241 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2242 | p->args = args; |
| 2243 | p->vararg = vararg; |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 2244 | p->kwonlyargs = kwonlyargs; |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 2245 | p->kw_defaults = kw_defaults; |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 2246 | p->kwarg = kwarg; |
| 2247 | p->defaults = defaults; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2248 | return p; |
| 2249 | } |
| 2250 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2251 | arg_ty |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2252 | arg(identifier arg, expr_ty annotation, PyArena *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2253 | { |
| 2254 | arg_ty p; |
| 2255 | if (!arg) { |
| 2256 | PyErr_SetString(PyExc_ValueError, |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2257 | "field arg is required for arg"); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2258 | return NULL; |
| 2259 | } |
| 2260 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2261 | if (!p) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2262 | return NULL; |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2263 | p->arg = arg; |
| 2264 | p->annotation = annotation; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2265 | return p; |
| 2266 | } |
| 2267 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2268 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2269 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2270 | { |
| 2271 | keyword_ty p; |
| 2272 | if (!arg) { |
| 2273 | PyErr_SetString(PyExc_ValueError, |
| 2274 | "field arg is required for keyword"); |
| 2275 | return NULL; |
| 2276 | } |
| 2277 | if (!value) { |
| 2278 | PyErr_SetString(PyExc_ValueError, |
| 2279 | "field value is required for keyword"); |
| 2280 | return NULL; |
| 2281 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2282 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2283 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2284 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2285 | p->arg = arg; |
| 2286 | p->value = value; |
| 2287 | return p; |
| 2288 | } |
| 2289 | |
| 2290 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2291 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2292 | { |
| 2293 | alias_ty p; |
| 2294 | if (!name) { |
| 2295 | PyErr_SetString(PyExc_ValueError, |
| 2296 | "field name is required for alias"); |
| 2297 | return NULL; |
| 2298 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2299 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2300 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2301 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2302 | p->name = name; |
| 2303 | p->asname = asname; |
| 2304 | return p; |
| 2305 | } |
| 2306 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2307 | withitem_ty |
| 2308 | withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) |
| 2309 | { |
| 2310 | withitem_ty p; |
| 2311 | if (!context_expr) { |
| 2312 | PyErr_SetString(PyExc_ValueError, |
| 2313 | "field context_expr is required for withitem"); |
| 2314 | return NULL; |
| 2315 | } |
| 2316 | p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2317 | if (!p) |
| 2318 | return NULL; |
| 2319 | p->context_expr = context_expr; |
| 2320 | p->optional_vars = optional_vars; |
| 2321 | return p; |
| 2322 | } |
| 2323 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2324 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2325 | PyObject* |
| 2326 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2327 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2328 | mod_ty o = (mod_ty)_o; |
| 2329 | PyObject *result = NULL, *value = NULL; |
| 2330 | if (!o) { |
| 2331 | Py_INCREF(Py_None); |
| 2332 | return Py_None; |
| 2333 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2334 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2335 | switch (o->kind) { |
| 2336 | case Module_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2337 | result = PyType_GenericNew(Module_type, NULL, NULL); |
| 2338 | if (!result) goto failed; |
| 2339 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 2340 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2341 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2342 | goto failed; |
| 2343 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2344 | break; |
| 2345 | case Interactive_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2346 | result = PyType_GenericNew(Interactive_type, NULL, NULL); |
| 2347 | if (!result) goto failed; |
| 2348 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 2349 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2350 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2351 | goto failed; |
| 2352 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2353 | break; |
| 2354 | case Expression_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2355 | result = PyType_GenericNew(Expression_type, NULL, NULL); |
| 2356 | if (!result) goto failed; |
| 2357 | value = ast2obj_expr(o->v.Expression.body); |
| 2358 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2359 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2360 | goto failed; |
| 2361 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2362 | break; |
| 2363 | case Suite_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2364 | result = PyType_GenericNew(Suite_type, NULL, NULL); |
| 2365 | if (!result) goto failed; |
| 2366 | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
| 2367 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2368 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2369 | goto failed; |
| 2370 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2371 | break; |
| 2372 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2373 | return result; |
| 2374 | failed: |
| 2375 | Py_XDECREF(value); |
| 2376 | Py_XDECREF(result); |
| 2377 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2378 | } |
| 2379 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2380 | PyObject* |
| 2381 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2382 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2383 | stmt_ty o = (stmt_ty)_o; |
| 2384 | PyObject *result = NULL, *value = NULL; |
| 2385 | if (!o) { |
| 2386 | Py_INCREF(Py_None); |
| 2387 | return Py_None; |
| 2388 | } |
| 2389 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2390 | switch (o->kind) { |
| 2391 | case FunctionDef_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2392 | result = PyType_GenericNew(FunctionDef_type, NULL, NULL); |
| 2393 | if (!result) goto failed; |
| 2394 | value = ast2obj_identifier(o->v.FunctionDef.name); |
| 2395 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2396 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2397 | goto failed; |
| 2398 | Py_DECREF(value); |
| 2399 | value = ast2obj_arguments(o->v.FunctionDef.args); |
| 2400 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2401 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2402 | goto failed; |
| 2403 | Py_DECREF(value); |
| 2404 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 2405 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2406 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2407 | goto failed; |
| 2408 | Py_DECREF(value); |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2409 | value = ast2obj_list(o->v.FunctionDef.decorator_list, |
| 2410 | ast2obj_expr); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 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_decorator_list, value) == |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2413 | -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2414 | goto failed; |
| 2415 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2416 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 2417 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2418 | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2419 | goto failed; |
| 2420 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2421 | break; |
| 2422 | case ClassDef_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2423 | result = PyType_GenericNew(ClassDef_type, NULL, NULL); |
| 2424 | if (!result) goto failed; |
| 2425 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 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_name, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2428 | goto failed; |
| 2429 | Py_DECREF(value); |
| 2430 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 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_bases, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2433 | goto failed; |
| 2434 | Py_DECREF(value); |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 2435 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 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_keywords, value) == -1) |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 2438 | goto failed; |
| 2439 | Py_DECREF(value); |
| 2440 | value = ast2obj_expr(o->v.ClassDef.starargs); |
| 2441 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2442 | if (_PyObject_SetAttrId(result, &PyId_starargs, value) == -1) |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 2443 | goto failed; |
| 2444 | Py_DECREF(value); |
| 2445 | value = ast2obj_expr(o->v.ClassDef.kwargs); |
| 2446 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2447 | if (_PyObject_SetAttrId(result, &PyId_kwargs, value) == -1) |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 2448 | goto failed; |
| 2449 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2450 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 2451 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2452 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2453 | goto failed; |
| 2454 | Py_DECREF(value); |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2455 | value = ast2obj_list(o->v.ClassDef.decorator_list, |
| 2456 | ast2obj_expr); |
| 2457 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2458 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2459 | -1) |
| 2460 | goto failed; |
| 2461 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2462 | break; |
| 2463 | case Return_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2464 | result = PyType_GenericNew(Return_type, NULL, NULL); |
| 2465 | if (!result) goto failed; |
| 2466 | value = ast2obj_expr(o->v.Return.value); |
| 2467 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2468 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2469 | goto failed; |
| 2470 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2471 | break; |
| 2472 | case Delete_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2473 | result = PyType_GenericNew(Delete_type, NULL, NULL); |
| 2474 | if (!result) goto failed; |
| 2475 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 2476 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2477 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2478 | goto failed; |
| 2479 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2480 | break; |
| 2481 | case Assign_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2482 | result = PyType_GenericNew(Assign_type, NULL, NULL); |
| 2483 | if (!result) goto failed; |
| 2484 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 2485 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2486 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2487 | goto failed; |
| 2488 | Py_DECREF(value); |
| 2489 | value = ast2obj_expr(o->v.Assign.value); |
| 2490 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2491 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2492 | goto failed; |
| 2493 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2494 | break; |
| 2495 | case AugAssign_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2496 | result = PyType_GenericNew(AugAssign_type, NULL, NULL); |
| 2497 | if (!result) goto failed; |
| 2498 | value = ast2obj_expr(o->v.AugAssign.target); |
| 2499 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2500 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2501 | goto failed; |
| 2502 | Py_DECREF(value); |
| 2503 | value = ast2obj_operator(o->v.AugAssign.op); |
| 2504 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2505 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2506 | goto failed; |
| 2507 | Py_DECREF(value); |
| 2508 | value = ast2obj_expr(o->v.AugAssign.value); |
| 2509 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2510 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2511 | goto failed; |
| 2512 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2513 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2514 | case For_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2515 | result = PyType_GenericNew(For_type, NULL, NULL); |
| 2516 | if (!result) goto failed; |
| 2517 | value = ast2obj_expr(o->v.For.target); |
| 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_target, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2520 | goto failed; |
| 2521 | Py_DECREF(value); |
| 2522 | value = ast2obj_expr(o->v.For.iter); |
| 2523 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2524 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2525 | goto failed; |
| 2526 | Py_DECREF(value); |
| 2527 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 2528 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2529 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2530 | goto failed; |
| 2531 | Py_DECREF(value); |
| 2532 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 2533 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2534 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2535 | goto failed; |
| 2536 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2537 | break; |
| 2538 | case While_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2539 | result = PyType_GenericNew(While_type, NULL, NULL); |
| 2540 | if (!result) goto failed; |
| 2541 | value = ast2obj_expr(o->v.While.test); |
| 2542 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2543 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2544 | goto failed; |
| 2545 | Py_DECREF(value); |
| 2546 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 2547 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2548 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2549 | goto failed; |
| 2550 | Py_DECREF(value); |
| 2551 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 2552 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2553 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2554 | goto failed; |
| 2555 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2556 | break; |
| 2557 | case If_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2558 | result = PyType_GenericNew(If_type, NULL, NULL); |
| 2559 | if (!result) goto failed; |
| 2560 | value = ast2obj_expr(o->v.If.test); |
| 2561 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2562 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2563 | goto failed; |
| 2564 | Py_DECREF(value); |
| 2565 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 2566 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2567 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2568 | goto failed; |
| 2569 | Py_DECREF(value); |
| 2570 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 2571 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2572 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2573 | goto failed; |
| 2574 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2575 | break; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2576 | case With_kind: |
| 2577 | result = PyType_GenericNew(With_type, NULL, NULL); |
| 2578 | if (!result) goto failed; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2579 | value = ast2obj_list(o->v.With.items, ast2obj_withitem); |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2580 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2581 | if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2582 | goto failed; |
| 2583 | Py_DECREF(value); |
| 2584 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 2585 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2586 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2587 | goto failed; |
| 2588 | Py_DECREF(value); |
| 2589 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2590 | case Raise_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2591 | result = PyType_GenericNew(Raise_type, NULL, NULL); |
| 2592 | if (!result) goto failed; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2593 | value = ast2obj_expr(o->v.Raise.exc); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2594 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2595 | if (_PyObject_SetAttrId(result, &PyId_exc, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2596 | goto failed; |
| 2597 | Py_DECREF(value); |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2598 | value = ast2obj_expr(o->v.Raise.cause); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2599 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2600 | if (_PyObject_SetAttrId(result, &PyId_cause, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2601 | goto failed; |
| 2602 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2603 | break; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2604 | case Try_kind: |
| 2605 | result = PyType_GenericNew(Try_type, NULL, NULL); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2606 | if (!result) goto failed; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2607 | value = ast2obj_list(o->v.Try.body, 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_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2610 | goto failed; |
| 2611 | Py_DECREF(value); |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2612 | value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2613 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2614 | if (_PyObject_SetAttrId(result, &PyId_handlers, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2615 | goto failed; |
| 2616 | Py_DECREF(value); |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2617 | value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2618 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2619 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2620 | goto failed; |
| 2621 | Py_DECREF(value); |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2622 | value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2623 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2624 | if (_PyObject_SetAttrId(result, &PyId_finalbody, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2625 | goto failed; |
| 2626 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2627 | break; |
| 2628 | case Assert_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2629 | result = PyType_GenericNew(Assert_type, NULL, NULL); |
| 2630 | if (!result) goto failed; |
| 2631 | value = ast2obj_expr(o->v.Assert.test); |
| 2632 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2633 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2634 | goto failed; |
| 2635 | Py_DECREF(value); |
| 2636 | value = ast2obj_expr(o->v.Assert.msg); |
| 2637 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2638 | if (_PyObject_SetAttrId(result, &PyId_msg, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2639 | goto failed; |
| 2640 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2641 | break; |
| 2642 | case Import_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2643 | result = PyType_GenericNew(Import_type, NULL, NULL); |
| 2644 | if (!result) goto failed; |
| 2645 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 2646 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2647 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2648 | goto failed; |
| 2649 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2650 | break; |
| 2651 | case ImportFrom_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2652 | result = PyType_GenericNew(ImportFrom_type, NULL, NULL); |
| 2653 | if (!result) goto failed; |
| 2654 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 2655 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2656 | if (_PyObject_SetAttrId(result, &PyId_module, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2657 | goto failed; |
| 2658 | Py_DECREF(value); |
| 2659 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 2660 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2661 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2662 | goto failed; |
| 2663 | Py_DECREF(value); |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 2664 | value = ast2obj_int(o->v.ImportFrom.level); |
| 2665 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2666 | if (_PyObject_SetAttrId(result, &PyId_level, value) == -1) |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 2667 | goto failed; |
| 2668 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2669 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2670 | case Global_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2671 | result = PyType_GenericNew(Global_type, NULL, NULL); |
| 2672 | if (!result) goto failed; |
| 2673 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 2674 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2675 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2676 | goto failed; |
| 2677 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2678 | break; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2679 | case Nonlocal_kind: |
| 2680 | result = PyType_GenericNew(Nonlocal_type, NULL, NULL); |
| 2681 | if (!result) goto failed; |
| 2682 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 2683 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2684 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2685 | goto failed; |
| 2686 | Py_DECREF(value); |
| 2687 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2688 | case Expr_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2689 | result = PyType_GenericNew(Expr_type, NULL, NULL); |
| 2690 | if (!result) goto failed; |
| 2691 | value = ast2obj_expr(o->v.Expr.value); |
| 2692 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2693 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2694 | goto failed; |
| 2695 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2696 | break; |
| 2697 | case Pass_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2698 | result = PyType_GenericNew(Pass_type, NULL, NULL); |
| 2699 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2700 | break; |
| 2701 | case Break_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2702 | result = PyType_GenericNew(Break_type, NULL, NULL); |
| 2703 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2704 | break; |
| 2705 | case Continue_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2706 | result = PyType_GenericNew(Continue_type, NULL, NULL); |
| 2707 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2708 | break; |
| 2709 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2710 | value = ast2obj_int(o->lineno); |
| 2711 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2712 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2713 | goto failed; |
| 2714 | Py_DECREF(value); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2715 | value = ast2obj_int(o->col_offset); |
| 2716 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2717 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2718 | goto failed; |
| 2719 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2720 | return result; |
| 2721 | failed: |
| 2722 | Py_XDECREF(value); |
| 2723 | Py_XDECREF(result); |
| 2724 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2725 | } |
| 2726 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2727 | PyObject* |
| 2728 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2729 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2730 | expr_ty o = (expr_ty)_o; |
| 2731 | PyObject *result = NULL, *value = NULL; |
| 2732 | if (!o) { |
| 2733 | Py_INCREF(Py_None); |
| 2734 | return Py_None; |
| 2735 | } |
| 2736 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2737 | switch (o->kind) { |
| 2738 | case BoolOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2739 | result = PyType_GenericNew(BoolOp_type, NULL, NULL); |
| 2740 | if (!result) goto failed; |
| 2741 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 2742 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2743 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2744 | goto failed; |
| 2745 | Py_DECREF(value); |
| 2746 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 2747 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2748 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2749 | goto failed; |
| 2750 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2751 | break; |
| 2752 | case BinOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2753 | result = PyType_GenericNew(BinOp_type, NULL, NULL); |
| 2754 | if (!result) goto failed; |
| 2755 | value = ast2obj_expr(o->v.BinOp.left); |
| 2756 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2757 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2758 | goto failed; |
| 2759 | Py_DECREF(value); |
| 2760 | value = ast2obj_operator(o->v.BinOp.op); |
| 2761 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2762 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2763 | goto failed; |
| 2764 | Py_DECREF(value); |
| 2765 | value = ast2obj_expr(o->v.BinOp.right); |
| 2766 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2767 | if (_PyObject_SetAttrId(result, &PyId_right, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2768 | goto failed; |
| 2769 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2770 | break; |
| 2771 | case UnaryOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2772 | result = PyType_GenericNew(UnaryOp_type, NULL, NULL); |
| 2773 | if (!result) goto failed; |
| 2774 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 2775 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2776 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2777 | goto failed; |
| 2778 | Py_DECREF(value); |
| 2779 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 2780 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2781 | if (_PyObject_SetAttrId(result, &PyId_operand, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2782 | goto failed; |
| 2783 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2784 | break; |
| 2785 | case Lambda_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2786 | result = PyType_GenericNew(Lambda_type, NULL, NULL); |
| 2787 | if (!result) goto failed; |
| 2788 | value = ast2obj_arguments(o->v.Lambda.args); |
| 2789 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2790 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2791 | goto failed; |
| 2792 | Py_DECREF(value); |
| 2793 | value = ast2obj_expr(o->v.Lambda.body); |
| 2794 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2795 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2796 | goto failed; |
| 2797 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2798 | break; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2799 | case IfExp_kind: |
| 2800 | result = PyType_GenericNew(IfExp_type, NULL, NULL); |
| 2801 | if (!result) goto failed; |
| 2802 | value = ast2obj_expr(o->v.IfExp.test); |
| 2803 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2804 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2805 | goto failed; |
| 2806 | Py_DECREF(value); |
| 2807 | value = ast2obj_expr(o->v.IfExp.body); |
| 2808 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2809 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2810 | goto failed; |
| 2811 | Py_DECREF(value); |
| 2812 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 2813 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2814 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2815 | goto failed; |
| 2816 | Py_DECREF(value); |
| 2817 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2818 | case Dict_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2819 | result = PyType_GenericNew(Dict_type, NULL, NULL); |
| 2820 | if (!result) goto failed; |
| 2821 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 2822 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2823 | if (_PyObject_SetAttrId(result, &PyId_keys, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2824 | goto failed; |
| 2825 | Py_DECREF(value); |
| 2826 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 2827 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2828 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2829 | goto failed; |
| 2830 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2831 | break; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2832 | case Set_kind: |
| 2833 | result = PyType_GenericNew(Set_type, NULL, NULL); |
| 2834 | if (!result) goto failed; |
| 2835 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 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_elts, value) == -1) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2838 | goto failed; |
| 2839 | Py_DECREF(value); |
| 2840 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2841 | case ListComp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2842 | result = PyType_GenericNew(ListComp_type, NULL, NULL); |
| 2843 | if (!result) goto failed; |
| 2844 | value = ast2obj_expr(o->v.ListComp.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) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2847 | goto failed; |
| 2848 | Py_DECREF(value); |
| 2849 | value = ast2obj_list(o->v.ListComp.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) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2853 | goto failed; |
| 2854 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2855 | break; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2856 | case SetComp_kind: |
| 2857 | result = PyType_GenericNew(SetComp_type, NULL, NULL); |
| 2858 | if (!result) goto failed; |
| 2859 | value = ast2obj_expr(o->v.SetComp.elt); |
| 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_elt, value) == -1) |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2862 | goto failed; |
| 2863 | Py_DECREF(value); |
| 2864 | value = ast2obj_list(o->v.SetComp.generators, |
| 2865 | ast2obj_comprehension); |
| 2866 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2867 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2868 | goto failed; |
| 2869 | Py_DECREF(value); |
| 2870 | break; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2871 | case DictComp_kind: |
| 2872 | result = PyType_GenericNew(DictComp_type, NULL, NULL); |
| 2873 | if (!result) goto failed; |
| 2874 | value = ast2obj_expr(o->v.DictComp.key); |
| 2875 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2876 | if (_PyObject_SetAttrId(result, &PyId_key, value) == -1) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2877 | goto failed; |
| 2878 | Py_DECREF(value); |
| 2879 | value = ast2obj_expr(o->v.DictComp.value); |
| 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_value, value) == -1) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2882 | goto failed; |
| 2883 | Py_DECREF(value); |
| 2884 | value = ast2obj_list(o->v.DictComp.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) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2888 | goto failed; |
| 2889 | Py_DECREF(value); |
| 2890 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2891 | case GeneratorExp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2892 | result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); |
| 2893 | if (!result) goto failed; |
| 2894 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 2895 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2896 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2897 | goto failed; |
| 2898 | Py_DECREF(value); |
| 2899 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 2900 | ast2obj_comprehension); |
| 2901 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2902 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2903 | goto failed; |
| 2904 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2905 | break; |
| 2906 | case Yield_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2907 | result = PyType_GenericNew(Yield_type, NULL, NULL); |
| 2908 | if (!result) goto failed; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2909 | value = ast2obj_expr(o->v.Yield.value); |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 2910 | if (!value) goto failed; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2911 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 2912 | goto failed; |
| 2913 | Py_DECREF(value); |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2914 | break; |
| 2915 | case YieldFrom_kind: |
| 2916 | result = PyType_GenericNew(YieldFrom_type, NULL, NULL); |
| 2917 | if (!result) goto failed; |
| 2918 | value = ast2obj_expr(o->v.YieldFrom.value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2919 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2920 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2921 | goto failed; |
| 2922 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2923 | break; |
| 2924 | case Compare_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2925 | result = PyType_GenericNew(Compare_type, NULL, NULL); |
| 2926 | if (!result) goto failed; |
| 2927 | value = ast2obj_expr(o->v.Compare.left); |
| 2928 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2929 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2930 | goto failed; |
| 2931 | Py_DECREF(value); |
Martin v. Löwis | ce1d5d2 | 2006-02-26 20:51:25 +0000 | [diff] [blame] | 2932 | { |
Benjamin Peterson | 77fa937 | 2012-05-15 10:10:27 -0700 | [diff] [blame] | 2933 | 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] | 2934 | value = PyList_New(n); |
| 2935 | if (!value) goto failed; |
| 2936 | for(i = 0; i < n; i++) |
| 2937 | PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i))); |
| 2938 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2939 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2940 | if (_PyObject_SetAttrId(result, &PyId_ops, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2941 | goto failed; |
| 2942 | Py_DECREF(value); |
| 2943 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
| 2944 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2945 | if (_PyObject_SetAttrId(result, &PyId_comparators, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2946 | goto failed; |
| 2947 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2948 | break; |
| 2949 | case Call_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2950 | result = PyType_GenericNew(Call_type, NULL, NULL); |
| 2951 | if (!result) goto failed; |
| 2952 | value = ast2obj_expr(o->v.Call.func); |
| 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_func, 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_list(o->v.Call.args, ast2obj_expr); |
| 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_args, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2960 | goto failed; |
| 2961 | Py_DECREF(value); |
| 2962 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 2963 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2964 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2965 | goto failed; |
| 2966 | Py_DECREF(value); |
| 2967 | value = ast2obj_expr(o->v.Call.starargs); |
| 2968 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2969 | if (_PyObject_SetAttrId(result, &PyId_starargs, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2970 | goto failed; |
| 2971 | Py_DECREF(value); |
| 2972 | value = ast2obj_expr(o->v.Call.kwargs); |
| 2973 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2974 | if (_PyObject_SetAttrId(result, &PyId_kwargs, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2975 | goto failed; |
| 2976 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2977 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2978 | case Num_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2979 | result = PyType_GenericNew(Num_type, NULL, NULL); |
| 2980 | if (!result) goto failed; |
| 2981 | value = ast2obj_object(o->v.Num.n); |
| 2982 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2983 | if (_PyObject_SetAttrId(result, &PyId_n, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2984 | goto failed; |
| 2985 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2986 | break; |
| 2987 | case Str_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2988 | result = PyType_GenericNew(Str_type, NULL, NULL); |
| 2989 | if (!result) goto failed; |
| 2990 | value = ast2obj_string(o->v.Str.s); |
| 2991 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2992 | if (_PyObject_SetAttrId(result, &PyId_s, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2993 | goto failed; |
| 2994 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2995 | break; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 2996 | case Bytes_kind: |
| 2997 | result = PyType_GenericNew(Bytes_type, NULL, NULL); |
| 2998 | if (!result) goto failed; |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 2999 | value = ast2obj_bytes(o->v.Bytes.s); |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 3000 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3001 | if (_PyObject_SetAttrId(result, &PyId_s, value) == -1) |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 3002 | goto failed; |
| 3003 | Py_DECREF(value); |
| 3004 | break; |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 3005 | case NameConstant_kind: |
| 3006 | result = PyType_GenericNew(NameConstant_type, NULL, NULL); |
| 3007 | if (!result) goto failed; |
| 3008 | value = ast2obj_singleton(o->v.NameConstant.value); |
| 3009 | if (!value) goto failed; |
| 3010 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3011 | goto failed; |
| 3012 | Py_DECREF(value); |
| 3013 | break; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 3014 | case Ellipsis_kind: |
| 3015 | result = PyType_GenericNew(Ellipsis_type, NULL, NULL); |
| 3016 | if (!result) goto failed; |
| 3017 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3018 | case Attribute_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3019 | result = PyType_GenericNew(Attribute_type, NULL, NULL); |
| 3020 | if (!result) goto failed; |
| 3021 | value = ast2obj_expr(o->v.Attribute.value); |
| 3022 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3023 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3024 | goto failed; |
| 3025 | Py_DECREF(value); |
| 3026 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 3027 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3028 | if (_PyObject_SetAttrId(result, &PyId_attr, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3029 | goto failed; |
| 3030 | Py_DECREF(value); |
| 3031 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 3032 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3033 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3034 | goto failed; |
| 3035 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3036 | break; |
| 3037 | case Subscript_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3038 | result = PyType_GenericNew(Subscript_type, NULL, NULL); |
| 3039 | if (!result) goto failed; |
| 3040 | value = ast2obj_expr(o->v.Subscript.value); |
| 3041 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3042 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3043 | goto failed; |
| 3044 | Py_DECREF(value); |
| 3045 | value = ast2obj_slice(o->v.Subscript.slice); |
| 3046 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3047 | if (_PyObject_SetAttrId(result, &PyId_slice, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3048 | goto failed; |
| 3049 | Py_DECREF(value); |
| 3050 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 3051 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3052 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3053 | goto failed; |
| 3054 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3055 | break; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 3056 | case Starred_kind: |
| 3057 | result = PyType_GenericNew(Starred_type, NULL, NULL); |
| 3058 | if (!result) goto failed; |
| 3059 | value = ast2obj_expr(o->v.Starred.value); |
| 3060 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3061 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 3062 | goto failed; |
| 3063 | Py_DECREF(value); |
| 3064 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 3065 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3066 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 3067 | goto failed; |
| 3068 | Py_DECREF(value); |
| 3069 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3070 | case Name_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3071 | result = PyType_GenericNew(Name_type, NULL, NULL); |
| 3072 | if (!result) goto failed; |
| 3073 | value = ast2obj_identifier(o->v.Name.id); |
| 3074 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3075 | if (_PyObject_SetAttrId(result, &PyId_id, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3076 | goto failed; |
| 3077 | Py_DECREF(value); |
| 3078 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 3079 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3080 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3081 | goto failed; |
| 3082 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3083 | break; |
| 3084 | case List_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3085 | result = PyType_GenericNew(List_type, NULL, NULL); |
| 3086 | if (!result) goto failed; |
| 3087 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 3088 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3089 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3090 | goto failed; |
| 3091 | Py_DECREF(value); |
| 3092 | value = ast2obj_expr_context(o->v.List.ctx); |
| 3093 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3094 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3095 | goto failed; |
| 3096 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3097 | break; |
| 3098 | case Tuple_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3099 | result = PyType_GenericNew(Tuple_type, NULL, NULL); |
| 3100 | if (!result) goto failed; |
| 3101 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 3102 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3103 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3104 | goto failed; |
| 3105 | Py_DECREF(value); |
| 3106 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 3107 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3108 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3109 | goto failed; |
| 3110 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3111 | break; |
| 3112 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 3113 | value = ast2obj_int(o->lineno); |
| 3114 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3115 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3116 | goto failed; |
| 3117 | Py_DECREF(value); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3118 | value = ast2obj_int(o->col_offset); |
| 3119 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3120 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3121 | goto failed; |
| 3122 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3123 | return result; |
| 3124 | failed: |
| 3125 | Py_XDECREF(value); |
| 3126 | Py_XDECREF(result); |
| 3127 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3128 | } |
| 3129 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3130 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3131 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3132 | switch(o) { |
| 3133 | case Load: |
| 3134 | Py_INCREF(Load_singleton); |
| 3135 | return Load_singleton; |
| 3136 | case Store: |
| 3137 | Py_INCREF(Store_singleton); |
| 3138 | return Store_singleton; |
| 3139 | case Del: |
| 3140 | Py_INCREF(Del_singleton); |
| 3141 | return Del_singleton; |
| 3142 | case AugLoad: |
| 3143 | Py_INCREF(AugLoad_singleton); |
| 3144 | return AugLoad_singleton; |
| 3145 | case AugStore: |
| 3146 | Py_INCREF(AugStore_singleton); |
| 3147 | return AugStore_singleton; |
| 3148 | case Param: |
| 3149 | Py_INCREF(Param_singleton); |
| 3150 | return Param_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3151 | default: |
| 3152 | /* should never happen, but just in case ... */ |
| 3153 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 3154 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3155 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3156 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3157 | PyObject* |
| 3158 | ast2obj_slice(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3159 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3160 | slice_ty o = (slice_ty)_o; |
| 3161 | PyObject *result = NULL, *value = NULL; |
| 3162 | if (!o) { |
| 3163 | Py_INCREF(Py_None); |
| 3164 | return Py_None; |
| 3165 | } |
| 3166 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3167 | switch (o->kind) { |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3168 | case Slice_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3169 | result = PyType_GenericNew(Slice_type, NULL, NULL); |
| 3170 | if (!result) goto failed; |
| 3171 | value = ast2obj_expr(o->v.Slice.lower); |
| 3172 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3173 | if (_PyObject_SetAttrId(result, &PyId_lower, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3174 | goto failed; |
| 3175 | Py_DECREF(value); |
| 3176 | value = ast2obj_expr(o->v.Slice.upper); |
| 3177 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3178 | if (_PyObject_SetAttrId(result, &PyId_upper, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3179 | goto failed; |
| 3180 | Py_DECREF(value); |
| 3181 | value = ast2obj_expr(o->v.Slice.step); |
| 3182 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3183 | if (_PyObject_SetAttrId(result, &PyId_step, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3184 | goto failed; |
| 3185 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3186 | break; |
| 3187 | case ExtSlice_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3188 | result = PyType_GenericNew(ExtSlice_type, NULL, NULL); |
| 3189 | if (!result) goto failed; |
| 3190 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 3191 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3192 | if (_PyObject_SetAttrId(result, &PyId_dims, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3193 | goto failed; |
| 3194 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3195 | break; |
| 3196 | case Index_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3197 | result = PyType_GenericNew(Index_type, NULL, NULL); |
| 3198 | if (!result) goto failed; |
| 3199 | value = ast2obj_expr(o->v.Index.value); |
| 3200 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3201 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3202 | goto failed; |
| 3203 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3204 | break; |
| 3205 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3206 | return result; |
| 3207 | failed: |
| 3208 | Py_XDECREF(value); |
| 3209 | Py_XDECREF(result); |
| 3210 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3211 | } |
| 3212 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3213 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3214 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3215 | switch(o) { |
| 3216 | case And: |
| 3217 | Py_INCREF(And_singleton); |
| 3218 | return And_singleton; |
| 3219 | case Or: |
| 3220 | Py_INCREF(Or_singleton); |
| 3221 | return Or_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3222 | default: |
| 3223 | /* should never happen, but just in case ... */ |
| 3224 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 3225 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3226 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3227 | } |
| 3228 | PyObject* ast2obj_operator(operator_ty o) |
| 3229 | { |
| 3230 | switch(o) { |
| 3231 | case Add: |
| 3232 | Py_INCREF(Add_singleton); |
| 3233 | return Add_singleton; |
| 3234 | case Sub: |
| 3235 | Py_INCREF(Sub_singleton); |
| 3236 | return Sub_singleton; |
| 3237 | case Mult: |
| 3238 | Py_INCREF(Mult_singleton); |
| 3239 | return Mult_singleton; |
| 3240 | case Div: |
| 3241 | Py_INCREF(Div_singleton); |
| 3242 | return Div_singleton; |
| 3243 | case Mod: |
| 3244 | Py_INCREF(Mod_singleton); |
| 3245 | return Mod_singleton; |
| 3246 | case Pow: |
| 3247 | Py_INCREF(Pow_singleton); |
| 3248 | return Pow_singleton; |
| 3249 | case LShift: |
| 3250 | Py_INCREF(LShift_singleton); |
| 3251 | return LShift_singleton; |
| 3252 | case RShift: |
| 3253 | Py_INCREF(RShift_singleton); |
| 3254 | return RShift_singleton; |
| 3255 | case BitOr: |
| 3256 | Py_INCREF(BitOr_singleton); |
| 3257 | return BitOr_singleton; |
| 3258 | case BitXor: |
| 3259 | Py_INCREF(BitXor_singleton); |
| 3260 | return BitXor_singleton; |
| 3261 | case BitAnd: |
| 3262 | Py_INCREF(BitAnd_singleton); |
| 3263 | return BitAnd_singleton; |
| 3264 | case FloorDiv: |
| 3265 | Py_INCREF(FloorDiv_singleton); |
| 3266 | return FloorDiv_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3267 | default: |
| 3268 | /* should never happen, but just in case ... */ |
| 3269 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 3270 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3271 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3272 | } |
| 3273 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 3274 | { |
| 3275 | switch(o) { |
| 3276 | case Invert: |
| 3277 | Py_INCREF(Invert_singleton); |
| 3278 | return Invert_singleton; |
| 3279 | case Not: |
| 3280 | Py_INCREF(Not_singleton); |
| 3281 | return Not_singleton; |
| 3282 | case UAdd: |
| 3283 | Py_INCREF(UAdd_singleton); |
| 3284 | return UAdd_singleton; |
| 3285 | case USub: |
| 3286 | Py_INCREF(USub_singleton); |
| 3287 | return USub_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3288 | default: |
| 3289 | /* should never happen, but just in case ... */ |
| 3290 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 3291 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3292 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3293 | } |
| 3294 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 3295 | { |
| 3296 | switch(o) { |
| 3297 | case Eq: |
| 3298 | Py_INCREF(Eq_singleton); |
| 3299 | return Eq_singleton; |
| 3300 | case NotEq: |
| 3301 | Py_INCREF(NotEq_singleton); |
| 3302 | return NotEq_singleton; |
| 3303 | case Lt: |
| 3304 | Py_INCREF(Lt_singleton); |
| 3305 | return Lt_singleton; |
| 3306 | case LtE: |
| 3307 | Py_INCREF(LtE_singleton); |
| 3308 | return LtE_singleton; |
| 3309 | case Gt: |
| 3310 | Py_INCREF(Gt_singleton); |
| 3311 | return Gt_singleton; |
| 3312 | case GtE: |
| 3313 | Py_INCREF(GtE_singleton); |
| 3314 | return GtE_singleton; |
| 3315 | case Is: |
| 3316 | Py_INCREF(Is_singleton); |
| 3317 | return Is_singleton; |
| 3318 | case IsNot: |
| 3319 | Py_INCREF(IsNot_singleton); |
| 3320 | return IsNot_singleton; |
| 3321 | case In: |
| 3322 | Py_INCREF(In_singleton); |
| 3323 | return In_singleton; |
| 3324 | case NotIn: |
| 3325 | Py_INCREF(NotIn_singleton); |
| 3326 | return NotIn_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3327 | default: |
| 3328 | /* should never happen, but just in case ... */ |
| 3329 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 3330 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3331 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3332 | } |
| 3333 | PyObject* |
| 3334 | ast2obj_comprehension(void* _o) |
| 3335 | { |
| 3336 | comprehension_ty o = (comprehension_ty)_o; |
| 3337 | PyObject *result = NULL, *value = NULL; |
| 3338 | if (!o) { |
| 3339 | Py_INCREF(Py_None); |
| 3340 | return Py_None; |
| 3341 | } |
| 3342 | |
| 3343 | result = PyType_GenericNew(comprehension_type, NULL, NULL); |
| 3344 | if (!result) return NULL; |
| 3345 | value = ast2obj_expr(o->target); |
| 3346 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3347 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3348 | goto failed; |
| 3349 | Py_DECREF(value); |
| 3350 | value = ast2obj_expr(o->iter); |
| 3351 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3352 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3353 | goto failed; |
| 3354 | Py_DECREF(value); |
| 3355 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 3356 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3357 | if (_PyObject_SetAttrId(result, &PyId_ifs, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3358 | goto failed; |
| 3359 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3360 | return result; |
| 3361 | failed: |
| 3362 | Py_XDECREF(value); |
| 3363 | Py_XDECREF(result); |
| 3364 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3365 | } |
| 3366 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3367 | PyObject* |
| 3368 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3369 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3370 | excepthandler_ty o = (excepthandler_ty)_o; |
| 3371 | PyObject *result = NULL, *value = NULL; |
| 3372 | if (!o) { |
| 3373 | Py_INCREF(Py_None); |
| 3374 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3375 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3376 | |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3377 | switch (o->kind) { |
| 3378 | case ExceptHandler_kind: |
| 3379 | result = PyType_GenericNew(ExceptHandler_type, NULL, NULL); |
| 3380 | if (!result) goto failed; |
| 3381 | value = ast2obj_expr(o->v.ExceptHandler.type); |
| 3382 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3383 | if (_PyObject_SetAttrId(result, &PyId_type, value) == -1) |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3384 | goto failed; |
| 3385 | Py_DECREF(value); |
| 3386 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
| 3387 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3388 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3389 | goto failed; |
| 3390 | Py_DECREF(value); |
| 3391 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 3392 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3393 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3394 | goto failed; |
| 3395 | Py_DECREF(value); |
| 3396 | break; |
| 3397 | } |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3398 | value = ast2obj_int(o->lineno); |
| 3399 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3400 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3401 | goto failed; |
| 3402 | Py_DECREF(value); |
| 3403 | value = ast2obj_int(o->col_offset); |
| 3404 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3405 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3406 | goto failed; |
| 3407 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3408 | return result; |
| 3409 | failed: |
| 3410 | Py_XDECREF(value); |
| 3411 | Py_XDECREF(result); |
| 3412 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3413 | } |
| 3414 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3415 | PyObject* |
| 3416 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3417 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3418 | arguments_ty o = (arguments_ty)_o; |
| 3419 | PyObject *result = NULL, *value = NULL; |
| 3420 | if (!o) { |
| 3421 | Py_INCREF(Py_None); |
| 3422 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3423 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3424 | |
| 3425 | result = PyType_GenericNew(arguments_type, NULL, NULL); |
| 3426 | if (!result) return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3427 | value = ast2obj_list(o->args, ast2obj_arg); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +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_args, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3430 | goto failed; |
| 3431 | Py_DECREF(value); |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 3432 | value = ast2obj_arg(o->vararg); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 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_vararg, 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_list(o->kwonlyargs, ast2obj_arg); |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 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_kwonlyargs, value) == -1) |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 3440 | goto failed; |
| 3441 | Py_DECREF(value); |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 3442 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3443 | if (!value) goto failed; |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 3444 | if (_PyObject_SetAttrId(result, &PyId_kw_defaults, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3445 | goto failed; |
| 3446 | Py_DECREF(value); |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 3447 | value = ast2obj_arg(o->kwarg); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3448 | if (!value) goto failed; |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 3449 | if (_PyObject_SetAttrId(result, &PyId_kwarg, value) == -1) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +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 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 3453 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3454 | if (_PyObject_SetAttrId(result, &PyId_defaults, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3455 | goto failed; |
| 3456 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3457 | return result; |
| 3458 | failed: |
| 3459 | Py_XDECREF(value); |
| 3460 | Py_XDECREF(result); |
| 3461 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3462 | } |
| 3463 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3464 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3465 | ast2obj_arg(void* _o) |
| 3466 | { |
| 3467 | arg_ty o = (arg_ty)_o; |
| 3468 | PyObject *result = NULL, *value = NULL; |
| 3469 | if (!o) { |
| 3470 | Py_INCREF(Py_None); |
| 3471 | return Py_None; |
| 3472 | } |
| 3473 | |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 3474 | result = PyType_GenericNew(arg_type, NULL, NULL); |
| 3475 | if (!result) return NULL; |
| 3476 | value = ast2obj_identifier(o->arg); |
| 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_arg, value) == -1) |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 3479 | goto failed; |
| 3480 | Py_DECREF(value); |
| 3481 | value = ast2obj_expr(o->annotation); |
| 3482 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3483 | if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 3484 | goto failed; |
| 3485 | Py_DECREF(value); |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 3486 | value = ast2obj_int(o->lineno); |
| 3487 | if (!value) goto failed; |
| 3488 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3489 | goto failed; |
| 3490 | Py_DECREF(value); |
| 3491 | value = ast2obj_int(o->col_offset); |
| 3492 | if (!value) goto failed; |
| 3493 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3494 | goto failed; |
| 3495 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3496 | return result; |
| 3497 | failed: |
| 3498 | Py_XDECREF(value); |
| 3499 | Py_XDECREF(result); |
| 3500 | return NULL; |
| 3501 | } |
| 3502 | |
| 3503 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3504 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3505 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3506 | keyword_ty o = (keyword_ty)_o; |
| 3507 | PyObject *result = NULL, *value = NULL; |
| 3508 | if (!o) { |
| 3509 | Py_INCREF(Py_None); |
| 3510 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3511 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3512 | |
| 3513 | result = PyType_GenericNew(keyword_type, NULL, NULL); |
| 3514 | if (!result) return NULL; |
| 3515 | value = ast2obj_identifier(o->arg); |
| 3516 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3517 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3518 | goto failed; |
| 3519 | Py_DECREF(value); |
| 3520 | value = ast2obj_expr(o->value); |
| 3521 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3522 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3523 | goto failed; |
| 3524 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3525 | return result; |
| 3526 | failed: |
| 3527 | Py_XDECREF(value); |
| 3528 | Py_XDECREF(result); |
| 3529 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3530 | } |
| 3531 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3532 | PyObject* |
| 3533 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3534 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3535 | alias_ty o = (alias_ty)_o; |
| 3536 | PyObject *result = NULL, *value = NULL; |
| 3537 | if (!o) { |
| 3538 | Py_INCREF(Py_None); |
| 3539 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3540 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3541 | |
| 3542 | result = PyType_GenericNew(alias_type, NULL, NULL); |
| 3543 | if (!result) return NULL; |
| 3544 | value = ast2obj_identifier(o->name); |
| 3545 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3546 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3547 | goto failed; |
| 3548 | Py_DECREF(value); |
| 3549 | value = ast2obj_identifier(o->asname); |
| 3550 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3551 | if (_PyObject_SetAttrId(result, &PyId_asname, value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3552 | goto failed; |
| 3553 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3554 | return result; |
| 3555 | failed: |
| 3556 | Py_XDECREF(value); |
| 3557 | Py_XDECREF(result); |
| 3558 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3559 | } |
| 3560 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3561 | PyObject* |
| 3562 | ast2obj_withitem(void* _o) |
| 3563 | { |
| 3564 | withitem_ty o = (withitem_ty)_o; |
| 3565 | PyObject *result = NULL, *value = NULL; |
| 3566 | if (!o) { |
| 3567 | Py_INCREF(Py_None); |
| 3568 | return Py_None; |
| 3569 | } |
| 3570 | |
| 3571 | result = PyType_GenericNew(withitem_type, NULL, NULL); |
| 3572 | if (!result) return NULL; |
| 3573 | value = ast2obj_expr(o->context_expr); |
| 3574 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3575 | if (_PyObject_SetAttrId(result, &PyId_context_expr, value) == -1) |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3576 | goto failed; |
| 3577 | Py_DECREF(value); |
| 3578 | value = ast2obj_expr(o->optional_vars); |
| 3579 | if (!value) goto failed; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 3580 | if (_PyObject_SetAttrId(result, &PyId_optional_vars, value) == -1) |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3581 | goto failed; |
| 3582 | Py_DECREF(value); |
| 3583 | return result; |
| 3584 | failed: |
| 3585 | Py_XDECREF(value); |
| 3586 | Py_XDECREF(result); |
| 3587 | return NULL; |
| 3588 | } |
| 3589 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3590 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3591 | int |
| 3592 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 3593 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3594 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3595 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 3596 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3597 | |
| 3598 | if (obj == Py_None) { |
| 3599 | *out = NULL; |
| 3600 | return 0; |
| 3601 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3602 | isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type); |
| 3603 | if (isinstance == -1) { |
| 3604 | return 1; |
| 3605 | } |
| 3606 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3607 | asdl_seq* body; |
| 3608 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3609 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3610 | int res; |
| 3611 | Py_ssize_t len; |
| 3612 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3613 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3614 | if (tmp == NULL) goto failed; |
| 3615 | if (!PyList_Check(tmp)) { |
| 3616 | PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3617 | goto failed; |
| 3618 | } |
| 3619 | len = PyList_GET_SIZE(tmp); |
| 3620 | body = asdl_seq_new(len, arena); |
| 3621 | if (body == NULL) goto failed; |
| 3622 | for (i = 0; i < len; i++) { |
| 3623 | stmt_ty value; |
| 3624 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3625 | if (res != 0) goto failed; |
| 3626 | asdl_seq_SET(body, i, value); |
| 3627 | } |
| 3628 | Py_XDECREF(tmp); |
| 3629 | tmp = NULL; |
| 3630 | } else { |
| 3631 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 3632 | return 1; |
| 3633 | } |
| 3634 | *out = Module(body, arena); |
| 3635 | if (*out == NULL) goto failed; |
| 3636 | return 0; |
| 3637 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3638 | isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type); |
| 3639 | if (isinstance == -1) { |
| 3640 | return 1; |
| 3641 | } |
| 3642 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3643 | asdl_seq* body; |
| 3644 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3645 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3646 | int res; |
| 3647 | Py_ssize_t len; |
| 3648 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3649 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3650 | if (tmp == NULL) goto failed; |
| 3651 | if (!PyList_Check(tmp)) { |
| 3652 | PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3653 | goto failed; |
| 3654 | } |
| 3655 | len = PyList_GET_SIZE(tmp); |
| 3656 | body = asdl_seq_new(len, arena); |
| 3657 | if (body == NULL) goto failed; |
| 3658 | for (i = 0; i < len; i++) { |
| 3659 | stmt_ty value; |
| 3660 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3661 | if (res != 0) goto failed; |
| 3662 | asdl_seq_SET(body, i, value); |
| 3663 | } |
| 3664 | Py_XDECREF(tmp); |
| 3665 | tmp = NULL; |
| 3666 | } else { |
| 3667 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 3668 | return 1; |
| 3669 | } |
| 3670 | *out = Interactive(body, arena); |
| 3671 | if (*out == NULL) goto failed; |
| 3672 | return 0; |
| 3673 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3674 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type); |
| 3675 | if (isinstance == -1) { |
| 3676 | return 1; |
| 3677 | } |
| 3678 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3679 | expr_ty body; |
| 3680 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3681 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3682 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3683 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3684 | if (tmp == NULL) goto failed; |
| 3685 | res = obj2ast_expr(tmp, &body, arena); |
| 3686 | if (res != 0) goto failed; |
| 3687 | Py_XDECREF(tmp); |
| 3688 | tmp = NULL; |
| 3689 | } else { |
| 3690 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 3691 | return 1; |
| 3692 | } |
| 3693 | *out = Expression(body, arena); |
| 3694 | if (*out == NULL) goto failed; |
| 3695 | return 0; |
| 3696 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3697 | isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type); |
| 3698 | if (isinstance == -1) { |
| 3699 | return 1; |
| 3700 | } |
| 3701 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3702 | asdl_seq* body; |
| 3703 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3704 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3705 | int res; |
| 3706 | Py_ssize_t len; |
| 3707 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3708 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3709 | if (tmp == NULL) goto failed; |
| 3710 | if (!PyList_Check(tmp)) { |
| 3711 | PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3712 | goto failed; |
| 3713 | } |
| 3714 | len = PyList_GET_SIZE(tmp); |
| 3715 | body = asdl_seq_new(len, arena); |
| 3716 | if (body == NULL) goto failed; |
| 3717 | for (i = 0; i < len; i++) { |
| 3718 | stmt_ty value; |
| 3719 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3720 | if (res != 0) goto failed; |
| 3721 | asdl_seq_SET(body, i, value); |
| 3722 | } |
| 3723 | Py_XDECREF(tmp); |
| 3724 | tmp = NULL; |
| 3725 | } else { |
| 3726 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite"); |
| 3727 | return 1; |
| 3728 | } |
| 3729 | *out = Suite(body, arena); |
| 3730 | if (*out == NULL) goto failed; |
| 3731 | return 0; |
| 3732 | } |
| 3733 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 3734 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
| 3735 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 3736 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3737 | return 1; |
| 3738 | } |
| 3739 | |
| 3740 | int |
| 3741 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 3742 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3743 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3744 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 3745 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3746 | int lineno; |
| 3747 | int col_offset; |
| 3748 | |
| 3749 | if (obj == Py_None) { |
| 3750 | *out = NULL; |
| 3751 | return 0; |
| 3752 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3753 | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3754 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3755 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3756 | if (tmp == NULL) goto failed; |
| 3757 | res = obj2ast_int(tmp, &lineno, arena); |
| 3758 | if (res != 0) goto failed; |
| 3759 | Py_XDECREF(tmp); |
| 3760 | tmp = NULL; |
| 3761 | } else { |
| 3762 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 3763 | return 1; |
| 3764 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3765 | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3766 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3767 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3768 | if (tmp == NULL) goto failed; |
| 3769 | res = obj2ast_int(tmp, &col_offset, arena); |
| 3770 | if (res != 0) goto failed; |
| 3771 | Py_XDECREF(tmp); |
| 3772 | tmp = NULL; |
| 3773 | } else { |
| 3774 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 3775 | return 1; |
| 3776 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3777 | isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type); |
| 3778 | if (isinstance == -1) { |
| 3779 | return 1; |
| 3780 | } |
| 3781 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3782 | identifier name; |
| 3783 | arguments_ty args; |
| 3784 | asdl_seq* body; |
| 3785 | asdl_seq* decorator_list; |
| 3786 | expr_ty returns; |
| 3787 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3788 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3789 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3790 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3791 | if (tmp == NULL) goto failed; |
| 3792 | res = obj2ast_identifier(tmp, &name, arena); |
| 3793 | if (res != 0) goto failed; |
| 3794 | Py_XDECREF(tmp); |
| 3795 | tmp = NULL; |
| 3796 | } else { |
| 3797 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 3798 | return 1; |
| 3799 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3800 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3801 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3802 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3803 | if (tmp == NULL) goto failed; |
| 3804 | res = obj2ast_arguments(tmp, &args, arena); |
| 3805 | if (res != 0) goto failed; |
| 3806 | Py_XDECREF(tmp); |
| 3807 | tmp = NULL; |
| 3808 | } else { |
| 3809 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 3810 | return 1; |
| 3811 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3812 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3813 | int res; |
| 3814 | Py_ssize_t len; |
| 3815 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3816 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3817 | if (tmp == NULL) goto failed; |
| 3818 | if (!PyList_Check(tmp)) { |
| 3819 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3820 | goto failed; |
| 3821 | } |
| 3822 | len = PyList_GET_SIZE(tmp); |
| 3823 | body = asdl_seq_new(len, arena); |
| 3824 | if (body == NULL) goto failed; |
| 3825 | for (i = 0; i < len; i++) { |
| 3826 | stmt_ty value; |
| 3827 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3828 | if (res != 0) goto failed; |
| 3829 | asdl_seq_SET(body, i, value); |
| 3830 | } |
| 3831 | Py_XDECREF(tmp); |
| 3832 | tmp = NULL; |
| 3833 | } else { |
| 3834 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 3835 | return 1; |
| 3836 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3837 | if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3838 | int res; |
| 3839 | Py_ssize_t len; |
| 3840 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3841 | tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3842 | if (tmp == NULL) goto failed; |
| 3843 | if (!PyList_Check(tmp)) { |
| 3844 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3845 | goto failed; |
| 3846 | } |
| 3847 | len = PyList_GET_SIZE(tmp); |
| 3848 | decorator_list = asdl_seq_new(len, arena); |
| 3849 | if (decorator_list == NULL) goto failed; |
| 3850 | for (i = 0; i < len; i++) { |
| 3851 | expr_ty value; |
| 3852 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3853 | if (res != 0) goto failed; |
| 3854 | asdl_seq_SET(decorator_list, i, value); |
| 3855 | } |
| 3856 | Py_XDECREF(tmp); |
| 3857 | tmp = NULL; |
| 3858 | } else { |
| 3859 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 3860 | return 1; |
| 3861 | } |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 3862 | if (exists_not_none(obj, &PyId_returns)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3863 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3864 | tmp = _PyObject_GetAttrId(obj, &PyId_returns); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3865 | if (tmp == NULL) goto failed; |
| 3866 | res = obj2ast_expr(tmp, &returns, arena); |
| 3867 | if (res != 0) goto failed; |
| 3868 | Py_XDECREF(tmp); |
| 3869 | tmp = NULL; |
| 3870 | } else { |
| 3871 | returns = NULL; |
| 3872 | } |
| 3873 | *out = FunctionDef(name, args, body, decorator_list, returns, |
| 3874 | lineno, col_offset, arena); |
| 3875 | if (*out == NULL) goto failed; |
| 3876 | return 0; |
| 3877 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3878 | isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type); |
| 3879 | if (isinstance == -1) { |
| 3880 | return 1; |
| 3881 | } |
| 3882 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3883 | identifier name; |
| 3884 | asdl_seq* bases; |
| 3885 | asdl_seq* keywords; |
| 3886 | expr_ty starargs; |
| 3887 | expr_ty kwargs; |
| 3888 | asdl_seq* body; |
| 3889 | asdl_seq* decorator_list; |
| 3890 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3891 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3892 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3893 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3894 | if (tmp == NULL) goto failed; |
| 3895 | res = obj2ast_identifier(tmp, &name, arena); |
| 3896 | if (res != 0) goto failed; |
| 3897 | Py_XDECREF(tmp); |
| 3898 | tmp = NULL; |
| 3899 | } else { |
| 3900 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 3901 | return 1; |
| 3902 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3903 | if (_PyObject_HasAttrId(obj, &PyId_bases)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3904 | int res; |
| 3905 | Py_ssize_t len; |
| 3906 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3907 | tmp = _PyObject_GetAttrId(obj, &PyId_bases); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3908 | if (tmp == NULL) goto failed; |
| 3909 | if (!PyList_Check(tmp)) { |
| 3910 | PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3911 | goto failed; |
| 3912 | } |
| 3913 | len = PyList_GET_SIZE(tmp); |
| 3914 | bases = asdl_seq_new(len, arena); |
| 3915 | if (bases == NULL) goto failed; |
| 3916 | for (i = 0; i < len; i++) { |
| 3917 | expr_ty value; |
| 3918 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3919 | if (res != 0) goto failed; |
| 3920 | asdl_seq_SET(bases, i, value); |
| 3921 | } |
| 3922 | Py_XDECREF(tmp); |
| 3923 | tmp = NULL; |
| 3924 | } else { |
| 3925 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 3926 | return 1; |
| 3927 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3928 | if (_PyObject_HasAttrId(obj, &PyId_keywords)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3929 | int res; |
| 3930 | Py_ssize_t len; |
| 3931 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3932 | tmp = _PyObject_GetAttrId(obj, &PyId_keywords); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3933 | if (tmp == NULL) goto failed; |
| 3934 | if (!PyList_Check(tmp)) { |
| 3935 | PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3936 | goto failed; |
| 3937 | } |
| 3938 | len = PyList_GET_SIZE(tmp); |
| 3939 | keywords = asdl_seq_new(len, arena); |
| 3940 | if (keywords == NULL) goto failed; |
| 3941 | for (i = 0; i < len; i++) { |
| 3942 | keyword_ty value; |
| 3943 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3944 | if (res != 0) goto failed; |
| 3945 | asdl_seq_SET(keywords, i, value); |
| 3946 | } |
| 3947 | Py_XDECREF(tmp); |
| 3948 | tmp = NULL; |
| 3949 | } else { |
| 3950 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 3951 | return 1; |
| 3952 | } |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 3953 | if (exists_not_none(obj, &PyId_starargs)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3954 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3955 | tmp = _PyObject_GetAttrId(obj, &PyId_starargs); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3956 | if (tmp == NULL) goto failed; |
| 3957 | res = obj2ast_expr(tmp, &starargs, arena); |
| 3958 | if (res != 0) goto failed; |
| 3959 | Py_XDECREF(tmp); |
| 3960 | tmp = NULL; |
| 3961 | } else { |
| 3962 | starargs = NULL; |
| 3963 | } |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 3964 | if (exists_not_none(obj, &PyId_kwargs)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3965 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3966 | tmp = _PyObject_GetAttrId(obj, &PyId_kwargs); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3967 | if (tmp == NULL) goto failed; |
| 3968 | res = obj2ast_expr(tmp, &kwargs, arena); |
| 3969 | if (res != 0) goto failed; |
| 3970 | Py_XDECREF(tmp); |
| 3971 | tmp = NULL; |
| 3972 | } else { |
| 3973 | kwargs = NULL; |
| 3974 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3975 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3976 | int res; |
| 3977 | Py_ssize_t len; |
| 3978 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 3979 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3980 | if (tmp == NULL) goto failed; |
| 3981 | if (!PyList_Check(tmp)) { |
| 3982 | PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3983 | goto failed; |
| 3984 | } |
| 3985 | len = PyList_GET_SIZE(tmp); |
| 3986 | body = asdl_seq_new(len, arena); |
| 3987 | if (body == NULL) goto failed; |
| 3988 | for (i = 0; i < len; i++) { |
| 3989 | stmt_ty value; |
| 3990 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3991 | if (res != 0) goto failed; |
| 3992 | asdl_seq_SET(body, i, value); |
| 3993 | } |
| 3994 | Py_XDECREF(tmp); |
| 3995 | tmp = NULL; |
| 3996 | } else { |
| 3997 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 3998 | return 1; |
| 3999 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4000 | if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4001 | int res; |
| 4002 | Py_ssize_t len; |
| 4003 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4004 | tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4005 | if (tmp == NULL) goto failed; |
| 4006 | if (!PyList_Check(tmp)) { |
| 4007 | PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4008 | goto failed; |
| 4009 | } |
| 4010 | len = PyList_GET_SIZE(tmp); |
| 4011 | decorator_list = asdl_seq_new(len, arena); |
| 4012 | if (decorator_list == NULL) goto failed; |
| 4013 | for (i = 0; i < len; i++) { |
| 4014 | expr_ty value; |
| 4015 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4016 | if (res != 0) goto failed; |
| 4017 | asdl_seq_SET(decorator_list, i, value); |
| 4018 | } |
| 4019 | Py_XDECREF(tmp); |
| 4020 | tmp = NULL; |
| 4021 | } else { |
| 4022 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 4023 | return 1; |
| 4024 | } |
| 4025 | *out = ClassDef(name, bases, keywords, starargs, kwargs, body, |
| 4026 | decorator_list, lineno, col_offset, arena); |
| 4027 | if (*out == NULL) goto failed; |
| 4028 | return 0; |
| 4029 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4030 | isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type); |
| 4031 | if (isinstance == -1) { |
| 4032 | return 1; |
| 4033 | } |
| 4034 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4035 | expr_ty value; |
| 4036 | |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 4037 | if (exists_not_none(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4038 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4039 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4040 | if (tmp == NULL) goto failed; |
| 4041 | res = obj2ast_expr(tmp, &value, arena); |
| 4042 | if (res != 0) goto failed; |
| 4043 | Py_XDECREF(tmp); |
| 4044 | tmp = NULL; |
| 4045 | } else { |
| 4046 | value = NULL; |
| 4047 | } |
| 4048 | *out = Return(value, lineno, col_offset, arena); |
| 4049 | if (*out == NULL) goto failed; |
| 4050 | return 0; |
| 4051 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4052 | isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type); |
| 4053 | if (isinstance == -1) { |
| 4054 | return 1; |
| 4055 | } |
| 4056 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4057 | asdl_seq* targets; |
| 4058 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4059 | if (_PyObject_HasAttrId(obj, &PyId_targets)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4060 | int res; |
| 4061 | Py_ssize_t len; |
| 4062 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4063 | tmp = _PyObject_GetAttrId(obj, &PyId_targets); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4064 | if (tmp == NULL) goto failed; |
| 4065 | if (!PyList_Check(tmp)) { |
| 4066 | PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4067 | goto failed; |
| 4068 | } |
| 4069 | len = PyList_GET_SIZE(tmp); |
| 4070 | targets = asdl_seq_new(len, arena); |
| 4071 | if (targets == NULL) goto failed; |
| 4072 | for (i = 0; i < len; i++) { |
| 4073 | expr_ty value; |
| 4074 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4075 | if (res != 0) goto failed; |
| 4076 | asdl_seq_SET(targets, i, value); |
| 4077 | } |
| 4078 | Py_XDECREF(tmp); |
| 4079 | tmp = NULL; |
| 4080 | } else { |
| 4081 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 4082 | return 1; |
| 4083 | } |
| 4084 | *out = Delete(targets, lineno, col_offset, arena); |
| 4085 | if (*out == NULL) goto failed; |
| 4086 | return 0; |
| 4087 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4088 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type); |
| 4089 | if (isinstance == -1) { |
| 4090 | return 1; |
| 4091 | } |
| 4092 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4093 | asdl_seq* targets; |
| 4094 | expr_ty value; |
| 4095 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4096 | if (_PyObject_HasAttrId(obj, &PyId_targets)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4097 | int res; |
| 4098 | Py_ssize_t len; |
| 4099 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4100 | tmp = _PyObject_GetAttrId(obj, &PyId_targets); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4101 | if (tmp == NULL) goto failed; |
| 4102 | if (!PyList_Check(tmp)) { |
| 4103 | PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4104 | goto failed; |
| 4105 | } |
| 4106 | len = PyList_GET_SIZE(tmp); |
| 4107 | targets = asdl_seq_new(len, arena); |
| 4108 | if (targets == NULL) goto failed; |
| 4109 | for (i = 0; i < len; i++) { |
| 4110 | expr_ty value; |
| 4111 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4112 | if (res != 0) goto failed; |
| 4113 | asdl_seq_SET(targets, i, value); |
| 4114 | } |
| 4115 | Py_XDECREF(tmp); |
| 4116 | tmp = NULL; |
| 4117 | } else { |
| 4118 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 4119 | return 1; |
| 4120 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4121 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4122 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4123 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4124 | if (tmp == NULL) goto failed; |
| 4125 | res = obj2ast_expr(tmp, &value, arena); |
| 4126 | if (res != 0) goto failed; |
| 4127 | Py_XDECREF(tmp); |
| 4128 | tmp = NULL; |
| 4129 | } else { |
| 4130 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 4131 | return 1; |
| 4132 | } |
| 4133 | *out = Assign(targets, value, lineno, col_offset, arena); |
| 4134 | if (*out == NULL) goto failed; |
| 4135 | return 0; |
| 4136 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4137 | isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type); |
| 4138 | if (isinstance == -1) { |
| 4139 | return 1; |
| 4140 | } |
| 4141 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4142 | expr_ty target; |
| 4143 | operator_ty op; |
| 4144 | expr_ty value; |
| 4145 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4146 | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4147 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4148 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4149 | if (tmp == NULL) goto failed; |
| 4150 | res = obj2ast_expr(tmp, &target, arena); |
| 4151 | if (res != 0) goto failed; |
| 4152 | Py_XDECREF(tmp); |
| 4153 | tmp = NULL; |
| 4154 | } else { |
| 4155 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 4156 | return 1; |
| 4157 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4158 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4159 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4160 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4161 | if (tmp == NULL) goto failed; |
| 4162 | res = obj2ast_operator(tmp, &op, arena); |
| 4163 | if (res != 0) goto failed; |
| 4164 | Py_XDECREF(tmp); |
| 4165 | tmp = NULL; |
| 4166 | } else { |
| 4167 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 4168 | return 1; |
| 4169 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4170 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4171 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4172 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4173 | if (tmp == NULL) goto failed; |
| 4174 | res = obj2ast_expr(tmp, &value, arena); |
| 4175 | if (res != 0) goto failed; |
| 4176 | Py_XDECREF(tmp); |
| 4177 | tmp = NULL; |
| 4178 | } else { |
| 4179 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 4180 | return 1; |
| 4181 | } |
| 4182 | *out = AugAssign(target, op, value, lineno, col_offset, arena); |
| 4183 | if (*out == NULL) goto failed; |
| 4184 | return 0; |
| 4185 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4186 | isinstance = PyObject_IsInstance(obj, (PyObject*)For_type); |
| 4187 | if (isinstance == -1) { |
| 4188 | return 1; |
| 4189 | } |
| 4190 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4191 | expr_ty target; |
| 4192 | expr_ty iter; |
| 4193 | asdl_seq* body; |
| 4194 | asdl_seq* orelse; |
| 4195 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4196 | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4197 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4198 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4199 | if (tmp == NULL) goto failed; |
| 4200 | res = obj2ast_expr(tmp, &target, arena); |
| 4201 | if (res != 0) goto failed; |
| 4202 | Py_XDECREF(tmp); |
| 4203 | tmp = NULL; |
| 4204 | } else { |
| 4205 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 4206 | return 1; |
| 4207 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4208 | if (_PyObject_HasAttrId(obj, &PyId_iter)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4209 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4210 | tmp = _PyObject_GetAttrId(obj, &PyId_iter); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4211 | if (tmp == NULL) goto failed; |
| 4212 | res = obj2ast_expr(tmp, &iter, arena); |
| 4213 | if (res != 0) goto failed; |
| 4214 | Py_XDECREF(tmp); |
| 4215 | tmp = NULL; |
| 4216 | } else { |
| 4217 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 4218 | return 1; |
| 4219 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4220 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4221 | int res; |
| 4222 | Py_ssize_t len; |
| 4223 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4224 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4225 | if (tmp == NULL) goto failed; |
| 4226 | if (!PyList_Check(tmp)) { |
| 4227 | PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4228 | goto failed; |
| 4229 | } |
| 4230 | len = PyList_GET_SIZE(tmp); |
| 4231 | body = asdl_seq_new(len, arena); |
| 4232 | if (body == NULL) goto failed; |
| 4233 | for (i = 0; i < len; i++) { |
| 4234 | stmt_ty value; |
| 4235 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4236 | if (res != 0) goto failed; |
| 4237 | asdl_seq_SET(body, i, value); |
| 4238 | } |
| 4239 | Py_XDECREF(tmp); |
| 4240 | tmp = NULL; |
| 4241 | } else { |
| 4242 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 4243 | return 1; |
| 4244 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4245 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4246 | int res; |
| 4247 | Py_ssize_t len; |
| 4248 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4249 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4250 | if (tmp == NULL) goto failed; |
| 4251 | if (!PyList_Check(tmp)) { |
| 4252 | PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4253 | goto failed; |
| 4254 | } |
| 4255 | len = PyList_GET_SIZE(tmp); |
| 4256 | orelse = asdl_seq_new(len, arena); |
| 4257 | if (orelse == NULL) goto failed; |
| 4258 | for (i = 0; i < len; i++) { |
| 4259 | stmt_ty value; |
| 4260 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4261 | if (res != 0) goto failed; |
| 4262 | asdl_seq_SET(orelse, i, value); |
| 4263 | } |
| 4264 | Py_XDECREF(tmp); |
| 4265 | tmp = NULL; |
| 4266 | } else { |
| 4267 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 4268 | return 1; |
| 4269 | } |
| 4270 | *out = For(target, iter, body, orelse, lineno, col_offset, |
| 4271 | arena); |
| 4272 | if (*out == NULL) goto failed; |
| 4273 | return 0; |
| 4274 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4275 | isinstance = PyObject_IsInstance(obj, (PyObject*)While_type); |
| 4276 | if (isinstance == -1) { |
| 4277 | return 1; |
| 4278 | } |
| 4279 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4280 | expr_ty test; |
| 4281 | asdl_seq* body; |
| 4282 | asdl_seq* orelse; |
| 4283 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4284 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4285 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4286 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4287 | if (tmp == NULL) goto failed; |
| 4288 | res = obj2ast_expr(tmp, &test, arena); |
| 4289 | if (res != 0) goto failed; |
| 4290 | Py_XDECREF(tmp); |
| 4291 | tmp = NULL; |
| 4292 | } else { |
| 4293 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 4294 | return 1; |
| 4295 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4296 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4297 | int res; |
| 4298 | Py_ssize_t len; |
| 4299 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4300 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4301 | if (tmp == NULL) goto failed; |
| 4302 | if (!PyList_Check(tmp)) { |
| 4303 | PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4304 | goto failed; |
| 4305 | } |
| 4306 | len = PyList_GET_SIZE(tmp); |
| 4307 | body = asdl_seq_new(len, arena); |
| 4308 | if (body == NULL) goto failed; |
| 4309 | for (i = 0; i < len; i++) { |
| 4310 | stmt_ty value; |
| 4311 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4312 | if (res != 0) goto failed; |
| 4313 | asdl_seq_SET(body, i, value); |
| 4314 | } |
| 4315 | Py_XDECREF(tmp); |
| 4316 | tmp = NULL; |
| 4317 | } else { |
| 4318 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 4319 | return 1; |
| 4320 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4321 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4322 | int res; |
| 4323 | Py_ssize_t len; |
| 4324 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4325 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4326 | if (tmp == NULL) goto failed; |
| 4327 | if (!PyList_Check(tmp)) { |
| 4328 | PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4329 | goto failed; |
| 4330 | } |
| 4331 | len = PyList_GET_SIZE(tmp); |
| 4332 | orelse = asdl_seq_new(len, arena); |
| 4333 | if (orelse == NULL) goto failed; |
| 4334 | for (i = 0; i < len; i++) { |
| 4335 | stmt_ty value; |
| 4336 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4337 | if (res != 0) goto failed; |
| 4338 | asdl_seq_SET(orelse, i, value); |
| 4339 | } |
| 4340 | Py_XDECREF(tmp); |
| 4341 | tmp = NULL; |
| 4342 | } else { |
| 4343 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 4344 | return 1; |
| 4345 | } |
| 4346 | *out = While(test, body, orelse, lineno, col_offset, arena); |
| 4347 | if (*out == NULL) goto failed; |
| 4348 | return 0; |
| 4349 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4350 | isinstance = PyObject_IsInstance(obj, (PyObject*)If_type); |
| 4351 | if (isinstance == -1) { |
| 4352 | return 1; |
| 4353 | } |
| 4354 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4355 | expr_ty test; |
| 4356 | asdl_seq* body; |
| 4357 | asdl_seq* orelse; |
| 4358 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4359 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4360 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4361 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4362 | if (tmp == NULL) goto failed; |
| 4363 | res = obj2ast_expr(tmp, &test, arena); |
| 4364 | if (res != 0) goto failed; |
| 4365 | Py_XDECREF(tmp); |
| 4366 | tmp = NULL; |
| 4367 | } else { |
| 4368 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 4369 | return 1; |
| 4370 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4371 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4372 | int res; |
| 4373 | Py_ssize_t len; |
| 4374 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4375 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4376 | if (tmp == NULL) goto failed; |
| 4377 | if (!PyList_Check(tmp)) { |
| 4378 | PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4379 | goto failed; |
| 4380 | } |
| 4381 | len = PyList_GET_SIZE(tmp); |
| 4382 | body = asdl_seq_new(len, arena); |
| 4383 | if (body == NULL) goto failed; |
| 4384 | for (i = 0; i < len; i++) { |
| 4385 | stmt_ty value; |
| 4386 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4387 | if (res != 0) goto failed; |
| 4388 | asdl_seq_SET(body, i, value); |
| 4389 | } |
| 4390 | Py_XDECREF(tmp); |
| 4391 | tmp = NULL; |
| 4392 | } else { |
| 4393 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 4394 | return 1; |
| 4395 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4396 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4397 | int res; |
| 4398 | Py_ssize_t len; |
| 4399 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4400 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4401 | if (tmp == NULL) goto failed; |
| 4402 | if (!PyList_Check(tmp)) { |
| 4403 | PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4404 | goto failed; |
| 4405 | } |
| 4406 | len = PyList_GET_SIZE(tmp); |
| 4407 | orelse = asdl_seq_new(len, arena); |
| 4408 | if (orelse == NULL) goto failed; |
| 4409 | for (i = 0; i < len; i++) { |
| 4410 | stmt_ty value; |
| 4411 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4412 | if (res != 0) goto failed; |
| 4413 | asdl_seq_SET(orelse, i, value); |
| 4414 | } |
| 4415 | Py_XDECREF(tmp); |
| 4416 | tmp = NULL; |
| 4417 | } else { |
| 4418 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 4419 | return 1; |
| 4420 | } |
| 4421 | *out = If(test, body, orelse, lineno, col_offset, arena); |
| 4422 | if (*out == NULL) goto failed; |
| 4423 | return 0; |
| 4424 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4425 | isinstance = PyObject_IsInstance(obj, (PyObject*)With_type); |
| 4426 | if (isinstance == -1) { |
| 4427 | return 1; |
| 4428 | } |
| 4429 | if (isinstance) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4430 | asdl_seq* items; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4431 | asdl_seq* body; |
| 4432 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4433 | if (_PyObject_HasAttrId(obj, &PyId_items)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4434 | int res; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4435 | Py_ssize_t len; |
| 4436 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4437 | tmp = _PyObject_GetAttrId(obj, &PyId_items); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4438 | if (tmp == NULL) goto failed; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4439 | if (!PyList_Check(tmp)) { |
| 4440 | PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4441 | goto failed; |
| 4442 | } |
| 4443 | len = PyList_GET_SIZE(tmp); |
| 4444 | items = asdl_seq_new(len, arena); |
| 4445 | if (items == NULL) goto failed; |
| 4446 | for (i = 0; i < len; i++) { |
| 4447 | withitem_ty value; |
| 4448 | res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4449 | if (res != 0) goto failed; |
| 4450 | asdl_seq_SET(items, i, value); |
| 4451 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4452 | Py_XDECREF(tmp); |
| 4453 | tmp = NULL; |
| 4454 | } else { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4455 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4456 | return 1; |
| 4457 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4458 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4459 | int res; |
| 4460 | Py_ssize_t len; |
| 4461 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4462 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4463 | if (tmp == NULL) goto failed; |
| 4464 | if (!PyList_Check(tmp)) { |
| 4465 | PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4466 | goto failed; |
| 4467 | } |
| 4468 | len = PyList_GET_SIZE(tmp); |
| 4469 | body = asdl_seq_new(len, arena); |
| 4470 | if (body == NULL) goto failed; |
| 4471 | for (i = 0; i < len; i++) { |
| 4472 | stmt_ty value; |
| 4473 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4474 | if (res != 0) goto failed; |
| 4475 | asdl_seq_SET(body, i, value); |
| 4476 | } |
| 4477 | Py_XDECREF(tmp); |
| 4478 | tmp = NULL; |
| 4479 | } else { |
| 4480 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 4481 | return 1; |
| 4482 | } |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4483 | *out = With(items, body, lineno, col_offset, arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4484 | if (*out == NULL) goto failed; |
| 4485 | return 0; |
| 4486 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4487 | isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type); |
| 4488 | if (isinstance == -1) { |
| 4489 | return 1; |
| 4490 | } |
| 4491 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4492 | expr_ty exc; |
| 4493 | expr_ty cause; |
| 4494 | |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 4495 | if (exists_not_none(obj, &PyId_exc)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4496 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4497 | tmp = _PyObject_GetAttrId(obj, &PyId_exc); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4498 | if (tmp == NULL) goto failed; |
| 4499 | res = obj2ast_expr(tmp, &exc, arena); |
| 4500 | if (res != 0) goto failed; |
| 4501 | Py_XDECREF(tmp); |
| 4502 | tmp = NULL; |
| 4503 | } else { |
| 4504 | exc = NULL; |
| 4505 | } |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 4506 | if (exists_not_none(obj, &PyId_cause)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4507 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4508 | tmp = _PyObject_GetAttrId(obj, &PyId_cause); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4509 | if (tmp == NULL) goto failed; |
| 4510 | res = obj2ast_expr(tmp, &cause, arena); |
| 4511 | if (res != 0) goto failed; |
| 4512 | Py_XDECREF(tmp); |
| 4513 | tmp = NULL; |
| 4514 | } else { |
| 4515 | cause = NULL; |
| 4516 | } |
| 4517 | *out = Raise(exc, cause, lineno, col_offset, arena); |
| 4518 | if (*out == NULL) goto failed; |
| 4519 | return 0; |
| 4520 | } |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4521 | isinstance = PyObject_IsInstance(obj, (PyObject*)Try_type); |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4522 | if (isinstance == -1) { |
| 4523 | return 1; |
| 4524 | } |
| 4525 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4526 | asdl_seq* body; |
| 4527 | asdl_seq* handlers; |
| 4528 | asdl_seq* orelse; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4529 | asdl_seq* finalbody; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4530 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4531 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4532 | int res; |
| 4533 | Py_ssize_t len; |
| 4534 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4535 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4536 | if (tmp == NULL) goto failed; |
| 4537 | if (!PyList_Check(tmp)) { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4538 | 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] | 4539 | goto failed; |
| 4540 | } |
| 4541 | len = PyList_GET_SIZE(tmp); |
| 4542 | body = asdl_seq_new(len, arena); |
| 4543 | if (body == NULL) goto failed; |
| 4544 | for (i = 0; i < len; i++) { |
| 4545 | stmt_ty value; |
| 4546 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4547 | if (res != 0) goto failed; |
| 4548 | asdl_seq_SET(body, i, value); |
| 4549 | } |
| 4550 | Py_XDECREF(tmp); |
| 4551 | tmp = NULL; |
| 4552 | } else { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4553 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4554 | return 1; |
| 4555 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4556 | if (_PyObject_HasAttrId(obj, &PyId_handlers)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4557 | int res; |
| 4558 | Py_ssize_t len; |
| 4559 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4560 | tmp = _PyObject_GetAttrId(obj, &PyId_handlers); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4561 | if (tmp == NULL) goto failed; |
| 4562 | if (!PyList_Check(tmp)) { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4563 | 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] | 4564 | goto failed; |
| 4565 | } |
| 4566 | len = PyList_GET_SIZE(tmp); |
| 4567 | handlers = asdl_seq_new(len, arena); |
| 4568 | if (handlers == NULL) goto failed; |
| 4569 | for (i = 0; i < len; i++) { |
| 4570 | excepthandler_ty value; |
| 4571 | res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4572 | if (res != 0) goto failed; |
| 4573 | asdl_seq_SET(handlers, i, value); |
| 4574 | } |
| 4575 | Py_XDECREF(tmp); |
| 4576 | tmp = NULL; |
| 4577 | } else { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4578 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4579 | return 1; |
| 4580 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4581 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4582 | int res; |
| 4583 | Py_ssize_t len; |
| 4584 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4585 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4586 | if (tmp == NULL) goto failed; |
| 4587 | if (!PyList_Check(tmp)) { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4588 | 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] | 4589 | goto failed; |
| 4590 | } |
| 4591 | len = PyList_GET_SIZE(tmp); |
| 4592 | orelse = asdl_seq_new(len, arena); |
| 4593 | if (orelse == NULL) goto failed; |
| 4594 | for (i = 0; i < len; i++) { |
| 4595 | stmt_ty value; |
| 4596 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4597 | if (res != 0) goto failed; |
| 4598 | asdl_seq_SET(orelse, i, value); |
| 4599 | } |
| 4600 | Py_XDECREF(tmp); |
| 4601 | tmp = NULL; |
| 4602 | } else { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4603 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4604 | return 1; |
| 4605 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4606 | if (_PyObject_HasAttrId(obj, &PyId_finalbody)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4607 | int res; |
| 4608 | Py_ssize_t len; |
| 4609 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4610 | tmp = _PyObject_GetAttrId(obj, &PyId_finalbody); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4611 | if (tmp == NULL) goto failed; |
| 4612 | if (!PyList_Check(tmp)) { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4613 | 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] | 4614 | goto failed; |
| 4615 | } |
| 4616 | len = PyList_GET_SIZE(tmp); |
| 4617 | finalbody = asdl_seq_new(len, arena); |
| 4618 | if (finalbody == NULL) goto failed; |
| 4619 | for (i = 0; i < len; i++) { |
| 4620 | stmt_ty value; |
| 4621 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4622 | if (res != 0) goto failed; |
| 4623 | asdl_seq_SET(finalbody, i, value); |
| 4624 | } |
| 4625 | Py_XDECREF(tmp); |
| 4626 | tmp = NULL; |
| 4627 | } else { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4628 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4629 | return 1; |
| 4630 | } |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4631 | *out = Try(body, handlers, orelse, finalbody, lineno, |
| 4632 | col_offset, arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4633 | if (*out == NULL) goto failed; |
| 4634 | return 0; |
| 4635 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4636 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type); |
| 4637 | if (isinstance == -1) { |
| 4638 | return 1; |
| 4639 | } |
| 4640 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4641 | expr_ty test; |
| 4642 | expr_ty msg; |
| 4643 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4644 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4645 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4646 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4647 | if (tmp == NULL) goto failed; |
| 4648 | res = obj2ast_expr(tmp, &test, arena); |
| 4649 | if (res != 0) goto failed; |
| 4650 | Py_XDECREF(tmp); |
| 4651 | tmp = NULL; |
| 4652 | } else { |
| 4653 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 4654 | return 1; |
| 4655 | } |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 4656 | if (exists_not_none(obj, &PyId_msg)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4657 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4658 | tmp = _PyObject_GetAttrId(obj, &PyId_msg); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4659 | if (tmp == NULL) goto failed; |
| 4660 | res = obj2ast_expr(tmp, &msg, arena); |
| 4661 | if (res != 0) goto failed; |
| 4662 | Py_XDECREF(tmp); |
| 4663 | tmp = NULL; |
| 4664 | } else { |
| 4665 | msg = NULL; |
| 4666 | } |
| 4667 | *out = Assert(test, msg, lineno, col_offset, arena); |
| 4668 | if (*out == NULL) goto failed; |
| 4669 | return 0; |
| 4670 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4671 | isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type); |
| 4672 | if (isinstance == -1) { |
| 4673 | return 1; |
| 4674 | } |
| 4675 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4676 | asdl_seq* names; |
| 4677 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4678 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4679 | int res; |
| 4680 | Py_ssize_t len; |
| 4681 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4682 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4683 | if (tmp == NULL) goto failed; |
| 4684 | if (!PyList_Check(tmp)) { |
| 4685 | PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4686 | goto failed; |
| 4687 | } |
| 4688 | len = PyList_GET_SIZE(tmp); |
| 4689 | names = asdl_seq_new(len, arena); |
| 4690 | if (names == NULL) goto failed; |
| 4691 | for (i = 0; i < len; i++) { |
| 4692 | alias_ty value; |
| 4693 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4694 | if (res != 0) goto failed; |
| 4695 | asdl_seq_SET(names, i, value); |
| 4696 | } |
| 4697 | Py_XDECREF(tmp); |
| 4698 | tmp = NULL; |
| 4699 | } else { |
| 4700 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 4701 | return 1; |
| 4702 | } |
| 4703 | *out = Import(names, lineno, col_offset, arena); |
| 4704 | if (*out == NULL) goto failed; |
| 4705 | return 0; |
| 4706 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4707 | isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type); |
| 4708 | if (isinstance == -1) { |
| 4709 | return 1; |
| 4710 | } |
| 4711 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4712 | identifier module; |
| 4713 | asdl_seq* names; |
| 4714 | int level; |
| 4715 | |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 4716 | if (exists_not_none(obj, &PyId_module)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4717 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4718 | tmp = _PyObject_GetAttrId(obj, &PyId_module); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4719 | if (tmp == NULL) goto failed; |
| 4720 | res = obj2ast_identifier(tmp, &module, arena); |
| 4721 | if (res != 0) goto failed; |
| 4722 | Py_XDECREF(tmp); |
| 4723 | tmp = NULL; |
| 4724 | } else { |
Benjamin Peterson | 78565b2 | 2009-06-28 19:19:51 +0000 | [diff] [blame] | 4725 | module = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4726 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4727 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4728 | int res; |
| 4729 | Py_ssize_t len; |
| 4730 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4731 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4732 | if (tmp == NULL) goto failed; |
| 4733 | if (!PyList_Check(tmp)) { |
| 4734 | PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4735 | goto failed; |
| 4736 | } |
| 4737 | len = PyList_GET_SIZE(tmp); |
| 4738 | names = asdl_seq_new(len, arena); |
| 4739 | if (names == NULL) goto failed; |
| 4740 | for (i = 0; i < len; i++) { |
| 4741 | alias_ty value; |
| 4742 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4743 | if (res != 0) goto failed; |
| 4744 | asdl_seq_SET(names, i, value); |
| 4745 | } |
| 4746 | Py_XDECREF(tmp); |
| 4747 | tmp = NULL; |
| 4748 | } else { |
| 4749 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 4750 | return 1; |
| 4751 | } |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 4752 | if (exists_not_none(obj, &PyId_level)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4753 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4754 | tmp = _PyObject_GetAttrId(obj, &PyId_level); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4755 | if (tmp == NULL) goto failed; |
| 4756 | res = obj2ast_int(tmp, &level, arena); |
| 4757 | if (res != 0) goto failed; |
| 4758 | Py_XDECREF(tmp); |
| 4759 | tmp = NULL; |
| 4760 | } else { |
| 4761 | level = 0; |
| 4762 | } |
| 4763 | *out = ImportFrom(module, names, level, lineno, col_offset, |
| 4764 | arena); |
| 4765 | if (*out == NULL) goto failed; |
| 4766 | return 0; |
| 4767 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4768 | isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type); |
| 4769 | if (isinstance == -1) { |
| 4770 | return 1; |
| 4771 | } |
| 4772 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4773 | asdl_seq* names; |
| 4774 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4775 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4776 | int res; |
| 4777 | Py_ssize_t len; |
| 4778 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4779 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4780 | if (tmp == NULL) goto failed; |
| 4781 | if (!PyList_Check(tmp)) { |
| 4782 | PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4783 | goto failed; |
| 4784 | } |
| 4785 | len = PyList_GET_SIZE(tmp); |
| 4786 | names = asdl_seq_new(len, arena); |
| 4787 | if (names == NULL) goto failed; |
| 4788 | for (i = 0; i < len; i++) { |
| 4789 | identifier value; |
| 4790 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4791 | if (res != 0) goto failed; |
| 4792 | asdl_seq_SET(names, i, value); |
| 4793 | } |
| 4794 | Py_XDECREF(tmp); |
| 4795 | tmp = NULL; |
| 4796 | } else { |
| 4797 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 4798 | return 1; |
| 4799 | } |
| 4800 | *out = Global(names, lineno, col_offset, arena); |
| 4801 | if (*out == NULL) goto failed; |
| 4802 | return 0; |
| 4803 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4804 | isinstance = PyObject_IsInstance(obj, (PyObject*)Nonlocal_type); |
| 4805 | if (isinstance == -1) { |
| 4806 | return 1; |
| 4807 | } |
| 4808 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4809 | asdl_seq* names; |
| 4810 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4811 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4812 | int res; |
| 4813 | Py_ssize_t len; |
| 4814 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4815 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4816 | if (tmp == NULL) goto failed; |
| 4817 | if (!PyList_Check(tmp)) { |
| 4818 | PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4819 | goto failed; |
| 4820 | } |
| 4821 | len = PyList_GET_SIZE(tmp); |
| 4822 | names = asdl_seq_new(len, arena); |
| 4823 | if (names == NULL) goto failed; |
| 4824 | for (i = 0; i < len; i++) { |
| 4825 | identifier value; |
| 4826 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4827 | if (res != 0) goto failed; |
| 4828 | asdl_seq_SET(names, i, value); |
| 4829 | } |
| 4830 | Py_XDECREF(tmp); |
| 4831 | tmp = NULL; |
| 4832 | } else { |
| 4833 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 4834 | return 1; |
| 4835 | } |
| 4836 | *out = Nonlocal(names, lineno, col_offset, arena); |
| 4837 | if (*out == NULL) goto failed; |
| 4838 | return 0; |
| 4839 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4840 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type); |
| 4841 | if (isinstance == -1) { |
| 4842 | return 1; |
| 4843 | } |
| 4844 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4845 | expr_ty value; |
| 4846 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4847 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4848 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4849 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4850 | if (tmp == NULL) goto failed; |
| 4851 | res = obj2ast_expr(tmp, &value, arena); |
| 4852 | if (res != 0) goto failed; |
| 4853 | Py_XDECREF(tmp); |
| 4854 | tmp = NULL; |
| 4855 | } else { |
| 4856 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 4857 | return 1; |
| 4858 | } |
| 4859 | *out = Expr(value, lineno, col_offset, arena); |
| 4860 | if (*out == NULL) goto failed; |
| 4861 | return 0; |
| 4862 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4863 | isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type); |
| 4864 | if (isinstance == -1) { |
| 4865 | return 1; |
| 4866 | } |
| 4867 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4868 | |
| 4869 | *out = Pass(lineno, col_offset, arena); |
| 4870 | if (*out == NULL) goto failed; |
| 4871 | return 0; |
| 4872 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4873 | isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type); |
| 4874 | if (isinstance == -1) { |
| 4875 | return 1; |
| 4876 | } |
| 4877 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4878 | |
| 4879 | *out = Break(lineno, col_offset, arena); |
| 4880 | if (*out == NULL) goto failed; |
| 4881 | return 0; |
| 4882 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4883 | isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type); |
| 4884 | if (isinstance == -1) { |
| 4885 | return 1; |
| 4886 | } |
| 4887 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4888 | |
| 4889 | *out = Continue(lineno, col_offset, arena); |
| 4890 | if (*out == NULL) goto failed; |
| 4891 | return 0; |
| 4892 | } |
| 4893 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 4894 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
| 4895 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 4896 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4897 | return 1; |
| 4898 | } |
| 4899 | |
| 4900 | int |
| 4901 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 4902 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4903 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4904 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 4905 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4906 | int lineno; |
| 4907 | int col_offset; |
| 4908 | |
| 4909 | if (obj == Py_None) { |
| 4910 | *out = NULL; |
| 4911 | return 0; |
| 4912 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4913 | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4914 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4915 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4916 | if (tmp == NULL) goto failed; |
| 4917 | res = obj2ast_int(tmp, &lineno, arena); |
| 4918 | if (res != 0) goto failed; |
| 4919 | Py_XDECREF(tmp); |
| 4920 | tmp = NULL; |
| 4921 | } else { |
| 4922 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 4923 | return 1; |
| 4924 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4925 | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4926 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4927 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4928 | if (tmp == NULL) goto failed; |
| 4929 | res = obj2ast_int(tmp, &col_offset, arena); |
| 4930 | if (res != 0) goto failed; |
| 4931 | Py_XDECREF(tmp); |
| 4932 | tmp = NULL; |
| 4933 | } else { |
| 4934 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 4935 | return 1; |
| 4936 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4937 | isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type); |
| 4938 | if (isinstance == -1) { |
| 4939 | return 1; |
| 4940 | } |
| 4941 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4942 | boolop_ty op; |
| 4943 | asdl_seq* values; |
| 4944 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4945 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4946 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4947 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4948 | if (tmp == NULL) goto failed; |
| 4949 | res = obj2ast_boolop(tmp, &op, arena); |
| 4950 | if (res != 0) goto failed; |
| 4951 | Py_XDECREF(tmp); |
| 4952 | tmp = NULL; |
| 4953 | } else { |
| 4954 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 4955 | return 1; |
| 4956 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4957 | if (_PyObject_HasAttrId(obj, &PyId_values)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4958 | int res; |
| 4959 | Py_ssize_t len; |
| 4960 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4961 | tmp = _PyObject_GetAttrId(obj, &PyId_values); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4962 | if (tmp == NULL) goto failed; |
| 4963 | if (!PyList_Check(tmp)) { |
| 4964 | PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4965 | goto failed; |
| 4966 | } |
| 4967 | len = PyList_GET_SIZE(tmp); |
| 4968 | values = asdl_seq_new(len, arena); |
| 4969 | if (values == NULL) goto failed; |
| 4970 | for (i = 0; i < len; i++) { |
| 4971 | expr_ty value; |
| 4972 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4973 | if (res != 0) goto failed; |
| 4974 | asdl_seq_SET(values, i, value); |
| 4975 | } |
| 4976 | Py_XDECREF(tmp); |
| 4977 | tmp = NULL; |
| 4978 | } else { |
| 4979 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 4980 | return 1; |
| 4981 | } |
| 4982 | *out = BoolOp(op, values, lineno, col_offset, arena); |
| 4983 | if (*out == NULL) goto failed; |
| 4984 | return 0; |
| 4985 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4986 | isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type); |
| 4987 | if (isinstance == -1) { |
| 4988 | return 1; |
| 4989 | } |
| 4990 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4991 | expr_ty left; |
| 4992 | operator_ty op; |
| 4993 | expr_ty right; |
| 4994 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4995 | if (_PyObject_HasAttrId(obj, &PyId_left)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4996 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 4997 | tmp = _PyObject_GetAttrId(obj, &PyId_left); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4998 | if (tmp == NULL) goto failed; |
| 4999 | res = obj2ast_expr(tmp, &left, arena); |
| 5000 | if (res != 0) goto failed; |
| 5001 | Py_XDECREF(tmp); |
| 5002 | tmp = NULL; |
| 5003 | } else { |
| 5004 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 5005 | return 1; |
| 5006 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5007 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5008 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5009 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5010 | if (tmp == NULL) goto failed; |
| 5011 | res = obj2ast_operator(tmp, &op, arena); |
| 5012 | if (res != 0) goto failed; |
| 5013 | Py_XDECREF(tmp); |
| 5014 | tmp = NULL; |
| 5015 | } else { |
| 5016 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 5017 | return 1; |
| 5018 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5019 | if (_PyObject_HasAttrId(obj, &PyId_right)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5020 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5021 | tmp = _PyObject_GetAttrId(obj, &PyId_right); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5022 | if (tmp == NULL) goto failed; |
| 5023 | res = obj2ast_expr(tmp, &right, arena); |
| 5024 | if (res != 0) goto failed; |
| 5025 | Py_XDECREF(tmp); |
| 5026 | tmp = NULL; |
| 5027 | } else { |
| 5028 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 5029 | return 1; |
| 5030 | } |
| 5031 | *out = BinOp(left, op, right, lineno, col_offset, arena); |
| 5032 | if (*out == NULL) goto failed; |
| 5033 | return 0; |
| 5034 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5035 | isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type); |
| 5036 | if (isinstance == -1) { |
| 5037 | return 1; |
| 5038 | } |
| 5039 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5040 | unaryop_ty op; |
| 5041 | expr_ty operand; |
| 5042 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5043 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5044 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5045 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5046 | if (tmp == NULL) goto failed; |
| 5047 | res = obj2ast_unaryop(tmp, &op, arena); |
| 5048 | if (res != 0) goto failed; |
| 5049 | Py_XDECREF(tmp); |
| 5050 | tmp = NULL; |
| 5051 | } else { |
| 5052 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 5053 | return 1; |
| 5054 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5055 | if (_PyObject_HasAttrId(obj, &PyId_operand)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5056 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5057 | tmp = _PyObject_GetAttrId(obj, &PyId_operand); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5058 | if (tmp == NULL) goto failed; |
| 5059 | res = obj2ast_expr(tmp, &operand, arena); |
| 5060 | if (res != 0) goto failed; |
| 5061 | Py_XDECREF(tmp); |
| 5062 | tmp = NULL; |
| 5063 | } else { |
| 5064 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 5065 | return 1; |
| 5066 | } |
| 5067 | *out = UnaryOp(op, operand, lineno, col_offset, arena); |
| 5068 | if (*out == NULL) goto failed; |
| 5069 | return 0; |
| 5070 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5071 | isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type); |
| 5072 | if (isinstance == -1) { |
| 5073 | return 1; |
| 5074 | } |
| 5075 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5076 | arguments_ty args; |
| 5077 | expr_ty body; |
| 5078 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5079 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5080 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5081 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5082 | if (tmp == NULL) goto failed; |
| 5083 | res = obj2ast_arguments(tmp, &args, arena); |
| 5084 | if (res != 0) goto failed; |
| 5085 | Py_XDECREF(tmp); |
| 5086 | tmp = NULL; |
| 5087 | } else { |
| 5088 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 5089 | return 1; |
| 5090 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5091 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5092 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5093 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5094 | if (tmp == NULL) goto failed; |
| 5095 | res = obj2ast_expr(tmp, &body, arena); |
| 5096 | if (res != 0) goto failed; |
| 5097 | Py_XDECREF(tmp); |
| 5098 | tmp = NULL; |
| 5099 | } else { |
| 5100 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 5101 | return 1; |
| 5102 | } |
| 5103 | *out = Lambda(args, body, lineno, col_offset, arena); |
| 5104 | if (*out == NULL) goto failed; |
| 5105 | return 0; |
| 5106 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5107 | isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type); |
| 5108 | if (isinstance == -1) { |
| 5109 | return 1; |
| 5110 | } |
| 5111 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5112 | expr_ty test; |
| 5113 | expr_ty body; |
| 5114 | expr_ty orelse; |
| 5115 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5116 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5117 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5118 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5119 | if (tmp == NULL) goto failed; |
| 5120 | res = obj2ast_expr(tmp, &test, arena); |
| 5121 | if (res != 0) goto failed; |
| 5122 | Py_XDECREF(tmp); |
| 5123 | tmp = NULL; |
| 5124 | } else { |
| 5125 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 5126 | return 1; |
| 5127 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5128 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5129 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5130 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5131 | if (tmp == NULL) goto failed; |
| 5132 | res = obj2ast_expr(tmp, &body, arena); |
| 5133 | if (res != 0) goto failed; |
| 5134 | Py_XDECREF(tmp); |
| 5135 | tmp = NULL; |
| 5136 | } else { |
| 5137 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 5138 | return 1; |
| 5139 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5140 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5141 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5142 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5143 | if (tmp == NULL) goto failed; |
| 5144 | res = obj2ast_expr(tmp, &orelse, arena); |
| 5145 | if (res != 0) goto failed; |
| 5146 | Py_XDECREF(tmp); |
| 5147 | tmp = NULL; |
| 5148 | } else { |
| 5149 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 5150 | return 1; |
| 5151 | } |
| 5152 | *out = IfExp(test, body, orelse, lineno, col_offset, arena); |
| 5153 | if (*out == NULL) goto failed; |
| 5154 | return 0; |
| 5155 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5156 | isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type); |
| 5157 | if (isinstance == -1) { |
| 5158 | return 1; |
| 5159 | } |
| 5160 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5161 | asdl_seq* keys; |
| 5162 | asdl_seq* values; |
| 5163 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5164 | if (_PyObject_HasAttrId(obj, &PyId_keys)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5165 | int res; |
| 5166 | Py_ssize_t len; |
| 5167 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5168 | tmp = _PyObject_GetAttrId(obj, &PyId_keys); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5169 | if (tmp == NULL) goto failed; |
| 5170 | if (!PyList_Check(tmp)) { |
| 5171 | PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5172 | goto failed; |
| 5173 | } |
| 5174 | len = PyList_GET_SIZE(tmp); |
| 5175 | keys = asdl_seq_new(len, arena); |
| 5176 | if (keys == NULL) goto failed; |
| 5177 | for (i = 0; i < len; i++) { |
| 5178 | expr_ty value; |
| 5179 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5180 | if (res != 0) goto failed; |
| 5181 | asdl_seq_SET(keys, i, value); |
| 5182 | } |
| 5183 | Py_XDECREF(tmp); |
| 5184 | tmp = NULL; |
| 5185 | } else { |
| 5186 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 5187 | return 1; |
| 5188 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5189 | if (_PyObject_HasAttrId(obj, &PyId_values)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5190 | int res; |
| 5191 | Py_ssize_t len; |
| 5192 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5193 | tmp = _PyObject_GetAttrId(obj, &PyId_values); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5194 | if (tmp == NULL) goto failed; |
| 5195 | if (!PyList_Check(tmp)) { |
| 5196 | PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5197 | goto failed; |
| 5198 | } |
| 5199 | len = PyList_GET_SIZE(tmp); |
| 5200 | values = asdl_seq_new(len, arena); |
| 5201 | if (values == NULL) goto failed; |
| 5202 | for (i = 0; i < len; i++) { |
| 5203 | expr_ty value; |
| 5204 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5205 | if (res != 0) goto failed; |
| 5206 | asdl_seq_SET(values, i, value); |
| 5207 | } |
| 5208 | Py_XDECREF(tmp); |
| 5209 | tmp = NULL; |
| 5210 | } else { |
| 5211 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 5212 | return 1; |
| 5213 | } |
| 5214 | *out = Dict(keys, values, lineno, col_offset, arena); |
| 5215 | if (*out == NULL) goto failed; |
| 5216 | return 0; |
| 5217 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5218 | isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type); |
| 5219 | if (isinstance == -1) { |
| 5220 | return 1; |
| 5221 | } |
| 5222 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5223 | asdl_seq* elts; |
| 5224 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5225 | if (_PyObject_HasAttrId(obj, &PyId_elts)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5226 | int res; |
| 5227 | Py_ssize_t len; |
| 5228 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5229 | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5230 | if (tmp == NULL) goto failed; |
| 5231 | if (!PyList_Check(tmp)) { |
| 5232 | PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5233 | goto failed; |
| 5234 | } |
| 5235 | len = PyList_GET_SIZE(tmp); |
| 5236 | elts = asdl_seq_new(len, arena); |
| 5237 | if (elts == NULL) goto failed; |
| 5238 | for (i = 0; i < len; i++) { |
| 5239 | expr_ty value; |
| 5240 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5241 | if (res != 0) goto failed; |
| 5242 | asdl_seq_SET(elts, i, value); |
| 5243 | } |
| 5244 | Py_XDECREF(tmp); |
| 5245 | tmp = NULL; |
| 5246 | } else { |
| 5247 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 5248 | return 1; |
| 5249 | } |
| 5250 | *out = Set(elts, lineno, col_offset, arena); |
| 5251 | if (*out == NULL) goto failed; |
| 5252 | return 0; |
| 5253 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5254 | isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type); |
| 5255 | if (isinstance == -1) { |
| 5256 | return 1; |
| 5257 | } |
| 5258 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5259 | expr_ty elt; |
| 5260 | asdl_seq* generators; |
| 5261 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5262 | if (_PyObject_HasAttrId(obj, &PyId_elt)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5263 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5264 | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5265 | if (tmp == NULL) goto failed; |
| 5266 | res = obj2ast_expr(tmp, &elt, arena); |
| 5267 | if (res != 0) goto failed; |
| 5268 | Py_XDECREF(tmp); |
| 5269 | tmp = NULL; |
| 5270 | } else { |
| 5271 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 5272 | return 1; |
| 5273 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5274 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5275 | int res; |
| 5276 | Py_ssize_t len; |
| 5277 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5278 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5279 | if (tmp == NULL) goto failed; |
| 5280 | if (!PyList_Check(tmp)) { |
| 5281 | PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5282 | goto failed; |
| 5283 | } |
| 5284 | len = PyList_GET_SIZE(tmp); |
| 5285 | generators = asdl_seq_new(len, arena); |
| 5286 | if (generators == NULL) goto failed; |
| 5287 | for (i = 0; i < len; i++) { |
| 5288 | comprehension_ty value; |
| 5289 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5290 | if (res != 0) goto failed; |
| 5291 | asdl_seq_SET(generators, i, value); |
| 5292 | } |
| 5293 | Py_XDECREF(tmp); |
| 5294 | tmp = NULL; |
| 5295 | } else { |
| 5296 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 5297 | return 1; |
| 5298 | } |
| 5299 | *out = ListComp(elt, generators, lineno, col_offset, arena); |
| 5300 | if (*out == NULL) goto failed; |
| 5301 | return 0; |
| 5302 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5303 | isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type); |
| 5304 | if (isinstance == -1) { |
| 5305 | return 1; |
| 5306 | } |
| 5307 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5308 | expr_ty elt; |
| 5309 | asdl_seq* generators; |
| 5310 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5311 | if (_PyObject_HasAttrId(obj, &PyId_elt)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5312 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5313 | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5314 | if (tmp == NULL) goto failed; |
| 5315 | res = obj2ast_expr(tmp, &elt, arena); |
| 5316 | if (res != 0) goto failed; |
| 5317 | Py_XDECREF(tmp); |
| 5318 | tmp = NULL; |
| 5319 | } else { |
| 5320 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 5321 | return 1; |
| 5322 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5323 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5324 | int res; |
| 5325 | Py_ssize_t len; |
| 5326 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5327 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5328 | if (tmp == NULL) goto failed; |
| 5329 | if (!PyList_Check(tmp)) { |
| 5330 | PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5331 | goto failed; |
| 5332 | } |
| 5333 | len = PyList_GET_SIZE(tmp); |
| 5334 | generators = asdl_seq_new(len, arena); |
| 5335 | if (generators == NULL) goto failed; |
| 5336 | for (i = 0; i < len; i++) { |
| 5337 | comprehension_ty value; |
| 5338 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5339 | if (res != 0) goto failed; |
| 5340 | asdl_seq_SET(generators, i, value); |
| 5341 | } |
| 5342 | Py_XDECREF(tmp); |
| 5343 | tmp = NULL; |
| 5344 | } else { |
| 5345 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 5346 | return 1; |
| 5347 | } |
| 5348 | *out = SetComp(elt, generators, lineno, col_offset, arena); |
| 5349 | if (*out == NULL) goto failed; |
| 5350 | return 0; |
| 5351 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5352 | isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type); |
| 5353 | if (isinstance == -1) { |
| 5354 | return 1; |
| 5355 | } |
| 5356 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5357 | expr_ty key; |
| 5358 | expr_ty value; |
| 5359 | asdl_seq* generators; |
| 5360 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5361 | if (_PyObject_HasAttrId(obj, &PyId_key)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5362 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5363 | tmp = _PyObject_GetAttrId(obj, &PyId_key); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5364 | if (tmp == NULL) goto failed; |
| 5365 | res = obj2ast_expr(tmp, &key, arena); |
| 5366 | if (res != 0) goto failed; |
| 5367 | Py_XDECREF(tmp); |
| 5368 | tmp = NULL; |
| 5369 | } else { |
| 5370 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 5371 | return 1; |
| 5372 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5373 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5374 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5375 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5376 | if (tmp == NULL) goto failed; |
| 5377 | res = obj2ast_expr(tmp, &value, arena); |
| 5378 | if (res != 0) goto failed; |
| 5379 | Py_XDECREF(tmp); |
| 5380 | tmp = NULL; |
| 5381 | } else { |
| 5382 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 5383 | return 1; |
| 5384 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5385 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5386 | int res; |
| 5387 | Py_ssize_t len; |
| 5388 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5389 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5390 | if (tmp == NULL) goto failed; |
| 5391 | if (!PyList_Check(tmp)) { |
| 5392 | PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5393 | goto failed; |
| 5394 | } |
| 5395 | len = PyList_GET_SIZE(tmp); |
| 5396 | generators = asdl_seq_new(len, arena); |
| 5397 | if (generators == NULL) goto failed; |
| 5398 | for (i = 0; i < len; i++) { |
| 5399 | comprehension_ty value; |
| 5400 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5401 | if (res != 0) goto failed; |
| 5402 | asdl_seq_SET(generators, i, value); |
| 5403 | } |
| 5404 | Py_XDECREF(tmp); |
| 5405 | tmp = NULL; |
| 5406 | } else { |
| 5407 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 5408 | return 1; |
| 5409 | } |
| 5410 | *out = DictComp(key, value, generators, lineno, col_offset, |
| 5411 | arena); |
| 5412 | if (*out == NULL) goto failed; |
| 5413 | return 0; |
| 5414 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5415 | isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type); |
| 5416 | if (isinstance == -1) { |
| 5417 | return 1; |
| 5418 | } |
| 5419 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5420 | expr_ty elt; |
| 5421 | asdl_seq* generators; |
| 5422 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5423 | if (_PyObject_HasAttrId(obj, &PyId_elt)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5424 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5425 | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5426 | if (tmp == NULL) goto failed; |
| 5427 | res = obj2ast_expr(tmp, &elt, arena); |
| 5428 | if (res != 0) goto failed; |
| 5429 | Py_XDECREF(tmp); |
| 5430 | tmp = NULL; |
| 5431 | } else { |
| 5432 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 5433 | return 1; |
| 5434 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5435 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5436 | int res; |
| 5437 | Py_ssize_t len; |
| 5438 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5439 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5440 | if (tmp == NULL) goto failed; |
| 5441 | if (!PyList_Check(tmp)) { |
| 5442 | PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5443 | goto failed; |
| 5444 | } |
| 5445 | len = PyList_GET_SIZE(tmp); |
| 5446 | generators = asdl_seq_new(len, arena); |
| 5447 | if (generators == NULL) goto failed; |
| 5448 | for (i = 0; i < len; i++) { |
| 5449 | comprehension_ty value; |
| 5450 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5451 | if (res != 0) goto failed; |
| 5452 | asdl_seq_SET(generators, i, value); |
| 5453 | } |
| 5454 | Py_XDECREF(tmp); |
| 5455 | tmp = NULL; |
| 5456 | } else { |
| 5457 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 5458 | return 1; |
| 5459 | } |
| 5460 | *out = GeneratorExp(elt, generators, lineno, col_offset, arena); |
| 5461 | if (*out == NULL) goto failed; |
| 5462 | return 0; |
| 5463 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5464 | isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); |
| 5465 | if (isinstance == -1) { |
| 5466 | return 1; |
| 5467 | } |
| 5468 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5469 | expr_ty value; |
| 5470 | |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 5471 | if (exists_not_none(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5472 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5473 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5474 | if (tmp == NULL) goto failed; |
| 5475 | res = obj2ast_expr(tmp, &value, arena); |
| 5476 | if (res != 0) goto failed; |
| 5477 | Py_XDECREF(tmp); |
| 5478 | tmp = NULL; |
| 5479 | } else { |
| 5480 | value = NULL; |
| 5481 | } |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 5482 | *out = Yield(value, lineno, col_offset, arena); |
| 5483 | if (*out == NULL) goto failed; |
| 5484 | return 0; |
| 5485 | } |
| 5486 | isinstance = PyObject_IsInstance(obj, (PyObject*)YieldFrom_type); |
| 5487 | if (isinstance == -1) { |
| 5488 | return 1; |
| 5489 | } |
| 5490 | if (isinstance) { |
| 5491 | expr_ty value; |
| 5492 | |
| 5493 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 5494 | int res; |
| 5495 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 5496 | if (tmp == NULL) goto failed; |
| 5497 | res = obj2ast_expr(tmp, &value, arena); |
| 5498 | if (res != 0) goto failed; |
| 5499 | Py_XDECREF(tmp); |
| 5500 | tmp = NULL; |
| 5501 | } else { |
Mark Dickinson | ded35ae | 2012-11-25 14:36:26 +0000 | [diff] [blame] | 5502 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom"); |
| 5503 | return 1; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 5504 | } |
| 5505 | *out = YieldFrom(value, lineno, col_offset, arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5506 | if (*out == NULL) goto failed; |
| 5507 | return 0; |
| 5508 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5509 | isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); |
| 5510 | if (isinstance == -1) { |
| 5511 | return 1; |
| 5512 | } |
| 5513 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5514 | expr_ty left; |
| 5515 | asdl_int_seq* ops; |
| 5516 | asdl_seq* comparators; |
| 5517 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5518 | if (_PyObject_HasAttrId(obj, &PyId_left)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5519 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5520 | tmp = _PyObject_GetAttrId(obj, &PyId_left); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5521 | if (tmp == NULL) goto failed; |
| 5522 | res = obj2ast_expr(tmp, &left, arena); |
| 5523 | if (res != 0) goto failed; |
| 5524 | Py_XDECREF(tmp); |
| 5525 | tmp = NULL; |
| 5526 | } else { |
| 5527 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 5528 | return 1; |
| 5529 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5530 | if (_PyObject_HasAttrId(obj, &PyId_ops)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5531 | int res; |
| 5532 | Py_ssize_t len; |
| 5533 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5534 | tmp = _PyObject_GetAttrId(obj, &PyId_ops); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5535 | if (tmp == NULL) goto failed; |
| 5536 | if (!PyList_Check(tmp)) { |
| 5537 | PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5538 | goto failed; |
| 5539 | } |
| 5540 | len = PyList_GET_SIZE(tmp); |
| 5541 | ops = asdl_int_seq_new(len, arena); |
| 5542 | if (ops == NULL) goto failed; |
| 5543 | for (i = 0; i < len; i++) { |
| 5544 | cmpop_ty value; |
| 5545 | res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5546 | if (res != 0) goto failed; |
| 5547 | asdl_seq_SET(ops, i, value); |
| 5548 | } |
| 5549 | Py_XDECREF(tmp); |
| 5550 | tmp = NULL; |
| 5551 | } else { |
| 5552 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 5553 | return 1; |
| 5554 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5555 | if (_PyObject_HasAttrId(obj, &PyId_comparators)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5556 | int res; |
| 5557 | Py_ssize_t len; |
| 5558 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5559 | tmp = _PyObject_GetAttrId(obj, &PyId_comparators); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5560 | if (tmp == NULL) goto failed; |
| 5561 | if (!PyList_Check(tmp)) { |
| 5562 | PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5563 | goto failed; |
| 5564 | } |
| 5565 | len = PyList_GET_SIZE(tmp); |
| 5566 | comparators = asdl_seq_new(len, arena); |
| 5567 | if (comparators == NULL) goto failed; |
| 5568 | for (i = 0; i < len; i++) { |
| 5569 | expr_ty value; |
| 5570 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5571 | if (res != 0) goto failed; |
| 5572 | asdl_seq_SET(comparators, i, value); |
| 5573 | } |
| 5574 | Py_XDECREF(tmp); |
| 5575 | tmp = NULL; |
| 5576 | } else { |
| 5577 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 5578 | return 1; |
| 5579 | } |
| 5580 | *out = Compare(left, ops, comparators, lineno, col_offset, |
| 5581 | arena); |
| 5582 | if (*out == NULL) goto failed; |
| 5583 | return 0; |
| 5584 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5585 | isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type); |
| 5586 | if (isinstance == -1) { |
| 5587 | return 1; |
| 5588 | } |
| 5589 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5590 | expr_ty func; |
| 5591 | asdl_seq* args; |
| 5592 | asdl_seq* keywords; |
| 5593 | expr_ty starargs; |
| 5594 | expr_ty kwargs; |
| 5595 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5596 | if (_PyObject_HasAttrId(obj, &PyId_func)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5597 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5598 | tmp = _PyObject_GetAttrId(obj, &PyId_func); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5599 | if (tmp == NULL) goto failed; |
| 5600 | res = obj2ast_expr(tmp, &func, arena); |
| 5601 | if (res != 0) goto failed; |
| 5602 | Py_XDECREF(tmp); |
| 5603 | tmp = NULL; |
| 5604 | } else { |
| 5605 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 5606 | return 1; |
| 5607 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5608 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5609 | int res; |
| 5610 | Py_ssize_t len; |
| 5611 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5612 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5613 | if (tmp == NULL) goto failed; |
| 5614 | if (!PyList_Check(tmp)) { |
| 5615 | PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5616 | goto failed; |
| 5617 | } |
| 5618 | len = PyList_GET_SIZE(tmp); |
| 5619 | args = asdl_seq_new(len, arena); |
| 5620 | if (args == NULL) goto failed; |
| 5621 | for (i = 0; i < len; i++) { |
| 5622 | expr_ty value; |
| 5623 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5624 | if (res != 0) goto failed; |
| 5625 | asdl_seq_SET(args, i, value); |
| 5626 | } |
| 5627 | Py_XDECREF(tmp); |
| 5628 | tmp = NULL; |
| 5629 | } else { |
| 5630 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 5631 | return 1; |
| 5632 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5633 | if (_PyObject_HasAttrId(obj, &PyId_keywords)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5634 | int res; |
| 5635 | Py_ssize_t len; |
| 5636 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5637 | tmp = _PyObject_GetAttrId(obj, &PyId_keywords); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5638 | if (tmp == NULL) goto failed; |
| 5639 | if (!PyList_Check(tmp)) { |
| 5640 | PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5641 | goto failed; |
| 5642 | } |
| 5643 | len = PyList_GET_SIZE(tmp); |
| 5644 | keywords = asdl_seq_new(len, arena); |
| 5645 | if (keywords == NULL) goto failed; |
| 5646 | for (i = 0; i < len; i++) { |
| 5647 | keyword_ty value; |
| 5648 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5649 | if (res != 0) goto failed; |
| 5650 | asdl_seq_SET(keywords, i, value); |
| 5651 | } |
| 5652 | Py_XDECREF(tmp); |
| 5653 | tmp = NULL; |
| 5654 | } else { |
| 5655 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 5656 | return 1; |
| 5657 | } |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 5658 | if (exists_not_none(obj, &PyId_starargs)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5659 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5660 | tmp = _PyObject_GetAttrId(obj, &PyId_starargs); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5661 | if (tmp == NULL) goto failed; |
| 5662 | res = obj2ast_expr(tmp, &starargs, arena); |
| 5663 | if (res != 0) goto failed; |
| 5664 | Py_XDECREF(tmp); |
| 5665 | tmp = NULL; |
| 5666 | } else { |
| 5667 | starargs = NULL; |
| 5668 | } |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 5669 | if (exists_not_none(obj, &PyId_kwargs)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5670 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5671 | tmp = _PyObject_GetAttrId(obj, &PyId_kwargs); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5672 | if (tmp == NULL) goto failed; |
| 5673 | res = obj2ast_expr(tmp, &kwargs, arena); |
| 5674 | if (res != 0) goto failed; |
| 5675 | Py_XDECREF(tmp); |
| 5676 | tmp = NULL; |
| 5677 | } else { |
| 5678 | kwargs = NULL; |
| 5679 | } |
| 5680 | *out = Call(func, args, keywords, starargs, kwargs, lineno, |
| 5681 | col_offset, arena); |
| 5682 | if (*out == NULL) goto failed; |
| 5683 | return 0; |
| 5684 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5685 | isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type); |
| 5686 | if (isinstance == -1) { |
| 5687 | return 1; |
| 5688 | } |
| 5689 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5690 | object n; |
| 5691 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5692 | if (_PyObject_HasAttrId(obj, &PyId_n)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5693 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5694 | tmp = _PyObject_GetAttrId(obj, &PyId_n); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5695 | if (tmp == NULL) goto failed; |
| 5696 | res = obj2ast_object(tmp, &n, arena); |
| 5697 | if (res != 0) goto failed; |
| 5698 | Py_XDECREF(tmp); |
| 5699 | tmp = NULL; |
| 5700 | } else { |
| 5701 | PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num"); |
| 5702 | return 1; |
| 5703 | } |
| 5704 | *out = Num(n, lineno, col_offset, arena); |
| 5705 | if (*out == NULL) goto failed; |
| 5706 | return 0; |
| 5707 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5708 | isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type); |
| 5709 | if (isinstance == -1) { |
| 5710 | return 1; |
| 5711 | } |
| 5712 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5713 | string s; |
| 5714 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5715 | if (_PyObject_HasAttrId(obj, &PyId_s)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5716 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5717 | tmp = _PyObject_GetAttrId(obj, &PyId_s); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5718 | if (tmp == NULL) goto failed; |
| 5719 | res = obj2ast_string(tmp, &s, arena); |
| 5720 | if (res != 0) goto failed; |
| 5721 | Py_XDECREF(tmp); |
| 5722 | tmp = NULL; |
| 5723 | } else { |
| 5724 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str"); |
| 5725 | return 1; |
| 5726 | } |
| 5727 | *out = Str(s, lineno, col_offset, arena); |
| 5728 | if (*out == NULL) goto failed; |
| 5729 | return 0; |
| 5730 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5731 | isinstance = PyObject_IsInstance(obj, (PyObject*)Bytes_type); |
| 5732 | if (isinstance == -1) { |
| 5733 | return 1; |
| 5734 | } |
| 5735 | if (isinstance) { |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 5736 | bytes s; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5737 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5738 | if (_PyObject_HasAttrId(obj, &PyId_s)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5739 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5740 | tmp = _PyObject_GetAttrId(obj, &PyId_s); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5741 | if (tmp == NULL) goto failed; |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 5742 | res = obj2ast_bytes(tmp, &s, arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5743 | if (res != 0) goto failed; |
| 5744 | Py_XDECREF(tmp); |
| 5745 | tmp = NULL; |
| 5746 | } else { |
| 5747 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Bytes"); |
| 5748 | return 1; |
| 5749 | } |
| 5750 | *out = Bytes(s, lineno, col_offset, arena); |
| 5751 | if (*out == NULL) goto failed; |
| 5752 | return 0; |
| 5753 | } |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 5754 | isinstance = PyObject_IsInstance(obj, (PyObject*)NameConstant_type); |
| 5755 | if (isinstance == -1) { |
| 5756 | return 1; |
| 5757 | } |
| 5758 | if (isinstance) { |
| 5759 | singleton value; |
| 5760 | |
| 5761 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 5762 | int res; |
| 5763 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 5764 | if (tmp == NULL) goto failed; |
| 5765 | res = obj2ast_singleton(tmp, &value, arena); |
| 5766 | if (res != 0) goto failed; |
| 5767 | Py_XDECREF(tmp); |
| 5768 | tmp = NULL; |
| 5769 | } else { |
| 5770 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NameConstant"); |
| 5771 | return 1; |
| 5772 | } |
| 5773 | *out = NameConstant(value, lineno, col_offset, arena); |
| 5774 | if (*out == NULL) goto failed; |
| 5775 | return 0; |
| 5776 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5777 | isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type); |
| 5778 | if (isinstance == -1) { |
| 5779 | return 1; |
| 5780 | } |
| 5781 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5782 | |
| 5783 | *out = Ellipsis(lineno, col_offset, arena); |
| 5784 | if (*out == NULL) goto failed; |
| 5785 | return 0; |
| 5786 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5787 | isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type); |
| 5788 | if (isinstance == -1) { |
| 5789 | return 1; |
| 5790 | } |
| 5791 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5792 | expr_ty value; |
| 5793 | identifier attr; |
| 5794 | expr_context_ty ctx; |
| 5795 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5796 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5797 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5798 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5799 | if (tmp == NULL) goto failed; |
| 5800 | res = obj2ast_expr(tmp, &value, arena); |
| 5801 | if (res != 0) goto failed; |
| 5802 | Py_XDECREF(tmp); |
| 5803 | tmp = NULL; |
| 5804 | } else { |
| 5805 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 5806 | return 1; |
| 5807 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5808 | if (_PyObject_HasAttrId(obj, &PyId_attr)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5809 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5810 | tmp = _PyObject_GetAttrId(obj, &PyId_attr); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5811 | if (tmp == NULL) goto failed; |
| 5812 | res = obj2ast_identifier(tmp, &attr, arena); |
| 5813 | if (res != 0) goto failed; |
| 5814 | Py_XDECREF(tmp); |
| 5815 | tmp = NULL; |
| 5816 | } else { |
| 5817 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 5818 | return 1; |
| 5819 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5820 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5821 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5822 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5823 | if (tmp == NULL) goto failed; |
| 5824 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5825 | if (res != 0) goto failed; |
| 5826 | Py_XDECREF(tmp); |
| 5827 | tmp = NULL; |
| 5828 | } else { |
| 5829 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 5830 | return 1; |
| 5831 | } |
| 5832 | *out = Attribute(value, attr, ctx, lineno, col_offset, arena); |
| 5833 | if (*out == NULL) goto failed; |
| 5834 | return 0; |
| 5835 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5836 | isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type); |
| 5837 | if (isinstance == -1) { |
| 5838 | return 1; |
| 5839 | } |
| 5840 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5841 | expr_ty value; |
| 5842 | slice_ty slice; |
| 5843 | expr_context_ty ctx; |
| 5844 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5845 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5846 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5847 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5848 | if (tmp == NULL) goto failed; |
| 5849 | res = obj2ast_expr(tmp, &value, arena); |
| 5850 | if (res != 0) goto failed; |
| 5851 | Py_XDECREF(tmp); |
| 5852 | tmp = NULL; |
| 5853 | } else { |
| 5854 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 5855 | return 1; |
| 5856 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5857 | if (_PyObject_HasAttrId(obj, &PyId_slice)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5858 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5859 | tmp = _PyObject_GetAttrId(obj, &PyId_slice); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5860 | if (tmp == NULL) goto failed; |
| 5861 | res = obj2ast_slice(tmp, &slice, arena); |
| 5862 | if (res != 0) goto failed; |
| 5863 | Py_XDECREF(tmp); |
| 5864 | tmp = NULL; |
| 5865 | } else { |
| 5866 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 5867 | return 1; |
| 5868 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5869 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5870 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5871 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5872 | if (tmp == NULL) goto failed; |
| 5873 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5874 | if (res != 0) goto failed; |
| 5875 | Py_XDECREF(tmp); |
| 5876 | tmp = NULL; |
| 5877 | } else { |
| 5878 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 5879 | return 1; |
| 5880 | } |
| 5881 | *out = Subscript(value, slice, ctx, lineno, col_offset, arena); |
| 5882 | if (*out == NULL) goto failed; |
| 5883 | return 0; |
| 5884 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5885 | isinstance = PyObject_IsInstance(obj, (PyObject*)Starred_type); |
| 5886 | if (isinstance == -1) { |
| 5887 | return 1; |
| 5888 | } |
| 5889 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5890 | expr_ty value; |
| 5891 | expr_context_ty ctx; |
| 5892 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5893 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5894 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5895 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5896 | if (tmp == NULL) goto failed; |
| 5897 | res = obj2ast_expr(tmp, &value, arena); |
| 5898 | if (res != 0) goto failed; |
| 5899 | Py_XDECREF(tmp); |
| 5900 | tmp = NULL; |
| 5901 | } else { |
| 5902 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 5903 | return 1; |
| 5904 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5905 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5906 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5907 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5908 | if (tmp == NULL) goto failed; |
| 5909 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5910 | if (res != 0) goto failed; |
| 5911 | Py_XDECREF(tmp); |
| 5912 | tmp = NULL; |
| 5913 | } else { |
| 5914 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 5915 | return 1; |
| 5916 | } |
| 5917 | *out = Starred(value, ctx, lineno, col_offset, arena); |
| 5918 | if (*out == NULL) goto failed; |
| 5919 | return 0; |
| 5920 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5921 | isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type); |
| 5922 | if (isinstance == -1) { |
| 5923 | return 1; |
| 5924 | } |
| 5925 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5926 | identifier id; |
| 5927 | expr_context_ty ctx; |
| 5928 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5929 | if (_PyObject_HasAttrId(obj, &PyId_id)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5930 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5931 | tmp = _PyObject_GetAttrId(obj, &PyId_id); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5932 | if (tmp == NULL) goto failed; |
| 5933 | res = obj2ast_identifier(tmp, &id, arena); |
| 5934 | if (res != 0) goto failed; |
| 5935 | Py_XDECREF(tmp); |
| 5936 | tmp = NULL; |
| 5937 | } else { |
| 5938 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 5939 | return 1; |
| 5940 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5941 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5942 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5943 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5944 | if (tmp == NULL) goto failed; |
| 5945 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5946 | if (res != 0) goto failed; |
| 5947 | Py_XDECREF(tmp); |
| 5948 | tmp = NULL; |
| 5949 | } else { |
| 5950 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 5951 | return 1; |
| 5952 | } |
| 5953 | *out = Name(id, ctx, lineno, col_offset, arena); |
| 5954 | if (*out == NULL) goto failed; |
| 5955 | return 0; |
| 5956 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5957 | isinstance = PyObject_IsInstance(obj, (PyObject*)List_type); |
| 5958 | if (isinstance == -1) { |
| 5959 | return 1; |
| 5960 | } |
| 5961 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5962 | asdl_seq* elts; |
| 5963 | expr_context_ty ctx; |
| 5964 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5965 | if (_PyObject_HasAttrId(obj, &PyId_elts)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5966 | int res; |
| 5967 | Py_ssize_t len; |
| 5968 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5969 | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5970 | if (tmp == NULL) goto failed; |
| 5971 | if (!PyList_Check(tmp)) { |
| 5972 | PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5973 | goto failed; |
| 5974 | } |
| 5975 | len = PyList_GET_SIZE(tmp); |
| 5976 | elts = asdl_seq_new(len, arena); |
| 5977 | if (elts == NULL) goto failed; |
| 5978 | for (i = 0; i < len; i++) { |
| 5979 | expr_ty value; |
| 5980 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5981 | if (res != 0) goto failed; |
| 5982 | asdl_seq_SET(elts, i, value); |
| 5983 | } |
| 5984 | Py_XDECREF(tmp); |
| 5985 | tmp = NULL; |
| 5986 | } else { |
| 5987 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 5988 | return 1; |
| 5989 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5990 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5991 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 5992 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5993 | if (tmp == NULL) goto failed; |
| 5994 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5995 | if (res != 0) goto failed; |
| 5996 | Py_XDECREF(tmp); |
| 5997 | tmp = NULL; |
| 5998 | } else { |
| 5999 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 6000 | return 1; |
| 6001 | } |
| 6002 | *out = List(elts, ctx, lineno, col_offset, arena); |
| 6003 | if (*out == NULL) goto failed; |
| 6004 | return 0; |
| 6005 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6006 | isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type); |
| 6007 | if (isinstance == -1) { |
| 6008 | return 1; |
| 6009 | } |
| 6010 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6011 | asdl_seq* elts; |
| 6012 | expr_context_ty ctx; |
| 6013 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6014 | if (_PyObject_HasAttrId(obj, &PyId_elts)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6015 | int res; |
| 6016 | Py_ssize_t len; |
| 6017 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6018 | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6019 | if (tmp == NULL) goto failed; |
| 6020 | if (!PyList_Check(tmp)) { |
| 6021 | PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6022 | goto failed; |
| 6023 | } |
| 6024 | len = PyList_GET_SIZE(tmp); |
| 6025 | elts = asdl_seq_new(len, arena); |
| 6026 | if (elts == NULL) goto failed; |
| 6027 | for (i = 0; i < len; i++) { |
| 6028 | expr_ty value; |
| 6029 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6030 | if (res != 0) goto failed; |
| 6031 | asdl_seq_SET(elts, i, value); |
| 6032 | } |
| 6033 | Py_XDECREF(tmp); |
| 6034 | tmp = NULL; |
| 6035 | } else { |
| 6036 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 6037 | return 1; |
| 6038 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6039 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6040 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6041 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6042 | if (tmp == NULL) goto failed; |
| 6043 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 6044 | if (res != 0) goto failed; |
| 6045 | Py_XDECREF(tmp); |
| 6046 | tmp = NULL; |
| 6047 | } else { |
| 6048 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 6049 | return 1; |
| 6050 | } |
| 6051 | *out = Tuple(elts, ctx, lineno, col_offset, arena); |
| 6052 | if (*out == NULL) goto failed; |
| 6053 | return 0; |
| 6054 | } |
| 6055 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6056 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
| 6057 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 6058 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6059 | return 1; |
| 6060 | } |
| 6061 | |
| 6062 | int |
| 6063 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 6064 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6065 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6066 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6067 | isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); |
| 6068 | if (isinstance == -1) { |
| 6069 | return 1; |
| 6070 | } |
| 6071 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6072 | *out = Load; |
| 6073 | return 0; |
| 6074 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6075 | isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type); |
| 6076 | if (isinstance == -1) { |
| 6077 | return 1; |
| 6078 | } |
| 6079 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6080 | *out = Store; |
| 6081 | return 0; |
| 6082 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6083 | isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type); |
| 6084 | if (isinstance == -1) { |
| 6085 | return 1; |
| 6086 | } |
| 6087 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6088 | *out = Del; |
| 6089 | return 0; |
| 6090 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6091 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type); |
| 6092 | if (isinstance == -1) { |
| 6093 | return 1; |
| 6094 | } |
| 6095 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6096 | *out = AugLoad; |
| 6097 | return 0; |
| 6098 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6099 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type); |
| 6100 | if (isinstance == -1) { |
| 6101 | return 1; |
| 6102 | } |
| 6103 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6104 | *out = AugStore; |
| 6105 | return 0; |
| 6106 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6107 | isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type); |
| 6108 | if (isinstance == -1) { |
| 6109 | return 1; |
| 6110 | } |
| 6111 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6112 | *out = Param; |
| 6113 | return 0; |
| 6114 | } |
| 6115 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6116 | 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] | 6117 | return 1; |
| 6118 | } |
| 6119 | |
| 6120 | int |
| 6121 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
| 6122 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6123 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6124 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 6125 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6126 | |
| 6127 | if (obj == Py_None) { |
| 6128 | *out = NULL; |
| 6129 | return 0; |
| 6130 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6131 | isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type); |
| 6132 | if (isinstance == -1) { |
| 6133 | return 1; |
| 6134 | } |
| 6135 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6136 | expr_ty lower; |
| 6137 | expr_ty upper; |
| 6138 | expr_ty step; |
| 6139 | |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 6140 | if (exists_not_none(obj, &PyId_lower)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6141 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6142 | tmp = _PyObject_GetAttrId(obj, &PyId_lower); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6143 | if (tmp == NULL) goto failed; |
| 6144 | res = obj2ast_expr(tmp, &lower, arena); |
| 6145 | if (res != 0) goto failed; |
| 6146 | Py_XDECREF(tmp); |
| 6147 | tmp = NULL; |
| 6148 | } else { |
| 6149 | lower = NULL; |
| 6150 | } |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 6151 | if (exists_not_none(obj, &PyId_upper)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6152 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6153 | tmp = _PyObject_GetAttrId(obj, &PyId_upper); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6154 | if (tmp == NULL) goto failed; |
| 6155 | res = obj2ast_expr(tmp, &upper, arena); |
| 6156 | if (res != 0) goto failed; |
| 6157 | Py_XDECREF(tmp); |
| 6158 | tmp = NULL; |
| 6159 | } else { |
| 6160 | upper = NULL; |
| 6161 | } |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 6162 | if (exists_not_none(obj, &PyId_step)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6163 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6164 | tmp = _PyObject_GetAttrId(obj, &PyId_step); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6165 | if (tmp == NULL) goto failed; |
| 6166 | res = obj2ast_expr(tmp, &step, arena); |
| 6167 | if (res != 0) goto failed; |
| 6168 | Py_XDECREF(tmp); |
| 6169 | tmp = NULL; |
| 6170 | } else { |
| 6171 | step = NULL; |
| 6172 | } |
| 6173 | *out = Slice(lower, upper, step, arena); |
| 6174 | if (*out == NULL) goto failed; |
| 6175 | return 0; |
| 6176 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6177 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type); |
| 6178 | if (isinstance == -1) { |
| 6179 | return 1; |
| 6180 | } |
| 6181 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6182 | asdl_seq* dims; |
| 6183 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6184 | if (_PyObject_HasAttrId(obj, &PyId_dims)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6185 | int res; |
| 6186 | Py_ssize_t len; |
| 6187 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6188 | tmp = _PyObject_GetAttrId(obj, &PyId_dims); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6189 | if (tmp == NULL) goto failed; |
| 6190 | if (!PyList_Check(tmp)) { |
| 6191 | PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6192 | goto failed; |
| 6193 | } |
| 6194 | len = PyList_GET_SIZE(tmp); |
| 6195 | dims = asdl_seq_new(len, arena); |
| 6196 | if (dims == NULL) goto failed; |
| 6197 | for (i = 0; i < len; i++) { |
| 6198 | slice_ty value; |
| 6199 | res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6200 | if (res != 0) goto failed; |
| 6201 | asdl_seq_SET(dims, i, value); |
| 6202 | } |
| 6203 | Py_XDECREF(tmp); |
| 6204 | tmp = NULL; |
| 6205 | } else { |
| 6206 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
| 6207 | return 1; |
| 6208 | } |
| 6209 | *out = ExtSlice(dims, arena); |
| 6210 | if (*out == NULL) goto failed; |
| 6211 | return 0; |
| 6212 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6213 | isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type); |
| 6214 | if (isinstance == -1) { |
| 6215 | return 1; |
| 6216 | } |
| 6217 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6218 | expr_ty value; |
| 6219 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6220 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6221 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6222 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6223 | if (tmp == NULL) goto failed; |
| 6224 | res = obj2ast_expr(tmp, &value, arena); |
| 6225 | if (res != 0) goto failed; |
| 6226 | Py_XDECREF(tmp); |
| 6227 | tmp = NULL; |
| 6228 | } else { |
| 6229 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
| 6230 | return 1; |
| 6231 | } |
| 6232 | *out = Index(value, arena); |
| 6233 | if (*out == NULL) goto failed; |
| 6234 | return 0; |
| 6235 | } |
| 6236 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6237 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj); |
| 6238 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 6239 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6240 | return 1; |
| 6241 | } |
| 6242 | |
| 6243 | int |
| 6244 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 6245 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6246 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6247 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6248 | isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); |
| 6249 | if (isinstance == -1) { |
| 6250 | return 1; |
| 6251 | } |
| 6252 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6253 | *out = And; |
| 6254 | return 0; |
| 6255 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6256 | isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type); |
| 6257 | if (isinstance == -1) { |
| 6258 | return 1; |
| 6259 | } |
| 6260 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6261 | *out = Or; |
| 6262 | return 0; |
| 6263 | } |
| 6264 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6265 | 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] | 6266 | return 1; |
| 6267 | } |
| 6268 | |
| 6269 | int |
| 6270 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 6271 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6272 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6273 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6274 | isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); |
| 6275 | if (isinstance == -1) { |
| 6276 | return 1; |
| 6277 | } |
| 6278 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6279 | *out = Add; |
| 6280 | return 0; |
| 6281 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6282 | isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type); |
| 6283 | if (isinstance == -1) { |
| 6284 | return 1; |
| 6285 | } |
| 6286 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6287 | *out = Sub; |
| 6288 | return 0; |
| 6289 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6290 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type); |
| 6291 | if (isinstance == -1) { |
| 6292 | return 1; |
| 6293 | } |
| 6294 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6295 | *out = Mult; |
| 6296 | return 0; |
| 6297 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6298 | isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type); |
| 6299 | if (isinstance == -1) { |
| 6300 | return 1; |
| 6301 | } |
| 6302 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6303 | *out = Div; |
| 6304 | return 0; |
| 6305 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6306 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type); |
| 6307 | if (isinstance == -1) { |
| 6308 | return 1; |
| 6309 | } |
| 6310 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6311 | *out = Mod; |
| 6312 | return 0; |
| 6313 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6314 | isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type); |
| 6315 | if (isinstance == -1) { |
| 6316 | return 1; |
| 6317 | } |
| 6318 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6319 | *out = Pow; |
| 6320 | return 0; |
| 6321 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6322 | isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type); |
| 6323 | if (isinstance == -1) { |
| 6324 | return 1; |
| 6325 | } |
| 6326 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6327 | *out = LShift; |
| 6328 | return 0; |
| 6329 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6330 | isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type); |
| 6331 | if (isinstance == -1) { |
| 6332 | return 1; |
| 6333 | } |
| 6334 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6335 | *out = RShift; |
| 6336 | return 0; |
| 6337 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6338 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type); |
| 6339 | if (isinstance == -1) { |
| 6340 | return 1; |
| 6341 | } |
| 6342 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6343 | *out = BitOr; |
| 6344 | return 0; |
| 6345 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6346 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type); |
| 6347 | if (isinstance == -1) { |
| 6348 | return 1; |
| 6349 | } |
| 6350 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6351 | *out = BitXor; |
| 6352 | return 0; |
| 6353 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6354 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type); |
| 6355 | if (isinstance == -1) { |
| 6356 | return 1; |
| 6357 | } |
| 6358 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6359 | *out = BitAnd; |
| 6360 | return 0; |
| 6361 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6362 | isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type); |
| 6363 | if (isinstance == -1) { |
| 6364 | return 1; |
| 6365 | } |
| 6366 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6367 | *out = FloorDiv; |
| 6368 | return 0; |
| 6369 | } |
| 6370 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6371 | 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] | 6372 | return 1; |
| 6373 | } |
| 6374 | |
| 6375 | int |
| 6376 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 6377 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6378 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6379 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6380 | isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); |
| 6381 | if (isinstance == -1) { |
| 6382 | return 1; |
| 6383 | } |
| 6384 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6385 | *out = Invert; |
| 6386 | return 0; |
| 6387 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6388 | isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type); |
| 6389 | if (isinstance == -1) { |
| 6390 | return 1; |
| 6391 | } |
| 6392 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6393 | *out = Not; |
| 6394 | return 0; |
| 6395 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6396 | isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type); |
| 6397 | if (isinstance == -1) { |
| 6398 | return 1; |
| 6399 | } |
| 6400 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6401 | *out = UAdd; |
| 6402 | return 0; |
| 6403 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6404 | isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type); |
| 6405 | if (isinstance == -1) { |
| 6406 | return 1; |
| 6407 | } |
| 6408 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6409 | *out = USub; |
| 6410 | return 0; |
| 6411 | } |
| 6412 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6413 | 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] | 6414 | return 1; |
| 6415 | } |
| 6416 | |
| 6417 | int |
| 6418 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 6419 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6420 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6421 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6422 | isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); |
| 6423 | if (isinstance == -1) { |
| 6424 | return 1; |
| 6425 | } |
| 6426 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6427 | *out = Eq; |
| 6428 | return 0; |
| 6429 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6430 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type); |
| 6431 | if (isinstance == -1) { |
| 6432 | return 1; |
| 6433 | } |
| 6434 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6435 | *out = NotEq; |
| 6436 | return 0; |
| 6437 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6438 | isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type); |
| 6439 | if (isinstance == -1) { |
| 6440 | return 1; |
| 6441 | } |
| 6442 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6443 | *out = Lt; |
| 6444 | return 0; |
| 6445 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6446 | isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type); |
| 6447 | if (isinstance == -1) { |
| 6448 | return 1; |
| 6449 | } |
| 6450 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6451 | *out = LtE; |
| 6452 | return 0; |
| 6453 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6454 | isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type); |
| 6455 | if (isinstance == -1) { |
| 6456 | return 1; |
| 6457 | } |
| 6458 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6459 | *out = Gt; |
| 6460 | return 0; |
| 6461 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6462 | isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type); |
| 6463 | if (isinstance == -1) { |
| 6464 | return 1; |
| 6465 | } |
| 6466 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6467 | *out = GtE; |
| 6468 | return 0; |
| 6469 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6470 | isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type); |
| 6471 | if (isinstance == -1) { |
| 6472 | return 1; |
| 6473 | } |
| 6474 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6475 | *out = Is; |
| 6476 | return 0; |
| 6477 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6478 | isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type); |
| 6479 | if (isinstance == -1) { |
| 6480 | return 1; |
| 6481 | } |
| 6482 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6483 | *out = IsNot; |
| 6484 | return 0; |
| 6485 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6486 | isinstance = PyObject_IsInstance(obj, (PyObject *)In_type); |
| 6487 | if (isinstance == -1) { |
| 6488 | return 1; |
| 6489 | } |
| 6490 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6491 | *out = In; |
| 6492 | return 0; |
| 6493 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6494 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type); |
| 6495 | if (isinstance == -1) { |
| 6496 | return 1; |
| 6497 | } |
| 6498 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6499 | *out = NotIn; |
| 6500 | return 0; |
| 6501 | } |
| 6502 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6503 | 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] | 6504 | return 1; |
| 6505 | } |
| 6506 | |
| 6507 | int |
| 6508 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 6509 | { |
| 6510 | PyObject* tmp = NULL; |
| 6511 | expr_ty target; |
| 6512 | expr_ty iter; |
| 6513 | asdl_seq* ifs; |
| 6514 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6515 | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6516 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6517 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6518 | if (tmp == NULL) goto failed; |
| 6519 | res = obj2ast_expr(tmp, &target, arena); |
| 6520 | if (res != 0) goto failed; |
| 6521 | Py_XDECREF(tmp); |
| 6522 | tmp = NULL; |
| 6523 | } else { |
| 6524 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 6525 | return 1; |
| 6526 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6527 | if (_PyObject_HasAttrId(obj, &PyId_iter)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6528 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6529 | tmp = _PyObject_GetAttrId(obj, &PyId_iter); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6530 | if (tmp == NULL) goto failed; |
| 6531 | res = obj2ast_expr(tmp, &iter, arena); |
| 6532 | if (res != 0) goto failed; |
| 6533 | Py_XDECREF(tmp); |
| 6534 | tmp = NULL; |
| 6535 | } else { |
| 6536 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 6537 | return 1; |
| 6538 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6539 | if (_PyObject_HasAttrId(obj, &PyId_ifs)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6540 | int res; |
| 6541 | Py_ssize_t len; |
| 6542 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6543 | tmp = _PyObject_GetAttrId(obj, &PyId_ifs); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6544 | if (tmp == NULL) goto failed; |
| 6545 | if (!PyList_Check(tmp)) { |
| 6546 | PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6547 | goto failed; |
| 6548 | } |
| 6549 | len = PyList_GET_SIZE(tmp); |
| 6550 | ifs = asdl_seq_new(len, arena); |
| 6551 | if (ifs == NULL) goto failed; |
| 6552 | for (i = 0; i < len; i++) { |
| 6553 | expr_ty value; |
| 6554 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6555 | if (res != 0) goto failed; |
| 6556 | asdl_seq_SET(ifs, i, value); |
| 6557 | } |
| 6558 | Py_XDECREF(tmp); |
| 6559 | tmp = NULL; |
| 6560 | } else { |
| 6561 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 6562 | return 1; |
| 6563 | } |
| 6564 | *out = comprehension(target, iter, ifs, arena); |
| 6565 | return 0; |
| 6566 | failed: |
| 6567 | Py_XDECREF(tmp); |
| 6568 | return 1; |
| 6569 | } |
| 6570 | |
| 6571 | int |
| 6572 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 6573 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6574 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6575 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 6576 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6577 | int lineno; |
| 6578 | int col_offset; |
| 6579 | |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6580 | if (obj == Py_None) { |
| 6581 | *out = NULL; |
| 6582 | return 0; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6583 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6584 | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6585 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6586 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6587 | if (tmp == NULL) goto failed; |
| 6588 | res = obj2ast_int(tmp, &lineno, arena); |
| 6589 | if (res != 0) goto failed; |
| 6590 | Py_XDECREF(tmp); |
| 6591 | tmp = NULL; |
| 6592 | } else { |
| 6593 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 6594 | return 1; |
| 6595 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6596 | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6597 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6598 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6599 | if (tmp == NULL) goto failed; |
| 6600 | res = obj2ast_int(tmp, &col_offset, arena); |
| 6601 | if (res != 0) goto failed; |
| 6602 | Py_XDECREF(tmp); |
| 6603 | tmp = NULL; |
| 6604 | } else { |
| 6605 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 6606 | return 1; |
| 6607 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6608 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type); |
| 6609 | if (isinstance == -1) { |
| 6610 | return 1; |
| 6611 | } |
| 6612 | if (isinstance) { |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6613 | expr_ty type; |
| 6614 | identifier name; |
| 6615 | asdl_seq* body; |
| 6616 | |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 6617 | if (exists_not_none(obj, &PyId_type)) { |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6618 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6619 | tmp = _PyObject_GetAttrId(obj, &PyId_type); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6620 | if (tmp == NULL) goto failed; |
| 6621 | res = obj2ast_expr(tmp, &type, arena); |
| 6622 | if (res != 0) goto failed; |
| 6623 | Py_XDECREF(tmp); |
| 6624 | tmp = NULL; |
| 6625 | } else { |
| 6626 | type = NULL; |
| 6627 | } |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 6628 | if (exists_not_none(obj, &PyId_name)) { |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6629 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6630 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6631 | if (tmp == NULL) goto failed; |
| 6632 | res = obj2ast_identifier(tmp, &name, arena); |
| 6633 | if (res != 0) goto failed; |
| 6634 | Py_XDECREF(tmp); |
| 6635 | tmp = NULL; |
| 6636 | } else { |
| 6637 | name = NULL; |
| 6638 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6639 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6640 | int res; |
| 6641 | Py_ssize_t len; |
| 6642 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6643 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6644 | if (tmp == NULL) goto failed; |
| 6645 | if (!PyList_Check(tmp)) { |
| 6646 | PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6647 | goto failed; |
| 6648 | } |
| 6649 | len = PyList_GET_SIZE(tmp); |
| 6650 | body = asdl_seq_new(len, arena); |
| 6651 | if (body == NULL) goto failed; |
| 6652 | for (i = 0; i < len; i++) { |
| 6653 | stmt_ty value; |
| 6654 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6655 | if (res != 0) goto failed; |
| 6656 | asdl_seq_SET(body, i, value); |
| 6657 | } |
| 6658 | Py_XDECREF(tmp); |
| 6659 | tmp = NULL; |
| 6660 | } else { |
| 6661 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 6662 | return 1; |
| 6663 | } |
| 6664 | *out = ExceptHandler(type, name, body, lineno, col_offset, |
| 6665 | arena); |
| 6666 | if (*out == NULL) goto failed; |
| 6667 | return 0; |
| 6668 | } |
| 6669 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6670 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
| 6671 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 6672 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6673 | return 1; |
| 6674 | } |
| 6675 | |
| 6676 | int |
| 6677 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 6678 | { |
| 6679 | PyObject* tmp = NULL; |
| 6680 | asdl_seq* args; |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 6681 | arg_ty vararg; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6682 | asdl_seq* kwonlyargs; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6683 | asdl_seq* kw_defaults; |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 6684 | arg_ty kwarg; |
| 6685 | asdl_seq* defaults; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6686 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6687 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6688 | int res; |
| 6689 | Py_ssize_t len; |
| 6690 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6691 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6692 | if (tmp == NULL) goto failed; |
| 6693 | if (!PyList_Check(tmp)) { |
| 6694 | PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6695 | goto failed; |
| 6696 | } |
| 6697 | len = PyList_GET_SIZE(tmp); |
| 6698 | args = asdl_seq_new(len, arena); |
| 6699 | if (args == NULL) goto failed; |
| 6700 | for (i = 0; i < len; i++) { |
| 6701 | arg_ty value; |
| 6702 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6703 | if (res != 0) goto failed; |
| 6704 | asdl_seq_SET(args, i, value); |
| 6705 | } |
| 6706 | Py_XDECREF(tmp); |
| 6707 | tmp = NULL; |
| 6708 | } else { |
| 6709 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 6710 | return 1; |
| 6711 | } |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 6712 | if (exists_not_none(obj, &PyId_vararg)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6713 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6714 | tmp = _PyObject_GetAttrId(obj, &PyId_vararg); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6715 | if (tmp == NULL) goto failed; |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 6716 | res = obj2ast_arg(tmp, &vararg, arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6717 | if (res != 0) goto failed; |
| 6718 | Py_XDECREF(tmp); |
| 6719 | tmp = NULL; |
| 6720 | } else { |
| 6721 | vararg = NULL; |
| 6722 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6723 | if (_PyObject_HasAttrId(obj, &PyId_kwonlyargs)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6724 | int res; |
| 6725 | Py_ssize_t len; |
| 6726 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6727 | tmp = _PyObject_GetAttrId(obj, &PyId_kwonlyargs); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6728 | if (tmp == NULL) goto failed; |
| 6729 | if (!PyList_Check(tmp)) { |
| 6730 | PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6731 | goto failed; |
| 6732 | } |
| 6733 | len = PyList_GET_SIZE(tmp); |
| 6734 | kwonlyargs = asdl_seq_new(len, arena); |
| 6735 | if (kwonlyargs == NULL) goto failed; |
| 6736 | for (i = 0; i < len; i++) { |
| 6737 | arg_ty value; |
| 6738 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6739 | if (res != 0) goto failed; |
| 6740 | asdl_seq_SET(kwonlyargs, i, value); |
| 6741 | } |
| 6742 | Py_XDECREF(tmp); |
| 6743 | tmp = NULL; |
| 6744 | } else { |
| 6745 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 6746 | return 1; |
| 6747 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6748 | if (_PyObject_HasAttrId(obj, &PyId_kw_defaults)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6749 | int res; |
| 6750 | Py_ssize_t len; |
| 6751 | Py_ssize_t i; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6752 | tmp = _PyObject_GetAttrId(obj, &PyId_kw_defaults); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6753 | if (tmp == NULL) goto failed; |
| 6754 | if (!PyList_Check(tmp)) { |
| 6755 | PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6756 | goto failed; |
| 6757 | } |
| 6758 | len = PyList_GET_SIZE(tmp); |
| 6759 | kw_defaults = asdl_seq_new(len, arena); |
| 6760 | if (kw_defaults == NULL) goto failed; |
| 6761 | for (i = 0; i < len; i++) { |
| 6762 | expr_ty value; |
| 6763 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6764 | if (res != 0) goto failed; |
| 6765 | asdl_seq_SET(kw_defaults, i, value); |
| 6766 | } |
| 6767 | Py_XDECREF(tmp); |
| 6768 | tmp = NULL; |
| 6769 | } else { |
| 6770 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 6771 | return 1; |
| 6772 | } |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 6773 | if (exists_not_none(obj, &PyId_kwarg)) { |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 6774 | int res; |
| 6775 | tmp = _PyObject_GetAttrId(obj, &PyId_kwarg); |
| 6776 | if (tmp == NULL) goto failed; |
| 6777 | res = obj2ast_arg(tmp, &kwarg, arena); |
| 6778 | if (res != 0) goto failed; |
| 6779 | Py_XDECREF(tmp); |
| 6780 | tmp = NULL; |
| 6781 | } else { |
| 6782 | kwarg = NULL; |
| 6783 | } |
| 6784 | if (_PyObject_HasAttrId(obj, &PyId_defaults)) { |
| 6785 | int res; |
| 6786 | Py_ssize_t len; |
| 6787 | Py_ssize_t i; |
| 6788 | tmp = _PyObject_GetAttrId(obj, &PyId_defaults); |
| 6789 | if (tmp == NULL) goto failed; |
| 6790 | if (!PyList_Check(tmp)) { |
| 6791 | PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6792 | goto failed; |
| 6793 | } |
| 6794 | len = PyList_GET_SIZE(tmp); |
| 6795 | defaults = asdl_seq_new(len, arena); |
| 6796 | if (defaults == NULL) goto failed; |
| 6797 | for (i = 0; i < len; i++) { |
| 6798 | expr_ty value; |
| 6799 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6800 | if (res != 0) goto failed; |
| 6801 | asdl_seq_SET(defaults, i, value); |
| 6802 | } |
| 6803 | Py_XDECREF(tmp); |
| 6804 | tmp = NULL; |
| 6805 | } else { |
| 6806 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 6807 | return 1; |
| 6808 | } |
| 6809 | *out = arguments(args, vararg, kwonlyargs, kw_defaults, kwarg, |
| 6810 | defaults, arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6811 | return 0; |
| 6812 | failed: |
| 6813 | Py_XDECREF(tmp); |
| 6814 | return 1; |
| 6815 | } |
| 6816 | |
| 6817 | int |
| 6818 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 6819 | { |
| 6820 | PyObject* tmp = NULL; |
| 6821 | identifier arg; |
| 6822 | expr_ty annotation; |
| 6823 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6824 | if (_PyObject_HasAttrId(obj, &PyId_arg)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6825 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6826 | tmp = _PyObject_GetAttrId(obj, &PyId_arg); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6827 | if (tmp == NULL) goto failed; |
| 6828 | res = obj2ast_identifier(tmp, &arg, arena); |
| 6829 | if (res != 0) goto failed; |
| 6830 | Py_XDECREF(tmp); |
| 6831 | tmp = NULL; |
| 6832 | } else { |
| 6833 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
| 6834 | return 1; |
| 6835 | } |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 6836 | if (exists_not_none(obj, &PyId_annotation)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6837 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6838 | tmp = _PyObject_GetAttrId(obj, &PyId_annotation); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6839 | if (tmp == NULL) goto failed; |
| 6840 | res = obj2ast_expr(tmp, &annotation, arena); |
| 6841 | if (res != 0) goto failed; |
| 6842 | Py_XDECREF(tmp); |
| 6843 | tmp = NULL; |
| 6844 | } else { |
| 6845 | annotation = NULL; |
| 6846 | } |
| 6847 | *out = arg(arg, annotation, arena); |
| 6848 | return 0; |
| 6849 | failed: |
| 6850 | Py_XDECREF(tmp); |
| 6851 | return 1; |
| 6852 | } |
| 6853 | |
| 6854 | int |
| 6855 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 6856 | { |
| 6857 | PyObject* tmp = NULL; |
| 6858 | identifier arg; |
| 6859 | expr_ty value; |
| 6860 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6861 | if (_PyObject_HasAttrId(obj, &PyId_arg)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6862 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6863 | tmp = _PyObject_GetAttrId(obj, &PyId_arg); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6864 | if (tmp == NULL) goto failed; |
| 6865 | res = obj2ast_identifier(tmp, &arg, arena); |
| 6866 | if (res != 0) goto failed; |
| 6867 | Py_XDECREF(tmp); |
| 6868 | tmp = NULL; |
| 6869 | } else { |
| 6870 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from keyword"); |
| 6871 | return 1; |
| 6872 | } |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6873 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6874 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6875 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6876 | if (tmp == NULL) goto failed; |
| 6877 | res = obj2ast_expr(tmp, &value, arena); |
| 6878 | if (res != 0) goto failed; |
| 6879 | Py_XDECREF(tmp); |
| 6880 | tmp = NULL; |
| 6881 | } else { |
| 6882 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 6883 | return 1; |
| 6884 | } |
| 6885 | *out = keyword(arg, value, arena); |
| 6886 | return 0; |
| 6887 | failed: |
| 6888 | Py_XDECREF(tmp); |
| 6889 | return 1; |
| 6890 | } |
| 6891 | |
| 6892 | int |
| 6893 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 6894 | { |
| 6895 | PyObject* tmp = NULL; |
| 6896 | identifier name; |
| 6897 | identifier asname; |
| 6898 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6899 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6900 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6901 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6902 | if (tmp == NULL) goto failed; |
| 6903 | res = obj2ast_identifier(tmp, &name, arena); |
| 6904 | if (res != 0) goto failed; |
| 6905 | Py_XDECREF(tmp); |
| 6906 | tmp = NULL; |
| 6907 | } else { |
| 6908 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 6909 | return 1; |
| 6910 | } |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 6911 | if (exists_not_none(obj, &PyId_asname)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6912 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6913 | tmp = _PyObject_GetAttrId(obj, &PyId_asname); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6914 | if (tmp == NULL) goto failed; |
| 6915 | res = obj2ast_identifier(tmp, &asname, arena); |
| 6916 | if (res != 0) goto failed; |
| 6917 | Py_XDECREF(tmp); |
| 6918 | tmp = NULL; |
| 6919 | } else { |
| 6920 | asname = NULL; |
| 6921 | } |
| 6922 | *out = alias(name, asname, arena); |
| 6923 | return 0; |
| 6924 | failed: |
| 6925 | Py_XDECREF(tmp); |
| 6926 | return 1; |
| 6927 | } |
| 6928 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6929 | int |
| 6930 | obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) |
| 6931 | { |
| 6932 | PyObject* tmp = NULL; |
| 6933 | expr_ty context_expr; |
| 6934 | expr_ty optional_vars; |
| 6935 | |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6936 | if (_PyObject_HasAttrId(obj, &PyId_context_expr)) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6937 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6938 | tmp = _PyObject_GetAttrId(obj, &PyId_context_expr); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6939 | if (tmp == NULL) goto failed; |
| 6940 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 6941 | if (res != 0) goto failed; |
| 6942 | Py_XDECREF(tmp); |
| 6943 | tmp = NULL; |
| 6944 | } else { |
| 6945 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); |
| 6946 | return 1; |
| 6947 | } |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 6948 | if (exists_not_none(obj, &PyId_optional_vars)) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6949 | int res; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 6950 | tmp = _PyObject_GetAttrId(obj, &PyId_optional_vars); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6951 | if (tmp == NULL) goto failed; |
| 6952 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 6953 | if (res != 0) goto failed; |
| 6954 | Py_XDECREF(tmp); |
| 6955 | tmp = NULL; |
| 6956 | } else { |
| 6957 | optional_vars = NULL; |
| 6958 | } |
| 6959 | *out = withitem(context_expr, optional_vars, arena); |
| 6960 | return 0; |
| 6961 | failed: |
| 6962 | Py_XDECREF(tmp); |
| 6963 | return 1; |
| 6964 | } |
| 6965 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6966 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6967 | static struct PyModuleDef _astmodule = { |
| 6968 | PyModuleDef_HEAD_INIT, "_ast" |
| 6969 | }; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6970 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6971 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6972 | { |
| 6973 | PyObject *m, *d; |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6974 | if (!init_types()) return NULL; |
| 6975 | m = PyModule_Create(&_astmodule); |
| 6976 | if (!m) return NULL; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6977 | d = PyModule_GetDict(m); |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6978 | if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return |
| 6979 | NULL; |
Charles-Francois Natali | 74ca886 | 2013-05-20 19:13:19 +0200 | [diff] [blame] | 6980 | if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6981 | return NULL; |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6982 | if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return |
| 6983 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6984 | if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6985 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6986 | if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6987 | < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6988 | if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6989 | 0) return NULL; |
| 6990 | if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return |
| 6991 | NULL; |
| 6992 | if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return |
| 6993 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6994 | if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6995 | < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6996 | if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6997 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6998 | if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6999 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7000 | if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7001 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7002 | if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7003 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7004 | if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7005 | 0) return NULL; |
| 7006 | if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return |
| 7007 | NULL; |
| 7008 | if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return |
| 7009 | NULL; |
| 7010 | if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return NULL; |
| 7011 | if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return |
| 7012 | NULL; |
| 7013 | if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return |
| 7014 | NULL; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 7015 | if (PyDict_SetItemString(d, "Try", (PyObject*)Try_type) < 0) return |
| 7016 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7017 | if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7018 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7019 | if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7020 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7021 | if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7022 | 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7023 | if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7024 | return NULL; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 7025 | if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7026 | return NULL; |
| 7027 | if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return |
| 7028 | NULL; |
| 7029 | if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return |
| 7030 | NULL; |
| 7031 | if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return |
| 7032 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7033 | if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7034 | return NULL; |
| 7035 | if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return |
| 7036 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7037 | if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7038 | return NULL; |
| 7039 | if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return |
| 7040 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7041 | if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7042 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7043 | if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7044 | return NULL; |
| 7045 | if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return |
| 7046 | NULL; |
| 7047 | if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return |
| 7048 | NULL; |
| 7049 | if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return |
| 7050 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7051 | if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7052 | return NULL; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 7053 | if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7054 | return NULL; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 7055 | if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7056 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7057 | if (PyDict_SetItemString(d, "GeneratorExp", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7058 | (PyObject*)GeneratorExp_type) < 0) return NULL; |
| 7059 | if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return |
| 7060 | NULL; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 7061 | if (PyDict_SetItemString(d, "YieldFrom", (PyObject*)YieldFrom_type) < |
| 7062 | 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7063 | if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7064 | return NULL; |
| 7065 | if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return |
| 7066 | NULL; |
| 7067 | if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return |
| 7068 | NULL; |
| 7069 | if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return |
| 7070 | NULL; |
| 7071 | if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return |
| 7072 | NULL; |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 7073 | if (PyDict_SetItemString(d, "NameConstant", |
| 7074 | (PyObject*)NameConstant_type) < 0) return NULL; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 7075 | if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7076 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7077 | if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7078 | 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7079 | if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7080 | 0) return NULL; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 7081 | if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7082 | return NULL; |
| 7083 | if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return |
| 7084 | NULL; |
| 7085 | if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return |
| 7086 | NULL; |
| 7087 | if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return |
| 7088 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7089 | if (PyDict_SetItemString(d, "expr_context", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7090 | (PyObject*)expr_context_type) < 0) return NULL; |
| 7091 | if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return |
| 7092 | NULL; |
| 7093 | if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return |
| 7094 | NULL; |
| 7095 | if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return |
| 7096 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7097 | if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7098 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7099 | if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7100 | return NULL; |
| 7101 | if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return |
| 7102 | NULL; |
| 7103 | if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return |
| 7104 | NULL; |
| 7105 | if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return |
| 7106 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7107 | if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7108 | return NULL; |
| 7109 | if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return |
| 7110 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7111 | if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7112 | return NULL; |
| 7113 | if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return |
| 7114 | NULL; |
| 7115 | if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7116 | if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7117 | return NULL; |
| 7118 | if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return |
| 7119 | NULL; |
| 7120 | if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return |
| 7121 | NULL; |
| 7122 | if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return |
| 7123 | NULL; |
| 7124 | if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return |
| 7125 | NULL; |
| 7126 | if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return |
| 7127 | NULL; |
| 7128 | if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return |
| 7129 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7130 | if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7131 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7132 | if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7133 | return NULL; |
| 7134 | if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return |
| 7135 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7136 | if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7137 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7138 | if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7139 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7140 | if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7141 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7142 | if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7143 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7144 | if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7145 | return NULL; |
| 7146 | if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return |
| 7147 | NULL; |
| 7148 | if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return |
| 7149 | NULL; |
| 7150 | if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return |
| 7151 | NULL; |
| 7152 | if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return |
| 7153 | NULL; |
| 7154 | if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return NULL; |
| 7155 | if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return |
| 7156 | NULL; |
| 7157 | if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return NULL; |
| 7158 | if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return |
| 7159 | NULL; |
| 7160 | if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return NULL; |
| 7161 | if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return |
| 7162 | NULL; |
| 7163 | if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return NULL; |
| 7164 | if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return |
| 7165 | NULL; |
| 7166 | if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return NULL; |
| 7167 | if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return |
| 7168 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7169 | if (PyDict_SetItemString(d, "comprehension", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7170 | (PyObject*)comprehension_type) < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7171 | if (PyDict_SetItemString(d, "excepthandler", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7172 | (PyObject*)excepthandler_type) < 0) return NULL; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 7173 | if (PyDict_SetItemString(d, "ExceptHandler", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7174 | (PyObject*)ExceptHandler_type) < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7175 | if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7176 | 0) return NULL; |
| 7177 | if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return |
| 7178 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7179 | if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7180 | return NULL; |
| 7181 | if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return |
| 7182 | NULL; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 7183 | if (PyDict_SetItemString(d, "withitem", (PyObject*)withitem_type) < 0) |
| 7184 | return NULL; |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7185 | return m; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 7186 | } |
| 7187 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 7188 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 7189 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 7190 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 7191 | init_types(); |
| 7192 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 7193 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 7194 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7195 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 7196 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7197 | { |
| 7198 | mod_ty res; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7199 | PyObject *req_type[] = {(PyObject*)Module_type, (PyObject*)Expression_type, |
| 7200 | (PyObject*)Interactive_type}; |
| 7201 | char *req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 7202 | int isinstance; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7203 | assert(0 <= mode && mode <= 2); |
| 7204 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7205 | init_types(); |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7206 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 7207 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 7208 | if (isinstance == -1) |
| 7209 | return NULL; |
| 7210 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7211 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
| 7212 | req_name[mode], Py_TYPE(ast)->tp_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7213 | return NULL; |
| 7214 | } |
| 7215 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 7216 | return NULL; |
| 7217 | else |
| 7218 | return res; |
| 7219 | } |
| 7220 | |
| 7221 | int PyAST_Check(PyObject* obj) |
| 7222 | { |
| 7223 | init_types(); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 7224 | return PyObject_IsInstance(obj, (PyObject*)&AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7225 | } |
| 7226 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 7227 | |