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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 14 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 15 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 16 | static PyTypeObject *Interactive_type; |
| 17 | static char *Interactive_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 18 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 19 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 20 | static PyTypeObject *Expression_type; |
| 21 | static char *Expression_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 22 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 23 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 24 | static PyTypeObject *Suite_type; |
| 25 | static char *Suite_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 26 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 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[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 32 | "lineno", |
| 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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 42 | "name", |
| 43 | "args", |
| 44 | "body", |
| 45 | "decorator_list", |
| 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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 54 | "name", |
| 55 | "bases", |
| 56 | "keywords", |
| 57 | "starargs", |
| 58 | "kwargs", |
| 59 | "body", |
| 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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 65 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 70 | "targets", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 71 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 72 | static PyTypeObject *Assign_type; |
| 73 | static char *Assign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 74 | "targets", |
| 75 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 81 | "target", |
| 82 | "op", |
| 83 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 89 | "target", |
| 90 | "iter", |
| 91 | "body", |
| 92 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 97 | "test", |
| 98 | "body", |
| 99 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 100 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 101 | static PyTypeObject *If_type; |
| 102 | static char *If_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 103 | "test", |
| 104 | "body", |
| 105 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 110 | "items", |
| 111 | "body", |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 124 | "body", |
| 125 | "handlers", |
| 126 | "orelse", |
| 127 | "finalbody", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 132 | "test", |
| 133 | "msg", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 138 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 144 | "module", |
| 145 | "names", |
| 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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 150 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 151 | }; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 152 | static PyTypeObject *Nonlocal_type; |
| 153 | static char *Nonlocal_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 154 | "names", |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 155 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 156 | static PyTypeObject *Expr_type; |
| 157 | static char *Expr_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 158 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 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[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 165 | "lineno", |
| 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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 172 | "op", |
| 173 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 179 | "left", |
| 180 | "op", |
| 181 | "right", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 186 | "op", |
| 187 | "operand", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 188 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 189 | static PyTypeObject *Lambda_type; |
| 190 | static char *Lambda_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 191 | "args", |
| 192 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 193 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 194 | static PyTypeObject *IfExp_type; |
| 195 | static char *IfExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 196 | "test", |
| 197 | "body", |
| 198 | "orelse", |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 203 | "keys", |
| 204 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 209 | "elts", |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 215 | "elt", |
| 216 | "generators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 217 | }; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 218 | static PyTypeObject *SetComp_type; |
| 219 | static char *SetComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 220 | "elt", |
| 221 | "generators", |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 226 | "key", |
| 227 | "value", |
| 228 | "generators", |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 229 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 230 | static PyTypeObject *GeneratorExp_type; |
| 231 | static char *GeneratorExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 232 | "elt", |
| 233 | "generators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 234 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 235 | static PyTypeObject *Yield_type; |
| 236 | static char *Yield_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 237 | "value", |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 238 | }; |
| 239 | static PyTypeObject *YieldFrom_type; |
| 240 | static char *YieldFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 241 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 247 | "left", |
| 248 | "ops", |
| 249 | "comparators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 254 | "func", |
| 255 | "args", |
| 256 | "keywords", |
| 257 | "starargs", |
| 258 | "kwargs", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 263 | "n", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 268 | "s", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 269 | }; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 270 | static PyTypeObject *Bytes_type; |
| 271 | static char *Bytes_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 272 | "s", |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 273 | }; |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 274 | static PyTypeObject *NameConstant_type; |
| 275 | static char *NameConstant_fields[]={ |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 276 | "value", |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 283 | "value", |
| 284 | "attr", |
| 285 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 290 | "value", |
| 291 | "slice", |
| 292 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 293 | }; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 294 | static PyTypeObject *Starred_type; |
| 295 | static char *Starred_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 296 | "value", |
| 297 | "ctx", |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 302 | "id", |
| 303 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 304 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 305 | static PyTypeObject *List_type; |
| 306 | static char *List_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 307 | "elts", |
| 308 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 309 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 310 | static PyTypeObject *Tuple_type; |
| 311 | static char *Tuple_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 312 | "elts", |
| 313 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 332 | "lower", |
| 333 | "upper", |
| 334 | "step", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 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[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 339 | "dims", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 340 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 341 | static PyTypeObject *Index_type; |
| 342 | static char *Index_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 343 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 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, |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 352 | *MatMult_singleton, *Div_singleton, *Mod_singleton, *Pow_singleton, |
| 353 | *LShift_singleton, *RShift_singleton, *BitOr_singleton, *BitXor_singleton, |
| 354 | *BitAnd_singleton, *FloorDiv_singleton; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 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; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 359 | static PyTypeObject *MatMult_type; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 360 | static PyTypeObject *Div_type; |
| 361 | static PyTypeObject *Mod_type; |
| 362 | static PyTypeObject *Pow_type; |
| 363 | static PyTypeObject *LShift_type; |
| 364 | static PyTypeObject *RShift_type; |
| 365 | static PyTypeObject *BitOr_type; |
| 366 | static PyTypeObject *BitXor_type; |
| 367 | static PyTypeObject *BitAnd_type; |
| 368 | static PyTypeObject *FloorDiv_type; |
| 369 | static PyTypeObject *unaryop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 370 | static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton, |
| 371 | *USub_singleton; |
| 372 | static PyObject* ast2obj_unaryop(unaryop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 373 | static PyTypeObject *Invert_type; |
| 374 | static PyTypeObject *Not_type; |
| 375 | static PyTypeObject *UAdd_type; |
| 376 | static PyTypeObject *USub_type; |
| 377 | static PyTypeObject *cmpop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 378 | static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton, |
| 379 | *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton, |
| 380 | *NotIn_singleton; |
| 381 | static PyObject* ast2obj_cmpop(cmpop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 382 | static PyTypeObject *Eq_type; |
| 383 | static PyTypeObject *NotEq_type; |
| 384 | static PyTypeObject *Lt_type; |
| 385 | static PyTypeObject *LtE_type; |
| 386 | static PyTypeObject *Gt_type; |
| 387 | static PyTypeObject *GtE_type; |
| 388 | static PyTypeObject *Is_type; |
| 389 | static PyTypeObject *IsNot_type; |
| 390 | static PyTypeObject *In_type; |
| 391 | static PyTypeObject *NotIn_type; |
| 392 | static PyTypeObject *comprehension_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 393 | static PyObject* ast2obj_comprehension(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 394 | _Py_IDENTIFIER(ifs); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 395 | static char *comprehension_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 396 | "target", |
| 397 | "iter", |
| 398 | "ifs", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 399 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 400 | static PyTypeObject *excepthandler_type; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 401 | static char *excepthandler_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 402 | "lineno", |
| 403 | "col_offset", |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 404 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 405 | static PyObject* ast2obj_excepthandler(void*); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 406 | static PyTypeObject *ExceptHandler_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 407 | _Py_IDENTIFIER(type); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 408 | static char *ExceptHandler_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 409 | "type", |
| 410 | "name", |
| 411 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 412 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 413 | static PyTypeObject *arguments_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 414 | static PyObject* ast2obj_arguments(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 415 | _Py_IDENTIFIER(vararg); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 416 | _Py_IDENTIFIER(kwonlyargs); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 417 | _Py_IDENTIFIER(kw_defaults); |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 418 | _Py_IDENTIFIER(kwarg); |
| 419 | _Py_IDENTIFIER(defaults); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 420 | static char *arguments_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 421 | "args", |
| 422 | "vararg", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 423 | "kwonlyargs", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 424 | "kw_defaults", |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 425 | "kwarg", |
| 426 | "defaults", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 427 | }; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 428 | static PyTypeObject *arg_type; |
| 429 | static PyObject* ast2obj_arg(void*); |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 430 | static char *arg_attributes[] = { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 431 | "lineno", |
| 432 | "col_offset", |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 433 | }; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 434 | _Py_IDENTIFIER(arg); |
| 435 | _Py_IDENTIFIER(annotation); |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 436 | static char *arg_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 437 | "arg", |
| 438 | "annotation", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 439 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 440 | static PyTypeObject *keyword_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 441 | static PyObject* ast2obj_keyword(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 442 | static char *keyword_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 443 | "arg", |
| 444 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 445 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 446 | static PyTypeObject *alias_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 447 | static PyObject* ast2obj_alias(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 448 | _Py_IDENTIFIER(asname); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 449 | static char *alias_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 450 | "name", |
| 451 | "asname", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 452 | }; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 453 | static PyTypeObject *withitem_type; |
| 454 | static PyObject* ast2obj_withitem(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 455 | _Py_IDENTIFIER(context_expr); |
| 456 | _Py_IDENTIFIER(optional_vars); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 457 | static char *withitem_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 458 | "context_expr", |
| 459 | "optional_vars", |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 460 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 461 | |
| 462 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 463 | typedef struct { |
Victor Stinner | 45e50de | 2012-03-13 01:17:31 +0100 | [diff] [blame] | 464 | PyObject_HEAD |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 465 | PyObject *dict; |
| 466 | } AST_object; |
| 467 | |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 468 | static void |
| 469 | ast_dealloc(AST_object *self) |
| 470 | { |
| 471 | Py_CLEAR(self->dict); |
Antoine Pitrou | 5075074 | 2012-07-08 12:43:32 +0200 | [diff] [blame] | 472 | Py_TYPE(self)->tp_free(self); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 473 | } |
| 474 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 475 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 476 | ast_traverse(AST_object *self, visitproc visit, void *arg) |
| 477 | { |
| 478 | Py_VISIT(self->dict); |
| 479 | return 0; |
| 480 | } |
| 481 | |
| 482 | static void |
| 483 | ast_clear(AST_object *self) |
| 484 | { |
| 485 | Py_CLEAR(self->dict); |
| 486 | } |
| 487 | |
| 488 | static int |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 489 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 490 | { |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 491 | _Py_IDENTIFIER(_fields); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 492 | Py_ssize_t i, numfields = 0; |
| 493 | int res = -1; |
| 494 | PyObject *key, *value, *fields; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 495 | fields = _PyObject_GetAttrId((PyObject*)Py_TYPE(self), &PyId__fields); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 496 | if (!fields) |
| 497 | PyErr_Clear(); |
| 498 | if (fields) { |
| 499 | numfields = PySequence_Size(fields); |
| 500 | if (numfields == -1) |
| 501 | goto cleanup; |
| 502 | } |
| 503 | res = 0; /* if no error occurs, this stays 0 to the end */ |
| 504 | if (PyTuple_GET_SIZE(args) > 0) { |
| 505 | if (numfields != PyTuple_GET_SIZE(args)) { |
| 506 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes %s" |
Amaury Forgeot d'Arc | 245c70b | 2008-09-10 22:24:24 +0000 | [diff] [blame] | 507 | "%zd positional argument%s", |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 508 | Py_TYPE(self)->tp_name, |
| 509 | numfields == 0 ? "" : "either 0 or ", |
| 510 | numfields, numfields == 1 ? "" : "s"); |
| 511 | res = -1; |
| 512 | goto cleanup; |
| 513 | } |
| 514 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
| 515 | /* cannot be reached when fields is NULL */ |
| 516 | PyObject *name = PySequence_GetItem(fields, i); |
| 517 | if (!name) { |
| 518 | res = -1; |
| 519 | goto cleanup; |
| 520 | } |
| 521 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
| 522 | Py_DECREF(name); |
| 523 | if (res < 0) |
| 524 | goto cleanup; |
| 525 | } |
| 526 | } |
| 527 | if (kw) { |
| 528 | i = 0; /* needed by PyDict_Next */ |
| 529 | while (PyDict_Next(kw, &i, &key, &value)) { |
| 530 | res = PyObject_SetAttr(self, key, value); |
| 531 | if (res < 0) |
| 532 | goto cleanup; |
| 533 | } |
| 534 | } |
| 535 | cleanup: |
| 536 | Py_XDECREF(fields); |
| 537 | return res; |
| 538 | } |
| 539 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 540 | /* Pickling support */ |
| 541 | static PyObject * |
| 542 | ast_type_reduce(PyObject *self, PyObject *unused) |
| 543 | { |
| 544 | PyObject *res; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 545 | _Py_IDENTIFIER(__dict__); |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 546 | PyObject *dict = _PyObject_GetAttrId(self, &PyId___dict__); |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 547 | if (dict == NULL) { |
| 548 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) |
| 549 | PyErr_Clear(); |
| 550 | else |
| 551 | return NULL; |
| 552 | } |
| 553 | if (dict) { |
| 554 | res = Py_BuildValue("O()O", Py_TYPE(self), dict); |
| 555 | Py_DECREF(dict); |
| 556 | return res; |
| 557 | } |
| 558 | return Py_BuildValue("O()", Py_TYPE(self)); |
| 559 | } |
| 560 | |
| 561 | static PyMethodDef ast_type_methods[] = { |
| 562 | {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, |
| 563 | {NULL} |
| 564 | }; |
| 565 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 566 | static PyGetSetDef ast_type_getsets[] = { |
| 567 | {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict}, |
| 568 | {NULL} |
| 569 | }; |
| 570 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 571 | static PyTypeObject AST_type = { |
| 572 | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 573 | "_ast.AST", |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 574 | sizeof(AST_object), |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 575 | 0, |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 576 | (destructor)ast_dealloc, /* tp_dealloc */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 577 | 0, /* tp_print */ |
| 578 | 0, /* tp_getattr */ |
| 579 | 0, /* tp_setattr */ |
Mark Dickinson | e94c679 | 2009-02-02 20:36:42 +0000 | [diff] [blame] | 580 | 0, /* tp_reserved */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 581 | 0, /* tp_repr */ |
| 582 | 0, /* tp_as_number */ |
| 583 | 0, /* tp_as_sequence */ |
| 584 | 0, /* tp_as_mapping */ |
| 585 | 0, /* tp_hash */ |
| 586 | 0, /* tp_call */ |
| 587 | 0, /* tp_str */ |
| 588 | PyObject_GenericGetAttr, /* tp_getattro */ |
| 589 | PyObject_GenericSetAttr, /* tp_setattro */ |
| 590 | 0, /* tp_as_buffer */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 591 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 592 | 0, /* tp_doc */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 593 | (traverseproc)ast_traverse, /* tp_traverse */ |
| 594 | (inquiry)ast_clear, /* tp_clear */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 595 | 0, /* tp_richcompare */ |
| 596 | 0, /* tp_weaklistoffset */ |
| 597 | 0, /* tp_iter */ |
| 598 | 0, /* tp_iternext */ |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 599 | ast_type_methods, /* tp_methods */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 600 | 0, /* tp_members */ |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 601 | ast_type_getsets, /* tp_getset */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 602 | 0, /* tp_base */ |
| 603 | 0, /* tp_dict */ |
| 604 | 0, /* tp_descr_get */ |
| 605 | 0, /* tp_descr_set */ |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 606 | offsetof(AST_object, dict),/* tp_dictoffset */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 607 | (initproc)ast_type_init, /* tp_init */ |
| 608 | PyType_GenericAlloc, /* tp_alloc */ |
| 609 | PyType_GenericNew, /* tp_new */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 610 | PyObject_GC_Del, /* tp_free */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 611 | }; |
| 612 | |
| 613 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 614 | static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields) |
| 615 | { |
| 616 | PyObject *fnames, *result; |
| 617 | int i; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 618 | fnames = PyTuple_New(num_fields); |
| 619 | if (!fnames) return NULL; |
| 620 | for (i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 621 | PyObject *field = PyUnicode_FromString(fields[i]); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 622 | if (!field) { |
| 623 | Py_DECREF(fnames); |
| 624 | return NULL; |
| 625 | } |
| 626 | PyTuple_SET_ITEM(fnames, i, field); |
| 627 | } |
Victor Stinner | 7eeb5b5 | 2010-06-07 19:57:46 +0000 | [diff] [blame] | 628 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 629 | type, base, "_fields", fnames, "__module__", "_ast"); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 630 | Py_DECREF(fnames); |
| 631 | return (PyTypeObject*)result; |
| 632 | } |
| 633 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 634 | static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) |
| 635 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 636 | int i, result; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 637 | _Py_IDENTIFIER(_attributes); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 638 | PyObject *s, *l = PyTuple_New(num_fields); |
Benjamin Peterson | 3e5cd1d | 2010-06-27 21:45:24 +0000 | [diff] [blame] | 639 | if (!l) |
| 640 | return 0; |
| 641 | for (i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 642 | s = PyUnicode_FromString(attrs[i]); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 643 | if (!s) { |
| 644 | Py_DECREF(l); |
| 645 | return 0; |
| 646 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 647 | PyTuple_SET_ITEM(l, i, s); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 648 | } |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 649 | result = _PyObject_SetAttrId((PyObject*)type, &PyId__attributes, l) >= 0; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 650 | Py_DECREF(l); |
| 651 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 652 | } |
| 653 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 654 | /* Conversion AST -> Python */ |
| 655 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 656 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 657 | { |
Benjamin Peterson | 77fa937 | 2012-05-15 10:10:27 -0700 | [diff] [blame] | 658 | Py_ssize_t i, n = asdl_seq_LEN(seq); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 659 | PyObject *result = PyList_New(n); |
| 660 | PyObject *value; |
| 661 | if (!result) |
| 662 | return NULL; |
| 663 | for (i = 0; i < n; i++) { |
| 664 | value = func(asdl_seq_GET(seq, i)); |
| 665 | if (!value) { |
| 666 | Py_DECREF(result); |
| 667 | return NULL; |
| 668 | } |
| 669 | PyList_SET_ITEM(result, i, value); |
| 670 | } |
| 671 | return result; |
| 672 | } |
| 673 | |
| 674 | static PyObject* ast2obj_object(void *o) |
| 675 | { |
| 676 | if (!o) |
| 677 | o = Py_None; |
| 678 | Py_INCREF((PyObject*)o); |
| 679 | return (PyObject*)o; |
| 680 | } |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 681 | #define ast2obj_singleton ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 682 | #define ast2obj_identifier ast2obj_object |
| 683 | #define ast2obj_string ast2obj_object |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 684 | #define ast2obj_bytes ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 685 | |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 686 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 687 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 688 | return PyLong_FromLong(b); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 689 | } |
| 690 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 691 | /* Conversion Python -> AST */ |
| 692 | |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 693 | static int obj2ast_singleton(PyObject *obj, PyObject** out, PyArena* arena) |
| 694 | { |
| 695 | if (obj != Py_None && obj != Py_True && obj != Py_False) { |
| 696 | PyErr_SetString(PyExc_ValueError, |
| 697 | "AST singleton must be True, False, or None"); |
| 698 | return 1; |
| 699 | } |
| 700 | *out = obj; |
| 701 | return 0; |
| 702 | } |
| 703 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 704 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 705 | { |
| 706 | if (obj == Py_None) |
| 707 | obj = NULL; |
Christian Heimes | 70c94e7 | 2013-07-27 00:33:13 +0200 | [diff] [blame] | 708 | if (obj) { |
| 709 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 710 | *out = NULL; |
| 711 | return -1; |
| 712 | } |
| 713 | Py_INCREF(obj); |
| 714 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 715 | *out = obj; |
| 716 | return 0; |
| 717 | } |
| 718 | |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 719 | static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 720 | { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 721 | if (!PyUnicode_CheckExact(obj) && obj != Py_None) { |
| 722 | PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 723 | return 1; |
| 724 | } |
| 725 | return obj2ast_object(obj, out, arena); |
| 726 | } |
| 727 | |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 728 | static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) |
| 729 | { |
Benjamin Peterson | 0224d4e | 2011-08-31 22:13:03 -0400 | [diff] [blame] | 730 | if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 731 | PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); |
| 732 | return 1; |
| 733 | } |
| 734 | return obj2ast_object(obj, out, arena); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 735 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 736 | |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 737 | static int obj2ast_bytes(PyObject* obj, PyObject** out, PyArena* arena) |
| 738 | { |
| 739 | if (!PyBytes_CheckExact(obj)) { |
| 740 | PyErr_SetString(PyExc_TypeError, "AST bytes must be of type bytes"); |
| 741 | return 1; |
| 742 | } |
| 743 | return obj2ast_object(obj, out, arena); |
| 744 | } |
| 745 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 746 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 747 | { |
| 748 | int i; |
| 749 | if (!PyLong_Check(obj)) { |
Amaury Forgeot d'Arc | 5e8f810 | 2011-11-22 21:52:30 +0100 | [diff] [blame] | 750 | PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 751 | return 1; |
| 752 | } |
| 753 | |
| 754 | i = (int)PyLong_AsLong(obj); |
| 755 | if (i == -1 && PyErr_Occurred()) |
| 756 | return 1; |
| 757 | *out = i; |
| 758 | return 0; |
| 759 | } |
| 760 | |
Benjamin Peterson | 1a6e0d0 | 2008-10-25 15:49:17 +0000 | [diff] [blame] | 761 | static int add_ast_fields(void) |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 762 | { |
| 763 | PyObject *empty_tuple, *d; |
| 764 | if (PyType_Ready(&AST_type) < 0) |
| 765 | return -1; |
| 766 | d = AST_type.tp_dict; |
| 767 | empty_tuple = PyTuple_New(0); |
| 768 | if (!empty_tuple || |
| 769 | PyDict_SetItemString(d, "_fields", empty_tuple) < 0 || |
| 770 | PyDict_SetItemString(d, "_attributes", empty_tuple) < 0) { |
| 771 | Py_XDECREF(empty_tuple); |
| 772 | return -1; |
| 773 | } |
| 774 | Py_DECREF(empty_tuple); |
| 775 | return 0; |
| 776 | } |
| 777 | |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 778 | static int exists_not_none(PyObject *obj, _Py_Identifier *id) |
| 779 | { |
Benjamin Peterson | 3a61943 | 2013-03-18 23:40:53 -0700 | [diff] [blame] | 780 | int isnone; |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 781 | PyObject *attr = _PyObject_GetAttrId(obj, id); |
| 782 | if (!attr) { |
| 783 | PyErr_Clear(); |
| 784 | return 0; |
| 785 | } |
Benjamin Peterson | 3a61943 | 2013-03-18 23:40:53 -0700 | [diff] [blame] | 786 | isnone = attr == Py_None; |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 787 | Py_DECREF(attr); |
| 788 | return !isnone; |
| 789 | } |
| 790 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 791 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 792 | static int init_types(void) |
| 793 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 794 | static int initialized; |
| 795 | if (initialized) return 1; |
| 796 | if (add_ast_fields() < 0) return 0; |
| 797 | mod_type = make_type("mod", &AST_type, NULL, 0); |
| 798 | if (!mod_type) return 0; |
| 799 | if (!add_attributes(mod_type, NULL, 0)) return 0; |
| 800 | Module_type = make_type("Module", mod_type, Module_fields, 1); |
| 801 | if (!Module_type) return 0; |
| 802 | Interactive_type = make_type("Interactive", mod_type, Interactive_fields, |
| 803 | 1); |
| 804 | if (!Interactive_type) return 0; |
| 805 | Expression_type = make_type("Expression", mod_type, Expression_fields, 1); |
| 806 | if (!Expression_type) return 0; |
| 807 | Suite_type = make_type("Suite", mod_type, Suite_fields, 1); |
| 808 | if (!Suite_type) return 0; |
| 809 | stmt_type = make_type("stmt", &AST_type, NULL, 0); |
| 810 | if (!stmt_type) return 0; |
| 811 | if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0; |
| 812 | FunctionDef_type = make_type("FunctionDef", stmt_type, FunctionDef_fields, |
| 813 | 5); |
| 814 | if (!FunctionDef_type) return 0; |
| 815 | ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 7); |
| 816 | if (!ClassDef_type) return 0; |
| 817 | Return_type = make_type("Return", stmt_type, Return_fields, 1); |
| 818 | if (!Return_type) return 0; |
| 819 | Delete_type = make_type("Delete", stmt_type, Delete_fields, 1); |
| 820 | if (!Delete_type) return 0; |
| 821 | Assign_type = make_type("Assign", stmt_type, Assign_fields, 2); |
| 822 | if (!Assign_type) return 0; |
| 823 | AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); |
| 824 | if (!AugAssign_type) return 0; |
| 825 | For_type = make_type("For", stmt_type, For_fields, 4); |
| 826 | if (!For_type) return 0; |
| 827 | While_type = make_type("While", stmt_type, While_fields, 3); |
| 828 | if (!While_type) return 0; |
| 829 | If_type = make_type("If", stmt_type, If_fields, 3); |
| 830 | if (!If_type) return 0; |
| 831 | With_type = make_type("With", stmt_type, With_fields, 2); |
| 832 | if (!With_type) return 0; |
| 833 | Raise_type = make_type("Raise", stmt_type, Raise_fields, 2); |
| 834 | if (!Raise_type) return 0; |
| 835 | Try_type = make_type("Try", stmt_type, Try_fields, 4); |
| 836 | if (!Try_type) return 0; |
| 837 | Assert_type = make_type("Assert", stmt_type, Assert_fields, 2); |
| 838 | if (!Assert_type) return 0; |
| 839 | Import_type = make_type("Import", stmt_type, Import_fields, 1); |
| 840 | if (!Import_type) return 0; |
| 841 | ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, 3); |
| 842 | if (!ImportFrom_type) return 0; |
| 843 | Global_type = make_type("Global", stmt_type, Global_fields, 1); |
| 844 | if (!Global_type) return 0; |
| 845 | Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1); |
| 846 | if (!Nonlocal_type) return 0; |
| 847 | Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); |
| 848 | if (!Expr_type) return 0; |
| 849 | Pass_type = make_type("Pass", stmt_type, NULL, 0); |
| 850 | if (!Pass_type) return 0; |
| 851 | Break_type = make_type("Break", stmt_type, NULL, 0); |
| 852 | if (!Break_type) return 0; |
| 853 | Continue_type = make_type("Continue", stmt_type, NULL, 0); |
| 854 | if (!Continue_type) return 0; |
| 855 | expr_type = make_type("expr", &AST_type, NULL, 0); |
| 856 | if (!expr_type) return 0; |
| 857 | if (!add_attributes(expr_type, expr_attributes, 2)) return 0; |
| 858 | BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2); |
| 859 | if (!BoolOp_type) return 0; |
| 860 | BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3); |
| 861 | if (!BinOp_type) return 0; |
| 862 | UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2); |
| 863 | if (!UnaryOp_type) return 0; |
| 864 | Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2); |
| 865 | if (!Lambda_type) return 0; |
| 866 | IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); |
| 867 | if (!IfExp_type) return 0; |
| 868 | Dict_type = make_type("Dict", expr_type, Dict_fields, 2); |
| 869 | if (!Dict_type) return 0; |
| 870 | Set_type = make_type("Set", expr_type, Set_fields, 1); |
| 871 | if (!Set_type) return 0; |
| 872 | ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); |
| 873 | if (!ListComp_type) return 0; |
| 874 | SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2); |
| 875 | if (!SetComp_type) return 0; |
| 876 | DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3); |
| 877 | if (!DictComp_type) return 0; |
| 878 | GeneratorExp_type = make_type("GeneratorExp", expr_type, |
| 879 | GeneratorExp_fields, 2); |
| 880 | if (!GeneratorExp_type) return 0; |
| 881 | Yield_type = make_type("Yield", expr_type, Yield_fields, 1); |
| 882 | if (!Yield_type) return 0; |
| 883 | YieldFrom_type = make_type("YieldFrom", expr_type, YieldFrom_fields, 1); |
| 884 | if (!YieldFrom_type) return 0; |
| 885 | Compare_type = make_type("Compare", expr_type, Compare_fields, 3); |
| 886 | if (!Compare_type) return 0; |
| 887 | Call_type = make_type("Call", expr_type, Call_fields, 5); |
| 888 | if (!Call_type) return 0; |
| 889 | Num_type = make_type("Num", expr_type, Num_fields, 1); |
| 890 | if (!Num_type) return 0; |
| 891 | Str_type = make_type("Str", expr_type, Str_fields, 1); |
| 892 | if (!Str_type) return 0; |
| 893 | Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1); |
| 894 | if (!Bytes_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 895 | NameConstant_type = make_type("NameConstant", expr_type, |
| 896 | NameConstant_fields, 1); |
| 897 | if (!NameConstant_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 898 | Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0); |
| 899 | if (!Ellipsis_type) return 0; |
| 900 | Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); |
| 901 | if (!Attribute_type) return 0; |
| 902 | Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); |
| 903 | if (!Subscript_type) return 0; |
| 904 | Starred_type = make_type("Starred", expr_type, Starred_fields, 2); |
| 905 | if (!Starred_type) return 0; |
| 906 | Name_type = make_type("Name", expr_type, Name_fields, 2); |
| 907 | if (!Name_type) return 0; |
| 908 | List_type = make_type("List", expr_type, List_fields, 2); |
| 909 | if (!List_type) return 0; |
| 910 | Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2); |
| 911 | if (!Tuple_type) return 0; |
| 912 | expr_context_type = make_type("expr_context", &AST_type, NULL, 0); |
| 913 | if (!expr_context_type) return 0; |
| 914 | if (!add_attributes(expr_context_type, NULL, 0)) return 0; |
| 915 | Load_type = make_type("Load", expr_context_type, NULL, 0); |
| 916 | if (!Load_type) return 0; |
| 917 | Load_singleton = PyType_GenericNew(Load_type, NULL, NULL); |
| 918 | if (!Load_singleton) return 0; |
| 919 | Store_type = make_type("Store", expr_context_type, NULL, 0); |
| 920 | if (!Store_type) return 0; |
| 921 | Store_singleton = PyType_GenericNew(Store_type, NULL, NULL); |
| 922 | if (!Store_singleton) return 0; |
| 923 | Del_type = make_type("Del", expr_context_type, NULL, 0); |
| 924 | if (!Del_type) return 0; |
| 925 | Del_singleton = PyType_GenericNew(Del_type, NULL, NULL); |
| 926 | if (!Del_singleton) return 0; |
| 927 | AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0); |
| 928 | if (!AugLoad_type) return 0; |
| 929 | AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL); |
| 930 | if (!AugLoad_singleton) return 0; |
| 931 | AugStore_type = make_type("AugStore", expr_context_type, NULL, 0); |
| 932 | if (!AugStore_type) return 0; |
| 933 | AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL); |
| 934 | if (!AugStore_singleton) return 0; |
| 935 | Param_type = make_type("Param", expr_context_type, NULL, 0); |
| 936 | if (!Param_type) return 0; |
| 937 | Param_singleton = PyType_GenericNew(Param_type, NULL, NULL); |
| 938 | if (!Param_singleton) return 0; |
| 939 | slice_type = make_type("slice", &AST_type, NULL, 0); |
| 940 | if (!slice_type) return 0; |
| 941 | if (!add_attributes(slice_type, NULL, 0)) return 0; |
| 942 | Slice_type = make_type("Slice", slice_type, Slice_fields, 3); |
| 943 | if (!Slice_type) return 0; |
| 944 | ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); |
| 945 | if (!ExtSlice_type) return 0; |
| 946 | Index_type = make_type("Index", slice_type, Index_fields, 1); |
| 947 | if (!Index_type) return 0; |
| 948 | boolop_type = make_type("boolop", &AST_type, NULL, 0); |
| 949 | if (!boolop_type) return 0; |
| 950 | if (!add_attributes(boolop_type, NULL, 0)) return 0; |
| 951 | And_type = make_type("And", boolop_type, NULL, 0); |
| 952 | if (!And_type) return 0; |
| 953 | And_singleton = PyType_GenericNew(And_type, NULL, NULL); |
| 954 | if (!And_singleton) return 0; |
| 955 | Or_type = make_type("Or", boolop_type, NULL, 0); |
| 956 | if (!Or_type) return 0; |
| 957 | Or_singleton = PyType_GenericNew(Or_type, NULL, NULL); |
| 958 | if (!Or_singleton) return 0; |
| 959 | operator_type = make_type("operator", &AST_type, NULL, 0); |
| 960 | if (!operator_type) return 0; |
| 961 | if (!add_attributes(operator_type, NULL, 0)) return 0; |
| 962 | Add_type = make_type("Add", operator_type, NULL, 0); |
| 963 | if (!Add_type) return 0; |
| 964 | Add_singleton = PyType_GenericNew(Add_type, NULL, NULL); |
| 965 | if (!Add_singleton) return 0; |
| 966 | Sub_type = make_type("Sub", operator_type, NULL, 0); |
| 967 | if (!Sub_type) return 0; |
| 968 | Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL); |
| 969 | if (!Sub_singleton) return 0; |
| 970 | Mult_type = make_type("Mult", operator_type, NULL, 0); |
| 971 | if (!Mult_type) return 0; |
| 972 | Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL); |
| 973 | if (!Mult_singleton) return 0; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 974 | MatMult_type = make_type("MatMult", operator_type, NULL, 0); |
| 975 | if (!MatMult_type) return 0; |
| 976 | MatMult_singleton = PyType_GenericNew(MatMult_type, NULL, NULL); |
| 977 | if (!MatMult_singleton) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 978 | Div_type = make_type("Div", operator_type, NULL, 0); |
| 979 | if (!Div_type) return 0; |
| 980 | Div_singleton = PyType_GenericNew(Div_type, NULL, NULL); |
| 981 | if (!Div_singleton) return 0; |
| 982 | Mod_type = make_type("Mod", operator_type, NULL, 0); |
| 983 | if (!Mod_type) return 0; |
| 984 | Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL); |
| 985 | if (!Mod_singleton) return 0; |
| 986 | Pow_type = make_type("Pow", operator_type, NULL, 0); |
| 987 | if (!Pow_type) return 0; |
| 988 | Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL); |
| 989 | if (!Pow_singleton) return 0; |
| 990 | LShift_type = make_type("LShift", operator_type, NULL, 0); |
| 991 | if (!LShift_type) return 0; |
| 992 | LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL); |
| 993 | if (!LShift_singleton) return 0; |
| 994 | RShift_type = make_type("RShift", operator_type, NULL, 0); |
| 995 | if (!RShift_type) return 0; |
| 996 | RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL); |
| 997 | if (!RShift_singleton) return 0; |
| 998 | BitOr_type = make_type("BitOr", operator_type, NULL, 0); |
| 999 | if (!BitOr_type) return 0; |
| 1000 | BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL); |
| 1001 | if (!BitOr_singleton) return 0; |
| 1002 | BitXor_type = make_type("BitXor", operator_type, NULL, 0); |
| 1003 | if (!BitXor_type) return 0; |
| 1004 | BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL); |
| 1005 | if (!BitXor_singleton) return 0; |
| 1006 | BitAnd_type = make_type("BitAnd", operator_type, NULL, 0); |
| 1007 | if (!BitAnd_type) return 0; |
| 1008 | BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL); |
| 1009 | if (!BitAnd_singleton) return 0; |
| 1010 | FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0); |
| 1011 | if (!FloorDiv_type) return 0; |
| 1012 | FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL); |
| 1013 | if (!FloorDiv_singleton) return 0; |
| 1014 | unaryop_type = make_type("unaryop", &AST_type, NULL, 0); |
| 1015 | if (!unaryop_type) return 0; |
| 1016 | if (!add_attributes(unaryop_type, NULL, 0)) return 0; |
| 1017 | Invert_type = make_type("Invert", unaryop_type, NULL, 0); |
| 1018 | if (!Invert_type) return 0; |
| 1019 | Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL); |
| 1020 | if (!Invert_singleton) return 0; |
| 1021 | Not_type = make_type("Not", unaryop_type, NULL, 0); |
| 1022 | if (!Not_type) return 0; |
| 1023 | Not_singleton = PyType_GenericNew(Not_type, NULL, NULL); |
| 1024 | if (!Not_singleton) return 0; |
| 1025 | UAdd_type = make_type("UAdd", unaryop_type, NULL, 0); |
| 1026 | if (!UAdd_type) return 0; |
| 1027 | UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL); |
| 1028 | if (!UAdd_singleton) return 0; |
| 1029 | USub_type = make_type("USub", unaryop_type, NULL, 0); |
| 1030 | if (!USub_type) return 0; |
| 1031 | USub_singleton = PyType_GenericNew(USub_type, NULL, NULL); |
| 1032 | if (!USub_singleton) return 0; |
| 1033 | cmpop_type = make_type("cmpop", &AST_type, NULL, 0); |
| 1034 | if (!cmpop_type) return 0; |
| 1035 | if (!add_attributes(cmpop_type, NULL, 0)) return 0; |
| 1036 | Eq_type = make_type("Eq", cmpop_type, NULL, 0); |
| 1037 | if (!Eq_type) return 0; |
| 1038 | Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL); |
| 1039 | if (!Eq_singleton) return 0; |
| 1040 | NotEq_type = make_type("NotEq", cmpop_type, NULL, 0); |
| 1041 | if (!NotEq_type) return 0; |
| 1042 | NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL); |
| 1043 | if (!NotEq_singleton) return 0; |
| 1044 | Lt_type = make_type("Lt", cmpop_type, NULL, 0); |
| 1045 | if (!Lt_type) return 0; |
| 1046 | Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL); |
| 1047 | if (!Lt_singleton) return 0; |
| 1048 | LtE_type = make_type("LtE", cmpop_type, NULL, 0); |
| 1049 | if (!LtE_type) return 0; |
| 1050 | LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL); |
| 1051 | if (!LtE_singleton) return 0; |
| 1052 | Gt_type = make_type("Gt", cmpop_type, NULL, 0); |
| 1053 | if (!Gt_type) return 0; |
| 1054 | Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL); |
| 1055 | if (!Gt_singleton) return 0; |
| 1056 | GtE_type = make_type("GtE", cmpop_type, NULL, 0); |
| 1057 | if (!GtE_type) return 0; |
| 1058 | GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL); |
| 1059 | if (!GtE_singleton) return 0; |
| 1060 | Is_type = make_type("Is", cmpop_type, NULL, 0); |
| 1061 | if (!Is_type) return 0; |
| 1062 | Is_singleton = PyType_GenericNew(Is_type, NULL, NULL); |
| 1063 | if (!Is_singleton) return 0; |
| 1064 | IsNot_type = make_type("IsNot", cmpop_type, NULL, 0); |
| 1065 | if (!IsNot_type) return 0; |
| 1066 | IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL); |
| 1067 | if (!IsNot_singleton) return 0; |
| 1068 | In_type = make_type("In", cmpop_type, NULL, 0); |
| 1069 | if (!In_type) return 0; |
| 1070 | In_singleton = PyType_GenericNew(In_type, NULL, NULL); |
| 1071 | if (!In_singleton) return 0; |
| 1072 | NotIn_type = make_type("NotIn", cmpop_type, NULL, 0); |
| 1073 | if (!NotIn_type) return 0; |
| 1074 | NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL); |
| 1075 | if (!NotIn_singleton) return 0; |
| 1076 | comprehension_type = make_type("comprehension", &AST_type, |
| 1077 | comprehension_fields, 3); |
| 1078 | if (!comprehension_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1079 | if (!add_attributes(comprehension_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1080 | excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0); |
| 1081 | if (!excepthandler_type) return 0; |
| 1082 | if (!add_attributes(excepthandler_type, excepthandler_attributes, 2)) |
| 1083 | return 0; |
| 1084 | ExceptHandler_type = make_type("ExceptHandler", excepthandler_type, |
| 1085 | ExceptHandler_fields, 3); |
| 1086 | if (!ExceptHandler_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1087 | arguments_type = make_type("arguments", &AST_type, arguments_fields, 6); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1088 | if (!arguments_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1089 | if (!add_attributes(arguments_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1090 | arg_type = make_type("arg", &AST_type, arg_fields, 2); |
| 1091 | if (!arg_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1092 | if (!add_attributes(arg_type, arg_attributes, 2)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1093 | keyword_type = make_type("keyword", &AST_type, keyword_fields, 2); |
| 1094 | if (!keyword_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1095 | if (!add_attributes(keyword_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1096 | alias_type = make_type("alias", &AST_type, alias_fields, 2); |
| 1097 | if (!alias_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1098 | if (!add_attributes(alias_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1099 | withitem_type = make_type("withitem", &AST_type, withitem_fields, 2); |
| 1100 | if (!withitem_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1101 | if (!add_attributes(withitem_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1102 | initialized = 1; |
| 1103 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1104 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 1105 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1106 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 1107 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 1108 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 1109 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 1110 | arena); |
| 1111 | static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena); |
| 1112 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 1113 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 1114 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 1115 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 1116 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 1117 | arena); |
| 1118 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 1119 | arena); |
| 1120 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 1121 | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
| 1122 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 1123 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1124 | 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] | 1125 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1126 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1127 | Module(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1128 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1129 | mod_ty p; |
| 1130 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1131 | if (!p) |
| 1132 | return NULL; |
| 1133 | p->kind = Module_kind; |
| 1134 | p->v.Module.body = body; |
| 1135 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1136 | } |
| 1137 | |
| 1138 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1139 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1140 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1141 | mod_ty p; |
| 1142 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1143 | if (!p) |
| 1144 | return NULL; |
| 1145 | p->kind = Interactive_kind; |
| 1146 | p->v.Interactive.body = body; |
| 1147 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1151 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1152 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1153 | mod_ty p; |
| 1154 | if (!body) { |
| 1155 | PyErr_SetString(PyExc_ValueError, |
| 1156 | "field body is required for Expression"); |
| 1157 | return NULL; |
| 1158 | } |
| 1159 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1160 | if (!p) |
| 1161 | return NULL; |
| 1162 | p->kind = Expression_kind; |
| 1163 | p->v.Expression.body = body; |
| 1164 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1168 | Suite(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1169 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1170 | mod_ty p; |
| 1171 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1172 | if (!p) |
| 1173 | return NULL; |
| 1174 | p->kind = Suite_kind; |
| 1175 | p->v.Suite.body = body; |
| 1176 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | stmt_ty |
| 1180 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1181 | decorator_list, expr_ty returns, int lineno, int col_offset, |
| 1182 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1183 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1184 | stmt_ty p; |
| 1185 | if (!name) { |
| 1186 | PyErr_SetString(PyExc_ValueError, |
| 1187 | "field name is required for FunctionDef"); |
| 1188 | return NULL; |
| 1189 | } |
| 1190 | if (!args) { |
| 1191 | PyErr_SetString(PyExc_ValueError, |
| 1192 | "field args is required for FunctionDef"); |
| 1193 | return NULL; |
| 1194 | } |
| 1195 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1196 | if (!p) |
| 1197 | return NULL; |
| 1198 | p->kind = FunctionDef_kind; |
| 1199 | p->v.FunctionDef.name = name; |
| 1200 | p->v.FunctionDef.args = args; |
| 1201 | p->v.FunctionDef.body = body; |
| 1202 | p->v.FunctionDef.decorator_list = decorator_list; |
| 1203 | p->v.FunctionDef.returns = returns; |
| 1204 | p->lineno = lineno; |
| 1205 | p->col_offset = col_offset; |
| 1206 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1207 | } |
| 1208 | |
| 1209 | stmt_ty |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 1210 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, expr_ty |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1211 | starargs, expr_ty kwargs, asdl_seq * body, asdl_seq * decorator_list, |
| 1212 | int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1213 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1214 | stmt_ty p; |
| 1215 | if (!name) { |
| 1216 | PyErr_SetString(PyExc_ValueError, |
| 1217 | "field name is required for ClassDef"); |
| 1218 | return NULL; |
| 1219 | } |
| 1220 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1221 | if (!p) |
| 1222 | return NULL; |
| 1223 | p->kind = ClassDef_kind; |
| 1224 | p->v.ClassDef.name = name; |
| 1225 | p->v.ClassDef.bases = bases; |
| 1226 | p->v.ClassDef.keywords = keywords; |
| 1227 | p->v.ClassDef.starargs = starargs; |
| 1228 | p->v.ClassDef.kwargs = kwargs; |
| 1229 | p->v.ClassDef.body = body; |
| 1230 | p->v.ClassDef.decorator_list = decorator_list; |
| 1231 | p->lineno = lineno; |
| 1232 | p->col_offset = col_offset; |
| 1233 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1237 | Return(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1238 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1239 | stmt_ty p; |
| 1240 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1241 | if (!p) |
| 1242 | return NULL; |
| 1243 | p->kind = Return_kind; |
| 1244 | p->v.Return.value = value; |
| 1245 | p->lineno = lineno; |
| 1246 | p->col_offset = col_offset; |
| 1247 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1251 | Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1252 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1253 | stmt_ty p; |
| 1254 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1255 | if (!p) |
| 1256 | return NULL; |
| 1257 | p->kind = Delete_kind; |
| 1258 | p->v.Delete.targets = targets; |
| 1259 | p->lineno = lineno; |
| 1260 | p->col_offset = col_offset; |
| 1261 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1265 | Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena |
| 1266 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1267 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1268 | stmt_ty p; |
| 1269 | if (!value) { |
| 1270 | PyErr_SetString(PyExc_ValueError, |
| 1271 | "field value is required for Assign"); |
| 1272 | return NULL; |
| 1273 | } |
| 1274 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1275 | if (!p) |
| 1276 | return NULL; |
| 1277 | p->kind = Assign_kind; |
| 1278 | p->v.Assign.targets = targets; |
| 1279 | p->v.Assign.value = value; |
| 1280 | p->lineno = lineno; |
| 1281 | p->col_offset = col_offset; |
| 1282 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1283 | } |
| 1284 | |
| 1285 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1286 | AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int |
| 1287 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1288 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1289 | stmt_ty p; |
| 1290 | if (!target) { |
| 1291 | PyErr_SetString(PyExc_ValueError, |
| 1292 | "field target is required for AugAssign"); |
| 1293 | return NULL; |
| 1294 | } |
| 1295 | if (!op) { |
| 1296 | PyErr_SetString(PyExc_ValueError, |
| 1297 | "field op is required for AugAssign"); |
| 1298 | return NULL; |
| 1299 | } |
| 1300 | if (!value) { |
| 1301 | PyErr_SetString(PyExc_ValueError, |
| 1302 | "field value is required for AugAssign"); |
| 1303 | return NULL; |
| 1304 | } |
| 1305 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1306 | if (!p) |
| 1307 | return NULL; |
| 1308 | p->kind = AugAssign_kind; |
| 1309 | p->v.AugAssign.target = target; |
| 1310 | p->v.AugAssign.op = op; |
| 1311 | p->v.AugAssign.value = value; |
| 1312 | p->lineno = lineno; |
| 1313 | p->col_offset = col_offset; |
| 1314 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | stmt_ty |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1318 | 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] | 1319 | lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1320 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1321 | stmt_ty p; |
| 1322 | if (!target) { |
| 1323 | PyErr_SetString(PyExc_ValueError, |
| 1324 | "field target is required for For"); |
| 1325 | return NULL; |
| 1326 | } |
| 1327 | if (!iter) { |
| 1328 | PyErr_SetString(PyExc_ValueError, |
| 1329 | "field iter is required for For"); |
| 1330 | return NULL; |
| 1331 | } |
| 1332 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1333 | if (!p) |
| 1334 | return NULL; |
| 1335 | p->kind = For_kind; |
| 1336 | p->v.For.target = target; |
| 1337 | p->v.For.iter = iter; |
| 1338 | p->v.For.body = body; |
| 1339 | p->v.For.orelse = orelse; |
| 1340 | p->lineno = lineno; |
| 1341 | p->col_offset = col_offset; |
| 1342 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1346 | While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1347 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1348 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1349 | stmt_ty p; |
| 1350 | if (!test) { |
| 1351 | PyErr_SetString(PyExc_ValueError, |
| 1352 | "field test is required for While"); |
| 1353 | return NULL; |
| 1354 | } |
| 1355 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1356 | if (!p) |
| 1357 | return NULL; |
| 1358 | p->kind = While_kind; |
| 1359 | p->v.While.test = test; |
| 1360 | p->v.While.body = body; |
| 1361 | p->v.While.orelse = orelse; |
| 1362 | p->lineno = lineno; |
| 1363 | p->col_offset = col_offset; |
| 1364 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1368 | If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1369 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1370 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1371 | stmt_ty p; |
| 1372 | if (!test) { |
| 1373 | PyErr_SetString(PyExc_ValueError, |
| 1374 | "field test is required for If"); |
| 1375 | return NULL; |
| 1376 | } |
| 1377 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1378 | if (!p) |
| 1379 | return NULL; |
| 1380 | p->kind = If_kind; |
| 1381 | p->v.If.test = test; |
| 1382 | p->v.If.body = body; |
| 1383 | p->v.If.orelse = orelse; |
| 1384 | p->lineno = lineno; |
| 1385 | p->col_offset = col_offset; |
| 1386 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | stmt_ty |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1390 | With(asdl_seq * items, asdl_seq * body, int lineno, int col_offset, PyArena |
| 1391 | *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1392 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1393 | stmt_ty p; |
| 1394 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1395 | if (!p) |
| 1396 | return NULL; |
| 1397 | p->kind = With_kind; |
| 1398 | p->v.With.items = items; |
| 1399 | p->v.With.body = body; |
| 1400 | p->lineno = lineno; |
| 1401 | p->col_offset = col_offset; |
| 1402 | return p; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1403 | } |
| 1404 | |
| 1405 | stmt_ty |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 1406 | 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] | 1407 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1408 | stmt_ty p; |
| 1409 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1410 | if (!p) |
| 1411 | return NULL; |
| 1412 | p->kind = Raise_kind; |
| 1413 | p->v.Raise.exc = exc; |
| 1414 | p->v.Raise.cause = cause; |
| 1415 | p->lineno = lineno; |
| 1416 | p->col_offset = col_offset; |
| 1417 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1418 | } |
| 1419 | |
| 1420 | stmt_ty |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 1421 | Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * |
| 1422 | finalbody, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1423 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1424 | stmt_ty p; |
| 1425 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1426 | if (!p) |
| 1427 | return NULL; |
| 1428 | p->kind = Try_kind; |
| 1429 | p->v.Try.body = body; |
| 1430 | p->v.Try.handlers = handlers; |
| 1431 | p->v.Try.orelse = orelse; |
| 1432 | p->v.Try.finalbody = finalbody; |
| 1433 | p->lineno = lineno; |
| 1434 | p->col_offset = col_offset; |
| 1435 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1436 | } |
| 1437 | |
| 1438 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1439 | 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] | 1440 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1441 | stmt_ty p; |
| 1442 | if (!test) { |
| 1443 | PyErr_SetString(PyExc_ValueError, |
| 1444 | "field test is required for Assert"); |
| 1445 | return NULL; |
| 1446 | } |
| 1447 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1448 | if (!p) |
| 1449 | return NULL; |
| 1450 | p->kind = Assert_kind; |
| 1451 | p->v.Assert.test = test; |
| 1452 | p->v.Assert.msg = msg; |
| 1453 | p->lineno = lineno; |
| 1454 | p->col_offset = col_offset; |
| 1455 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1459 | Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1460 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1461 | stmt_ty p; |
| 1462 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1463 | if (!p) |
| 1464 | return NULL; |
| 1465 | p->kind = Import_kind; |
| 1466 | p->v.Import.names = names; |
| 1467 | p->lineno = lineno; |
| 1468 | p->col_offset = col_offset; |
| 1469 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1473 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
| 1474 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1475 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1476 | stmt_ty p; |
| 1477 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1478 | if (!p) |
| 1479 | return NULL; |
| 1480 | p->kind = ImportFrom_kind; |
| 1481 | p->v.ImportFrom.module = module; |
| 1482 | p->v.ImportFrom.names = names; |
| 1483 | p->v.ImportFrom.level = level; |
| 1484 | p->lineno = lineno; |
| 1485 | p->col_offset = col_offset; |
| 1486 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1490 | Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1491 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1492 | stmt_ty p; |
| 1493 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1494 | if (!p) |
| 1495 | return NULL; |
| 1496 | p->kind = Global_kind; |
| 1497 | p->v.Global.names = names; |
| 1498 | p->lineno = lineno; |
| 1499 | p->col_offset = col_offset; |
| 1500 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | stmt_ty |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 1504 | Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
| 1505 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1506 | stmt_ty p; |
| 1507 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1508 | if (!p) |
| 1509 | return NULL; |
| 1510 | p->kind = Nonlocal_kind; |
| 1511 | p->v.Nonlocal.names = names; |
| 1512 | p->lineno = lineno; |
| 1513 | p->col_offset = col_offset; |
| 1514 | return p; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 1515 | } |
| 1516 | |
| 1517 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1518 | Expr(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1519 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1520 | stmt_ty p; |
| 1521 | if (!value) { |
| 1522 | PyErr_SetString(PyExc_ValueError, |
| 1523 | "field value is required for Expr"); |
| 1524 | return NULL; |
| 1525 | } |
| 1526 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1527 | if (!p) |
| 1528 | return NULL; |
| 1529 | p->kind = Expr_kind; |
| 1530 | p->v.Expr.value = value; |
| 1531 | p->lineno = lineno; |
| 1532 | p->col_offset = col_offset; |
| 1533 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1534 | } |
| 1535 | |
| 1536 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1537 | Pass(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1538 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1539 | stmt_ty p; |
| 1540 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1541 | if (!p) |
| 1542 | return NULL; |
| 1543 | p->kind = Pass_kind; |
| 1544 | p->lineno = lineno; |
| 1545 | p->col_offset = col_offset; |
| 1546 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1547 | } |
| 1548 | |
| 1549 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1550 | Break(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1551 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1552 | stmt_ty p; |
| 1553 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1554 | if (!p) |
| 1555 | return NULL; |
| 1556 | p->kind = Break_kind; |
| 1557 | p->lineno = lineno; |
| 1558 | p->col_offset = col_offset; |
| 1559 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1560 | } |
| 1561 | |
| 1562 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1563 | Continue(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1564 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1565 | stmt_ty p; |
| 1566 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1567 | if (!p) |
| 1568 | return NULL; |
| 1569 | p->kind = Continue_kind; |
| 1570 | p->lineno = lineno; |
| 1571 | p->col_offset = col_offset; |
| 1572 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1573 | } |
| 1574 | |
| 1575 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1576 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1577 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1578 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1579 | expr_ty p; |
| 1580 | if (!op) { |
| 1581 | PyErr_SetString(PyExc_ValueError, |
| 1582 | "field op is required for BoolOp"); |
| 1583 | return NULL; |
| 1584 | } |
| 1585 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1586 | if (!p) |
| 1587 | return NULL; |
| 1588 | p->kind = BoolOp_kind; |
| 1589 | p->v.BoolOp.op = op; |
| 1590 | p->v.BoolOp.values = values; |
| 1591 | p->lineno = lineno; |
| 1592 | p->col_offset = col_offset; |
| 1593 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1594 | } |
| 1595 | |
| 1596 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1597 | BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset, |
| 1598 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1599 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1600 | expr_ty p; |
| 1601 | if (!left) { |
| 1602 | PyErr_SetString(PyExc_ValueError, |
| 1603 | "field left is required for BinOp"); |
| 1604 | return NULL; |
| 1605 | } |
| 1606 | if (!op) { |
| 1607 | PyErr_SetString(PyExc_ValueError, |
| 1608 | "field op is required for BinOp"); |
| 1609 | return NULL; |
| 1610 | } |
| 1611 | if (!right) { |
| 1612 | PyErr_SetString(PyExc_ValueError, |
| 1613 | "field right is required for BinOp"); |
| 1614 | return NULL; |
| 1615 | } |
| 1616 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1617 | if (!p) |
| 1618 | return NULL; |
| 1619 | p->kind = BinOp_kind; |
| 1620 | p->v.BinOp.left = left; |
| 1621 | p->v.BinOp.op = op; |
| 1622 | p->v.BinOp.right = right; |
| 1623 | p->lineno = lineno; |
| 1624 | p->col_offset = col_offset; |
| 1625 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1626 | } |
| 1627 | |
| 1628 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1629 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena |
| 1630 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1631 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1632 | expr_ty p; |
| 1633 | if (!op) { |
| 1634 | PyErr_SetString(PyExc_ValueError, |
| 1635 | "field op is required for UnaryOp"); |
| 1636 | return NULL; |
| 1637 | } |
| 1638 | if (!operand) { |
| 1639 | PyErr_SetString(PyExc_ValueError, |
| 1640 | "field operand is required for UnaryOp"); |
| 1641 | return NULL; |
| 1642 | } |
| 1643 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1644 | if (!p) |
| 1645 | return NULL; |
| 1646 | p->kind = UnaryOp_kind; |
| 1647 | p->v.UnaryOp.op = op; |
| 1648 | p->v.UnaryOp.operand = operand; |
| 1649 | p->lineno = lineno; |
| 1650 | p->col_offset = col_offset; |
| 1651 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1652 | } |
| 1653 | |
| 1654 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1655 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena |
| 1656 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1657 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1658 | expr_ty p; |
| 1659 | if (!args) { |
| 1660 | PyErr_SetString(PyExc_ValueError, |
| 1661 | "field args is required for Lambda"); |
| 1662 | return NULL; |
| 1663 | } |
| 1664 | if (!body) { |
| 1665 | PyErr_SetString(PyExc_ValueError, |
| 1666 | "field body is required for Lambda"); |
| 1667 | return NULL; |
| 1668 | } |
| 1669 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1670 | if (!p) |
| 1671 | return NULL; |
| 1672 | p->kind = Lambda_kind; |
| 1673 | p->v.Lambda.args = args; |
| 1674 | p->v.Lambda.body = body; |
| 1675 | p->lineno = lineno; |
| 1676 | p->col_offset = col_offset; |
| 1677 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1678 | } |
| 1679 | |
| 1680 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1681 | IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset, |
| 1682 | PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1683 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1684 | expr_ty p; |
| 1685 | if (!test) { |
| 1686 | PyErr_SetString(PyExc_ValueError, |
| 1687 | "field test is required for IfExp"); |
| 1688 | return NULL; |
| 1689 | } |
| 1690 | if (!body) { |
| 1691 | PyErr_SetString(PyExc_ValueError, |
| 1692 | "field body is required for IfExp"); |
| 1693 | return NULL; |
| 1694 | } |
| 1695 | if (!orelse) { |
| 1696 | PyErr_SetString(PyExc_ValueError, |
| 1697 | "field orelse is required for IfExp"); |
| 1698 | return NULL; |
| 1699 | } |
| 1700 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1701 | if (!p) |
| 1702 | return NULL; |
| 1703 | p->kind = IfExp_kind; |
| 1704 | p->v.IfExp.test = test; |
| 1705 | p->v.IfExp.body = body; |
| 1706 | p->v.IfExp.orelse = orelse; |
| 1707 | p->lineno = lineno; |
| 1708 | p->col_offset = col_offset; |
| 1709 | return p; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1710 | } |
| 1711 | |
| 1712 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1713 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1714 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1715 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1716 | expr_ty p; |
| 1717 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1718 | if (!p) |
| 1719 | return NULL; |
| 1720 | p->kind = Dict_kind; |
| 1721 | p->v.Dict.keys = keys; |
| 1722 | p->v.Dict.values = values; |
| 1723 | p->lineno = lineno; |
| 1724 | p->col_offset = col_offset; |
| 1725 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | expr_ty |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1729 | Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena) |
| 1730 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1731 | expr_ty p; |
| 1732 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1733 | if (!p) |
| 1734 | return NULL; |
| 1735 | p->kind = Set_kind; |
| 1736 | p->v.Set.elts = elts; |
| 1737 | p->lineno = lineno; |
| 1738 | p->col_offset = col_offset; |
| 1739 | return p; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1740 | } |
| 1741 | |
| 1742 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1743 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1744 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1745 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1746 | expr_ty p; |
| 1747 | if (!elt) { |
| 1748 | PyErr_SetString(PyExc_ValueError, |
| 1749 | "field elt is required for ListComp"); |
| 1750 | return NULL; |
| 1751 | } |
| 1752 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1753 | if (!p) |
| 1754 | return NULL; |
| 1755 | p->kind = ListComp_kind; |
| 1756 | p->v.ListComp.elt = elt; |
| 1757 | p->v.ListComp.generators = generators; |
| 1758 | p->lineno = lineno; |
| 1759 | p->col_offset = col_offset; |
| 1760 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1761 | } |
| 1762 | |
| 1763 | expr_ty |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 1764 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena |
| 1765 | *arena) |
| 1766 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1767 | expr_ty p; |
| 1768 | if (!elt) { |
| 1769 | PyErr_SetString(PyExc_ValueError, |
| 1770 | "field elt is required for SetComp"); |
| 1771 | return NULL; |
| 1772 | } |
| 1773 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1774 | if (!p) |
| 1775 | return NULL; |
| 1776 | p->kind = SetComp_kind; |
| 1777 | p->v.SetComp.elt = elt; |
| 1778 | p->v.SetComp.generators = generators; |
| 1779 | p->lineno = lineno; |
| 1780 | p->col_offset = col_offset; |
| 1781 | return p; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 1782 | } |
| 1783 | |
| 1784 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 1785 | DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int |
| 1786 | col_offset, PyArena *arena) |
| 1787 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1788 | expr_ty p; |
| 1789 | if (!key) { |
| 1790 | PyErr_SetString(PyExc_ValueError, |
| 1791 | "field key is required for DictComp"); |
| 1792 | return NULL; |
| 1793 | } |
| 1794 | if (!value) { |
| 1795 | PyErr_SetString(PyExc_ValueError, |
| 1796 | "field value is required for DictComp"); |
| 1797 | return NULL; |
| 1798 | } |
| 1799 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1800 | if (!p) |
| 1801 | return NULL; |
| 1802 | p->kind = DictComp_kind; |
| 1803 | p->v.DictComp.key = key; |
| 1804 | p->v.DictComp.value = value; |
| 1805 | p->v.DictComp.generators = generators; |
| 1806 | p->lineno = lineno; |
| 1807 | p->col_offset = col_offset; |
| 1808 | return p; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1812 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1813 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1814 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1815 | expr_ty p; |
| 1816 | if (!elt) { |
| 1817 | PyErr_SetString(PyExc_ValueError, |
| 1818 | "field elt is required for GeneratorExp"); |
| 1819 | return NULL; |
| 1820 | } |
| 1821 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1822 | if (!p) |
| 1823 | return NULL; |
| 1824 | p->kind = GeneratorExp_kind; |
| 1825 | p->v.GeneratorExp.elt = elt; |
| 1826 | p->v.GeneratorExp.generators = generators; |
| 1827 | p->lineno = lineno; |
| 1828 | p->col_offset = col_offset; |
| 1829 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1830 | } |
| 1831 | |
| 1832 | expr_ty |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 1833 | Yield(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1834 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1835 | expr_ty p; |
| 1836 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1837 | if (!p) |
| 1838 | return NULL; |
| 1839 | p->kind = Yield_kind; |
| 1840 | p->v.Yield.value = value; |
| 1841 | p->lineno = lineno; |
| 1842 | p->col_offset = col_offset; |
| 1843 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1844 | } |
| 1845 | |
| 1846 | expr_ty |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 1847 | YieldFrom(expr_ty value, int lineno, int col_offset, PyArena *arena) |
| 1848 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1849 | expr_ty p; |
| 1850 | if (!value) { |
| 1851 | PyErr_SetString(PyExc_ValueError, |
| 1852 | "field value is required for YieldFrom"); |
| 1853 | return NULL; |
| 1854 | } |
| 1855 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1856 | if (!p) |
| 1857 | return NULL; |
| 1858 | p->kind = YieldFrom_kind; |
| 1859 | p->v.YieldFrom.value = value; |
| 1860 | p->lineno = lineno; |
| 1861 | p->col_offset = col_offset; |
| 1862 | return p; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 1863 | } |
| 1864 | |
| 1865 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1866 | Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno, |
| 1867 | int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1868 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1869 | expr_ty p; |
| 1870 | if (!left) { |
| 1871 | PyErr_SetString(PyExc_ValueError, |
| 1872 | "field left is required for Compare"); |
| 1873 | return NULL; |
| 1874 | } |
| 1875 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1876 | if (!p) |
| 1877 | return NULL; |
| 1878 | p->kind = Compare_kind; |
| 1879 | p->v.Compare.left = left; |
| 1880 | p->v.Compare.ops = ops; |
| 1881 | p->v.Compare.comparators = comparators; |
| 1882 | p->lineno = lineno; |
| 1883 | p->col_offset = col_offset; |
| 1884 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1885 | } |
| 1886 | |
| 1887 | expr_ty |
| 1888 | 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] | 1889 | expr_ty kwargs, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1890 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1891 | expr_ty p; |
| 1892 | if (!func) { |
| 1893 | PyErr_SetString(PyExc_ValueError, |
| 1894 | "field func is required for Call"); |
| 1895 | return NULL; |
| 1896 | } |
| 1897 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1898 | if (!p) |
| 1899 | return NULL; |
| 1900 | p->kind = Call_kind; |
| 1901 | p->v.Call.func = func; |
| 1902 | p->v.Call.args = args; |
| 1903 | p->v.Call.keywords = keywords; |
| 1904 | p->v.Call.starargs = starargs; |
| 1905 | p->v.Call.kwargs = kwargs; |
| 1906 | p->lineno = lineno; |
| 1907 | p->col_offset = col_offset; |
| 1908 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1909 | } |
| 1910 | |
| 1911 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1912 | Num(object n, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1913 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1914 | expr_ty p; |
| 1915 | if (!n) { |
| 1916 | PyErr_SetString(PyExc_ValueError, |
| 1917 | "field n is required for Num"); |
| 1918 | return NULL; |
| 1919 | } |
| 1920 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1921 | if (!p) |
| 1922 | return NULL; |
| 1923 | p->kind = Num_kind; |
| 1924 | p->v.Num.n = n; |
| 1925 | p->lineno = lineno; |
| 1926 | p->col_offset = col_offset; |
| 1927 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1928 | } |
| 1929 | |
| 1930 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1931 | Str(string s, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1932 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1933 | expr_ty p; |
| 1934 | if (!s) { |
| 1935 | PyErr_SetString(PyExc_ValueError, |
| 1936 | "field s is required for Str"); |
| 1937 | return NULL; |
| 1938 | } |
| 1939 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1940 | if (!p) |
| 1941 | return NULL; |
| 1942 | p->kind = Str_kind; |
| 1943 | p->v.Str.s = s; |
| 1944 | p->lineno = lineno; |
| 1945 | p->col_offset = col_offset; |
| 1946 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1947 | } |
| 1948 | |
| 1949 | expr_ty |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 1950 | Bytes(bytes s, int lineno, int col_offset, PyArena *arena) |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1951 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1952 | expr_ty p; |
| 1953 | if (!s) { |
| 1954 | PyErr_SetString(PyExc_ValueError, |
| 1955 | "field s is required for Bytes"); |
| 1956 | return NULL; |
| 1957 | } |
| 1958 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1959 | if (!p) |
| 1960 | return NULL; |
| 1961 | p->kind = Bytes_kind; |
| 1962 | p->v.Bytes.s = s; |
| 1963 | p->lineno = lineno; |
| 1964 | p->col_offset = col_offset; |
| 1965 | return p; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1966 | } |
| 1967 | |
| 1968 | expr_ty |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 1969 | NameConstant(singleton value, int lineno, int col_offset, PyArena *arena) |
| 1970 | { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1971 | expr_ty p; |
| 1972 | if (!value) { |
| 1973 | PyErr_SetString(PyExc_ValueError, |
| 1974 | "field value is required for NameConstant"); |
| 1975 | return NULL; |
| 1976 | } |
| 1977 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1978 | if (!p) |
| 1979 | return NULL; |
| 1980 | p->kind = NameConstant_kind; |
| 1981 | p->v.NameConstant.value = value; |
| 1982 | p->lineno = lineno; |
| 1983 | p->col_offset = col_offset; |
| 1984 | return p; |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 1985 | } |
| 1986 | |
| 1987 | expr_ty |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1988 | Ellipsis(int lineno, int col_offset, PyArena *arena) |
| 1989 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1990 | expr_ty p; |
| 1991 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1992 | if (!p) |
| 1993 | return NULL; |
| 1994 | p->kind = Ellipsis_kind; |
| 1995 | p->lineno = lineno; |
| 1996 | p->col_offset = col_offset; |
| 1997 | return p; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2001 | Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int |
| 2002 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2003 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2004 | expr_ty p; |
| 2005 | if (!value) { |
| 2006 | PyErr_SetString(PyExc_ValueError, |
| 2007 | "field value is required for Attribute"); |
| 2008 | return NULL; |
| 2009 | } |
| 2010 | if (!attr) { |
| 2011 | PyErr_SetString(PyExc_ValueError, |
| 2012 | "field attr is required for Attribute"); |
| 2013 | return NULL; |
| 2014 | } |
| 2015 | if (!ctx) { |
| 2016 | PyErr_SetString(PyExc_ValueError, |
| 2017 | "field ctx is required for Attribute"); |
| 2018 | return NULL; |
| 2019 | } |
| 2020 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2021 | if (!p) |
| 2022 | return NULL; |
| 2023 | p->kind = Attribute_kind; |
| 2024 | p->v.Attribute.value = value; |
| 2025 | p->v.Attribute.attr = attr; |
| 2026 | p->v.Attribute.ctx = ctx; |
| 2027 | p->lineno = lineno; |
| 2028 | p->col_offset = col_offset; |
| 2029 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2030 | } |
| 2031 | |
| 2032 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2033 | Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int |
| 2034 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2035 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2036 | expr_ty p; |
| 2037 | if (!value) { |
| 2038 | PyErr_SetString(PyExc_ValueError, |
| 2039 | "field value is required for Subscript"); |
| 2040 | return NULL; |
| 2041 | } |
| 2042 | if (!slice) { |
| 2043 | PyErr_SetString(PyExc_ValueError, |
| 2044 | "field slice is required for Subscript"); |
| 2045 | return NULL; |
| 2046 | } |
| 2047 | if (!ctx) { |
| 2048 | PyErr_SetString(PyExc_ValueError, |
| 2049 | "field ctx is required for Subscript"); |
| 2050 | return NULL; |
| 2051 | } |
| 2052 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2053 | if (!p) |
| 2054 | return NULL; |
| 2055 | p->kind = Subscript_kind; |
| 2056 | p->v.Subscript.value = value; |
| 2057 | p->v.Subscript.slice = slice; |
| 2058 | p->v.Subscript.ctx = ctx; |
| 2059 | p->lineno = lineno; |
| 2060 | p->col_offset = col_offset; |
| 2061 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2062 | } |
| 2063 | |
| 2064 | expr_ty |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2065 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 2066 | *arena) |
| 2067 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2068 | expr_ty p; |
| 2069 | if (!value) { |
| 2070 | PyErr_SetString(PyExc_ValueError, |
| 2071 | "field value is required for Starred"); |
| 2072 | return NULL; |
| 2073 | } |
| 2074 | if (!ctx) { |
| 2075 | PyErr_SetString(PyExc_ValueError, |
| 2076 | "field ctx is required for Starred"); |
| 2077 | return NULL; |
| 2078 | } |
| 2079 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2080 | if (!p) |
| 2081 | return NULL; |
| 2082 | p->kind = Starred_kind; |
| 2083 | p->v.Starred.value = value; |
| 2084 | p->v.Starred.ctx = ctx; |
| 2085 | p->lineno = lineno; |
| 2086 | p->col_offset = col_offset; |
| 2087 | return p; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2088 | } |
| 2089 | |
| 2090 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2091 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 2092 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2093 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2094 | expr_ty p; |
| 2095 | if (!id) { |
| 2096 | PyErr_SetString(PyExc_ValueError, |
| 2097 | "field id is required for Name"); |
| 2098 | return NULL; |
| 2099 | } |
| 2100 | if (!ctx) { |
| 2101 | PyErr_SetString(PyExc_ValueError, |
| 2102 | "field ctx is required for Name"); |
| 2103 | return NULL; |
| 2104 | } |
| 2105 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2106 | if (!p) |
| 2107 | return NULL; |
| 2108 | p->kind = Name_kind; |
| 2109 | p->v.Name.id = id; |
| 2110 | p->v.Name.ctx = ctx; |
| 2111 | p->lineno = lineno; |
| 2112 | p->col_offset = col_offset; |
| 2113 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2114 | } |
| 2115 | |
| 2116 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2117 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 2118 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2119 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2120 | expr_ty p; |
| 2121 | if (!ctx) { |
| 2122 | PyErr_SetString(PyExc_ValueError, |
| 2123 | "field ctx is required for List"); |
| 2124 | return NULL; |
| 2125 | } |
| 2126 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2127 | if (!p) |
| 2128 | return NULL; |
| 2129 | p->kind = List_kind; |
| 2130 | p->v.List.elts = elts; |
| 2131 | p->v.List.ctx = ctx; |
| 2132 | p->lineno = lineno; |
| 2133 | p->col_offset = col_offset; |
| 2134 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2138 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 2139 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2140 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2141 | expr_ty p; |
| 2142 | if (!ctx) { |
| 2143 | PyErr_SetString(PyExc_ValueError, |
| 2144 | "field ctx is required for Tuple"); |
| 2145 | return NULL; |
| 2146 | } |
| 2147 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2148 | if (!p) |
| 2149 | return NULL; |
| 2150 | p->kind = Tuple_kind; |
| 2151 | p->v.Tuple.elts = elts; |
| 2152 | p->v.Tuple.ctx = ctx; |
| 2153 | p->lineno = lineno; |
| 2154 | p->col_offset = col_offset; |
| 2155 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2156 | } |
| 2157 | |
| 2158 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2159 | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2160 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2161 | slice_ty p; |
| 2162 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2163 | if (!p) |
| 2164 | return NULL; |
| 2165 | p->kind = Slice_kind; |
| 2166 | p->v.Slice.lower = lower; |
| 2167 | p->v.Slice.upper = upper; |
| 2168 | p->v.Slice.step = step; |
| 2169 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2170 | } |
| 2171 | |
| 2172 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2173 | ExtSlice(asdl_seq * dims, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2174 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2175 | slice_ty p; |
| 2176 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2177 | if (!p) |
| 2178 | return NULL; |
| 2179 | p->kind = ExtSlice_kind; |
| 2180 | p->v.ExtSlice.dims = dims; |
| 2181 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2182 | } |
| 2183 | |
| 2184 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2185 | Index(expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2186 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2187 | slice_ty p; |
| 2188 | if (!value) { |
| 2189 | PyErr_SetString(PyExc_ValueError, |
| 2190 | "field value is required for Index"); |
| 2191 | return NULL; |
| 2192 | } |
| 2193 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2194 | if (!p) |
| 2195 | return NULL; |
| 2196 | p->kind = Index_kind; |
| 2197 | p->v.Index.value = value; |
| 2198 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2199 | } |
| 2200 | |
| 2201 | comprehension_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2202 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2203 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2204 | comprehension_ty p; |
| 2205 | if (!target) { |
| 2206 | PyErr_SetString(PyExc_ValueError, |
| 2207 | "field target is required for comprehension"); |
| 2208 | return NULL; |
| 2209 | } |
| 2210 | if (!iter) { |
| 2211 | PyErr_SetString(PyExc_ValueError, |
| 2212 | "field iter is required for comprehension"); |
| 2213 | return NULL; |
| 2214 | } |
| 2215 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2216 | if (!p) |
| 2217 | return NULL; |
| 2218 | p->target = target; |
| 2219 | p->iter = iter; |
| 2220 | p->ifs = ifs; |
| 2221 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2222 | } |
| 2223 | |
| 2224 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 2225 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2226 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2227 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2228 | excepthandler_ty p; |
| 2229 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2230 | if (!p) |
| 2231 | return NULL; |
| 2232 | p->kind = ExceptHandler_kind; |
| 2233 | p->v.ExceptHandler.type = type; |
| 2234 | p->v.ExceptHandler.name = name; |
| 2235 | p->v.ExceptHandler.body = body; |
| 2236 | p->lineno = lineno; |
| 2237 | p->col_offset = col_offset; |
| 2238 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2239 | } |
| 2240 | |
| 2241 | arguments_ty |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 2242 | arguments(asdl_seq * args, arg_ty vararg, asdl_seq * kwonlyargs, asdl_seq * |
| 2243 | kw_defaults, arg_ty kwarg, asdl_seq * defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2244 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2245 | arguments_ty p; |
| 2246 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2247 | if (!p) |
| 2248 | return NULL; |
| 2249 | p->args = args; |
| 2250 | p->vararg = vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2251 | p->kwonlyargs = kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2252 | p->kw_defaults = kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 2253 | p->kwarg = kwarg; |
| 2254 | p->defaults = defaults; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2255 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2256 | } |
| 2257 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2258 | arg_ty |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2259 | arg(identifier arg, expr_ty annotation, PyArena *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2260 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2261 | arg_ty p; |
| 2262 | if (!arg) { |
| 2263 | PyErr_SetString(PyExc_ValueError, |
| 2264 | "field arg is required for arg"); |
| 2265 | return NULL; |
| 2266 | } |
| 2267 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2268 | if (!p) |
| 2269 | return NULL; |
| 2270 | p->arg = arg; |
| 2271 | p->annotation = annotation; |
| 2272 | return p; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2273 | } |
| 2274 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2275 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2276 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2277 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2278 | keyword_ty p; |
| 2279 | if (!arg) { |
| 2280 | PyErr_SetString(PyExc_ValueError, |
| 2281 | "field arg is required for keyword"); |
| 2282 | return NULL; |
| 2283 | } |
| 2284 | if (!value) { |
| 2285 | PyErr_SetString(PyExc_ValueError, |
| 2286 | "field value is required for keyword"); |
| 2287 | return NULL; |
| 2288 | } |
| 2289 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2290 | if (!p) |
| 2291 | return NULL; |
| 2292 | p->arg = arg; |
| 2293 | p->value = value; |
| 2294 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2295 | } |
| 2296 | |
| 2297 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2298 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2299 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2300 | alias_ty p; |
| 2301 | if (!name) { |
| 2302 | PyErr_SetString(PyExc_ValueError, |
| 2303 | "field name is required for alias"); |
| 2304 | return NULL; |
| 2305 | } |
| 2306 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2307 | if (!p) |
| 2308 | return NULL; |
| 2309 | p->name = name; |
| 2310 | p->asname = asname; |
| 2311 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2312 | } |
| 2313 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2314 | withitem_ty |
| 2315 | withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) |
| 2316 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2317 | withitem_ty p; |
| 2318 | if (!context_expr) { |
| 2319 | PyErr_SetString(PyExc_ValueError, |
| 2320 | "field context_expr is required for withitem"); |
| 2321 | return NULL; |
| 2322 | } |
| 2323 | p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2324 | if (!p) |
| 2325 | return NULL; |
| 2326 | p->context_expr = context_expr; |
| 2327 | p->optional_vars = optional_vars; |
| 2328 | return p; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2329 | } |
| 2330 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2331 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2332 | PyObject* |
| 2333 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2334 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2335 | mod_ty o = (mod_ty)_o; |
| 2336 | PyObject *result = NULL, *value = NULL; |
| 2337 | if (!o) { |
| 2338 | Py_INCREF(Py_None); |
| 2339 | return Py_None; |
| 2340 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2341 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2342 | switch (o->kind) { |
| 2343 | case Module_kind: |
| 2344 | result = PyType_GenericNew(Module_type, NULL, NULL); |
| 2345 | if (!result) goto failed; |
| 2346 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 2347 | if (!value) goto failed; |
| 2348 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2349 | goto failed; |
| 2350 | Py_DECREF(value); |
| 2351 | break; |
| 2352 | case Interactive_kind: |
| 2353 | result = PyType_GenericNew(Interactive_type, NULL, NULL); |
| 2354 | if (!result) goto failed; |
| 2355 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 2356 | if (!value) goto failed; |
| 2357 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2358 | goto failed; |
| 2359 | Py_DECREF(value); |
| 2360 | break; |
| 2361 | case Expression_kind: |
| 2362 | result = PyType_GenericNew(Expression_type, NULL, NULL); |
| 2363 | if (!result) goto failed; |
| 2364 | value = ast2obj_expr(o->v.Expression.body); |
| 2365 | if (!value) goto failed; |
| 2366 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2367 | goto failed; |
| 2368 | Py_DECREF(value); |
| 2369 | break; |
| 2370 | case Suite_kind: |
| 2371 | result = PyType_GenericNew(Suite_type, NULL, NULL); |
| 2372 | if (!result) goto failed; |
| 2373 | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
| 2374 | if (!value) goto failed; |
| 2375 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2376 | goto failed; |
| 2377 | Py_DECREF(value); |
| 2378 | break; |
| 2379 | } |
| 2380 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2381 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2382 | Py_XDECREF(value); |
| 2383 | Py_XDECREF(result); |
| 2384 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2385 | } |
| 2386 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2387 | PyObject* |
| 2388 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2389 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2390 | stmt_ty o = (stmt_ty)_o; |
| 2391 | PyObject *result = NULL, *value = NULL; |
| 2392 | if (!o) { |
| 2393 | Py_INCREF(Py_None); |
| 2394 | return Py_None; |
| 2395 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2396 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2397 | switch (o->kind) { |
| 2398 | case FunctionDef_kind: |
| 2399 | result = PyType_GenericNew(FunctionDef_type, NULL, NULL); |
| 2400 | if (!result) goto failed; |
| 2401 | value = ast2obj_identifier(o->v.FunctionDef.name); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2402 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2403 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2404 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2405 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2406 | value = ast2obj_arguments(o->v.FunctionDef.args); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2407 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2408 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 2409 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2410 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2411 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 2412 | if (!value) goto failed; |
| 2413 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2414 | goto failed; |
| 2415 | Py_DECREF(value); |
| 2416 | value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr); |
| 2417 | if (!value) goto failed; |
| 2418 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2419 | goto failed; |
| 2420 | Py_DECREF(value); |
| 2421 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 2422 | if (!value) goto failed; |
| 2423 | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
| 2424 | goto failed; |
| 2425 | Py_DECREF(value); |
| 2426 | break; |
| 2427 | case ClassDef_kind: |
| 2428 | result = PyType_GenericNew(ClassDef_type, NULL, NULL); |
| 2429 | if (!result) goto failed; |
| 2430 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 2431 | if (!value) goto failed; |
| 2432 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2433 | goto failed; |
| 2434 | Py_DECREF(value); |
| 2435 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 2436 | if (!value) goto failed; |
| 2437 | if (_PyObject_SetAttrId(result, &PyId_bases, value) == -1) |
| 2438 | goto failed; |
| 2439 | Py_DECREF(value); |
| 2440 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 2441 | if (!value) goto failed; |
| 2442 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
| 2443 | goto failed; |
| 2444 | Py_DECREF(value); |
| 2445 | value = ast2obj_expr(o->v.ClassDef.starargs); |
| 2446 | if (!value) goto failed; |
| 2447 | if (_PyObject_SetAttrId(result, &PyId_starargs, value) == -1) |
| 2448 | goto failed; |
| 2449 | Py_DECREF(value); |
| 2450 | value = ast2obj_expr(o->v.ClassDef.kwargs); |
| 2451 | if (!value) goto failed; |
| 2452 | if (_PyObject_SetAttrId(result, &PyId_kwargs, value) == -1) |
| 2453 | goto failed; |
| 2454 | Py_DECREF(value); |
| 2455 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 2456 | if (!value) goto failed; |
| 2457 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2458 | goto failed; |
| 2459 | Py_DECREF(value); |
| 2460 | value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr); |
| 2461 | if (!value) goto failed; |
| 2462 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2463 | goto failed; |
| 2464 | Py_DECREF(value); |
| 2465 | break; |
| 2466 | case Return_kind: |
| 2467 | result = PyType_GenericNew(Return_type, NULL, NULL); |
| 2468 | if (!result) goto failed; |
| 2469 | value = ast2obj_expr(o->v.Return.value); |
| 2470 | if (!value) goto failed; |
| 2471 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2472 | goto failed; |
| 2473 | Py_DECREF(value); |
| 2474 | break; |
| 2475 | case Delete_kind: |
| 2476 | result = PyType_GenericNew(Delete_type, NULL, NULL); |
| 2477 | if (!result) goto failed; |
| 2478 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 2479 | if (!value) goto failed; |
| 2480 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
| 2481 | goto failed; |
| 2482 | Py_DECREF(value); |
| 2483 | break; |
| 2484 | case Assign_kind: |
| 2485 | result = PyType_GenericNew(Assign_type, NULL, NULL); |
| 2486 | if (!result) goto failed; |
| 2487 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 2488 | if (!value) goto failed; |
| 2489 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
| 2490 | goto failed; |
| 2491 | Py_DECREF(value); |
| 2492 | value = ast2obj_expr(o->v.Assign.value); |
| 2493 | if (!value) goto failed; |
| 2494 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2495 | goto failed; |
| 2496 | Py_DECREF(value); |
| 2497 | break; |
| 2498 | case AugAssign_kind: |
| 2499 | result = PyType_GenericNew(AugAssign_type, NULL, NULL); |
| 2500 | if (!result) goto failed; |
| 2501 | value = ast2obj_expr(o->v.AugAssign.target); |
| 2502 | if (!value) goto failed; |
| 2503 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2504 | goto failed; |
| 2505 | Py_DECREF(value); |
| 2506 | value = ast2obj_operator(o->v.AugAssign.op); |
| 2507 | if (!value) goto failed; |
| 2508 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 2509 | goto failed; |
| 2510 | Py_DECREF(value); |
| 2511 | value = ast2obj_expr(o->v.AugAssign.value); |
| 2512 | if (!value) goto failed; |
| 2513 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2514 | goto failed; |
| 2515 | Py_DECREF(value); |
| 2516 | break; |
| 2517 | case For_kind: |
| 2518 | result = PyType_GenericNew(For_type, NULL, NULL); |
| 2519 | if (!result) goto failed; |
| 2520 | value = ast2obj_expr(o->v.For.target); |
| 2521 | if (!value) goto failed; |
| 2522 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2523 | goto failed; |
| 2524 | Py_DECREF(value); |
| 2525 | value = ast2obj_expr(o->v.For.iter); |
| 2526 | if (!value) goto failed; |
| 2527 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 2528 | goto failed; |
| 2529 | Py_DECREF(value); |
| 2530 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 2531 | if (!value) goto failed; |
| 2532 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2533 | goto failed; |
| 2534 | Py_DECREF(value); |
| 2535 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 2536 | if (!value) goto failed; |
| 2537 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2538 | goto failed; |
| 2539 | Py_DECREF(value); |
| 2540 | break; |
| 2541 | case While_kind: |
| 2542 | result = PyType_GenericNew(While_type, NULL, NULL); |
| 2543 | if (!result) goto failed; |
| 2544 | value = ast2obj_expr(o->v.While.test); |
| 2545 | if (!value) goto failed; |
| 2546 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 2547 | goto failed; |
| 2548 | Py_DECREF(value); |
| 2549 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 2550 | if (!value) goto failed; |
| 2551 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2552 | goto failed; |
| 2553 | Py_DECREF(value); |
| 2554 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 2555 | if (!value) goto failed; |
| 2556 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2557 | goto failed; |
| 2558 | Py_DECREF(value); |
| 2559 | break; |
| 2560 | case If_kind: |
| 2561 | result = PyType_GenericNew(If_type, NULL, NULL); |
| 2562 | if (!result) goto failed; |
| 2563 | value = ast2obj_expr(o->v.If.test); |
| 2564 | if (!value) goto failed; |
| 2565 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 2566 | goto failed; |
| 2567 | Py_DECREF(value); |
| 2568 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 2569 | if (!value) goto failed; |
| 2570 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2571 | goto failed; |
| 2572 | Py_DECREF(value); |
| 2573 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 2574 | if (!value) goto failed; |
| 2575 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2576 | goto failed; |
| 2577 | Py_DECREF(value); |
| 2578 | break; |
| 2579 | case With_kind: |
| 2580 | result = PyType_GenericNew(With_type, NULL, NULL); |
| 2581 | if (!result) goto failed; |
| 2582 | value = ast2obj_list(o->v.With.items, ast2obj_withitem); |
| 2583 | if (!value) goto failed; |
| 2584 | if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) |
| 2585 | goto failed; |
| 2586 | Py_DECREF(value); |
| 2587 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 2588 | if (!value) goto failed; |
| 2589 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2590 | goto failed; |
| 2591 | Py_DECREF(value); |
| 2592 | break; |
| 2593 | case Raise_kind: |
| 2594 | result = PyType_GenericNew(Raise_type, NULL, NULL); |
| 2595 | if (!result) goto failed; |
| 2596 | value = ast2obj_expr(o->v.Raise.exc); |
| 2597 | if (!value) goto failed; |
| 2598 | if (_PyObject_SetAttrId(result, &PyId_exc, value) == -1) |
| 2599 | goto failed; |
| 2600 | Py_DECREF(value); |
| 2601 | value = ast2obj_expr(o->v.Raise.cause); |
| 2602 | if (!value) goto failed; |
| 2603 | if (_PyObject_SetAttrId(result, &PyId_cause, value) == -1) |
| 2604 | goto failed; |
| 2605 | Py_DECREF(value); |
| 2606 | break; |
| 2607 | case Try_kind: |
| 2608 | result = PyType_GenericNew(Try_type, NULL, NULL); |
| 2609 | if (!result) goto failed; |
| 2610 | value = ast2obj_list(o->v.Try.body, ast2obj_stmt); |
| 2611 | if (!value) goto failed; |
| 2612 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2613 | goto failed; |
| 2614 | Py_DECREF(value); |
| 2615 | value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); |
| 2616 | if (!value) goto failed; |
| 2617 | if (_PyObject_SetAttrId(result, &PyId_handlers, value) == -1) |
| 2618 | goto failed; |
| 2619 | Py_DECREF(value); |
| 2620 | value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); |
| 2621 | if (!value) goto failed; |
| 2622 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2623 | goto failed; |
| 2624 | Py_DECREF(value); |
| 2625 | value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); |
| 2626 | if (!value) goto failed; |
| 2627 | if (_PyObject_SetAttrId(result, &PyId_finalbody, value) == -1) |
| 2628 | goto failed; |
| 2629 | Py_DECREF(value); |
| 2630 | break; |
| 2631 | case Assert_kind: |
| 2632 | result = PyType_GenericNew(Assert_type, NULL, NULL); |
| 2633 | if (!result) goto failed; |
| 2634 | value = ast2obj_expr(o->v.Assert.test); |
| 2635 | if (!value) goto failed; |
| 2636 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 2637 | goto failed; |
| 2638 | Py_DECREF(value); |
| 2639 | value = ast2obj_expr(o->v.Assert.msg); |
| 2640 | if (!value) goto failed; |
| 2641 | if (_PyObject_SetAttrId(result, &PyId_msg, value) == -1) |
| 2642 | goto failed; |
| 2643 | Py_DECREF(value); |
| 2644 | break; |
| 2645 | case Import_kind: |
| 2646 | result = PyType_GenericNew(Import_type, NULL, NULL); |
| 2647 | if (!result) goto failed; |
| 2648 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 2649 | if (!value) goto failed; |
| 2650 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 2651 | goto failed; |
| 2652 | Py_DECREF(value); |
| 2653 | break; |
| 2654 | case ImportFrom_kind: |
| 2655 | result = PyType_GenericNew(ImportFrom_type, NULL, NULL); |
| 2656 | if (!result) goto failed; |
| 2657 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 2658 | if (!value) goto failed; |
| 2659 | if (_PyObject_SetAttrId(result, &PyId_module, value) == -1) |
| 2660 | goto failed; |
| 2661 | Py_DECREF(value); |
| 2662 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 2663 | if (!value) goto failed; |
| 2664 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 2665 | goto failed; |
| 2666 | Py_DECREF(value); |
| 2667 | value = ast2obj_int(o->v.ImportFrom.level); |
| 2668 | if (!value) goto failed; |
| 2669 | if (_PyObject_SetAttrId(result, &PyId_level, value) == -1) |
| 2670 | goto failed; |
| 2671 | Py_DECREF(value); |
| 2672 | break; |
| 2673 | case Global_kind: |
| 2674 | result = PyType_GenericNew(Global_type, NULL, NULL); |
| 2675 | if (!result) goto failed; |
| 2676 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 2677 | if (!value) goto failed; |
| 2678 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 2679 | goto failed; |
| 2680 | Py_DECREF(value); |
| 2681 | break; |
| 2682 | case Nonlocal_kind: |
| 2683 | result = PyType_GenericNew(Nonlocal_type, NULL, NULL); |
| 2684 | if (!result) goto failed; |
| 2685 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 2686 | if (!value) goto failed; |
| 2687 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 2688 | goto failed; |
| 2689 | Py_DECREF(value); |
| 2690 | break; |
| 2691 | case Expr_kind: |
| 2692 | result = PyType_GenericNew(Expr_type, NULL, NULL); |
| 2693 | if (!result) goto failed; |
| 2694 | value = ast2obj_expr(o->v.Expr.value); |
| 2695 | if (!value) goto failed; |
| 2696 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2697 | goto failed; |
| 2698 | Py_DECREF(value); |
| 2699 | break; |
| 2700 | case Pass_kind: |
| 2701 | result = PyType_GenericNew(Pass_type, NULL, NULL); |
| 2702 | if (!result) goto failed; |
| 2703 | break; |
| 2704 | case Break_kind: |
| 2705 | result = PyType_GenericNew(Break_type, NULL, NULL); |
| 2706 | if (!result) goto failed; |
| 2707 | break; |
| 2708 | case Continue_kind: |
| 2709 | result = PyType_GenericNew(Continue_type, NULL, NULL); |
| 2710 | if (!result) goto failed; |
| 2711 | break; |
| 2712 | } |
| 2713 | value = ast2obj_int(o->lineno); |
| 2714 | if (!value) goto failed; |
| 2715 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 2716 | goto failed; |
| 2717 | Py_DECREF(value); |
| 2718 | value = ast2obj_int(o->col_offset); |
| 2719 | if (!value) goto failed; |
| 2720 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 2721 | goto failed; |
| 2722 | Py_DECREF(value); |
| 2723 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2724 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2725 | Py_XDECREF(value); |
| 2726 | Py_XDECREF(result); |
| 2727 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2728 | } |
| 2729 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2730 | PyObject* |
| 2731 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2732 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2733 | expr_ty o = (expr_ty)_o; |
| 2734 | PyObject *result = NULL, *value = NULL; |
| 2735 | if (!o) { |
| 2736 | Py_INCREF(Py_None); |
| 2737 | return Py_None; |
| 2738 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2739 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2740 | switch (o->kind) { |
| 2741 | case BoolOp_kind: |
| 2742 | result = PyType_GenericNew(BoolOp_type, NULL, NULL); |
| 2743 | if (!result) goto failed; |
| 2744 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 2745 | if (!value) goto failed; |
| 2746 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 2747 | goto failed; |
| 2748 | Py_DECREF(value); |
| 2749 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 2750 | if (!value) goto failed; |
| 2751 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 2752 | goto failed; |
| 2753 | Py_DECREF(value); |
| 2754 | break; |
| 2755 | case BinOp_kind: |
| 2756 | result = PyType_GenericNew(BinOp_type, NULL, NULL); |
| 2757 | if (!result) goto failed; |
| 2758 | value = ast2obj_expr(o->v.BinOp.left); |
| 2759 | if (!value) goto failed; |
| 2760 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
| 2761 | goto failed; |
| 2762 | Py_DECREF(value); |
| 2763 | value = ast2obj_operator(o->v.BinOp.op); |
| 2764 | if (!value) goto failed; |
| 2765 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 2766 | goto failed; |
| 2767 | Py_DECREF(value); |
| 2768 | value = ast2obj_expr(o->v.BinOp.right); |
| 2769 | if (!value) goto failed; |
| 2770 | if (_PyObject_SetAttrId(result, &PyId_right, value) == -1) |
| 2771 | goto failed; |
| 2772 | Py_DECREF(value); |
| 2773 | break; |
| 2774 | case UnaryOp_kind: |
| 2775 | result = PyType_GenericNew(UnaryOp_type, NULL, NULL); |
| 2776 | if (!result) goto failed; |
| 2777 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 2778 | if (!value) goto failed; |
| 2779 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 2780 | goto failed; |
| 2781 | Py_DECREF(value); |
| 2782 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 2783 | if (!value) goto failed; |
| 2784 | if (_PyObject_SetAttrId(result, &PyId_operand, value) == -1) |
| 2785 | goto failed; |
| 2786 | Py_DECREF(value); |
| 2787 | break; |
| 2788 | case Lambda_kind: |
| 2789 | result = PyType_GenericNew(Lambda_type, NULL, NULL); |
| 2790 | if (!result) goto failed; |
| 2791 | value = ast2obj_arguments(o->v.Lambda.args); |
| 2792 | if (!value) goto failed; |
| 2793 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 2794 | goto failed; |
| 2795 | Py_DECREF(value); |
| 2796 | value = ast2obj_expr(o->v.Lambda.body); |
| 2797 | if (!value) goto failed; |
| 2798 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2799 | goto failed; |
| 2800 | Py_DECREF(value); |
| 2801 | break; |
| 2802 | case IfExp_kind: |
| 2803 | result = PyType_GenericNew(IfExp_type, NULL, NULL); |
| 2804 | if (!result) goto failed; |
| 2805 | value = ast2obj_expr(o->v.IfExp.test); |
| 2806 | if (!value) goto failed; |
| 2807 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 2808 | goto failed; |
| 2809 | Py_DECREF(value); |
| 2810 | value = ast2obj_expr(o->v.IfExp.body); |
| 2811 | if (!value) goto failed; |
| 2812 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2813 | goto failed; |
| 2814 | Py_DECREF(value); |
| 2815 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 2816 | if (!value) goto failed; |
| 2817 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2818 | goto failed; |
| 2819 | Py_DECREF(value); |
| 2820 | break; |
| 2821 | case Dict_kind: |
| 2822 | result = PyType_GenericNew(Dict_type, NULL, NULL); |
| 2823 | if (!result) goto failed; |
| 2824 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 2825 | if (!value) goto failed; |
| 2826 | if (_PyObject_SetAttrId(result, &PyId_keys, value) == -1) |
| 2827 | goto failed; |
| 2828 | Py_DECREF(value); |
| 2829 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 2830 | if (!value) goto failed; |
| 2831 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 2832 | goto failed; |
| 2833 | Py_DECREF(value); |
| 2834 | break; |
| 2835 | case Set_kind: |
| 2836 | result = PyType_GenericNew(Set_type, NULL, NULL); |
| 2837 | if (!result) goto failed; |
| 2838 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 2839 | if (!value) goto failed; |
| 2840 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 2841 | goto failed; |
| 2842 | Py_DECREF(value); |
| 2843 | break; |
| 2844 | case ListComp_kind: |
| 2845 | result = PyType_GenericNew(ListComp_type, NULL, NULL); |
| 2846 | if (!result) goto failed; |
| 2847 | value = ast2obj_expr(o->v.ListComp.elt); |
| 2848 | if (!value) goto failed; |
| 2849 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 2850 | goto failed; |
| 2851 | Py_DECREF(value); |
| 2852 | value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension); |
| 2853 | if (!value) goto failed; |
| 2854 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 2855 | goto failed; |
| 2856 | Py_DECREF(value); |
| 2857 | break; |
| 2858 | case SetComp_kind: |
| 2859 | result = PyType_GenericNew(SetComp_type, NULL, NULL); |
| 2860 | if (!result) goto failed; |
| 2861 | value = ast2obj_expr(o->v.SetComp.elt); |
| 2862 | if (!value) goto failed; |
| 2863 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 2864 | goto failed; |
| 2865 | Py_DECREF(value); |
| 2866 | value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension); |
| 2867 | if (!value) goto failed; |
| 2868 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 2869 | goto failed; |
| 2870 | Py_DECREF(value); |
| 2871 | break; |
| 2872 | case DictComp_kind: |
| 2873 | result = PyType_GenericNew(DictComp_type, NULL, NULL); |
| 2874 | if (!result) goto failed; |
| 2875 | value = ast2obj_expr(o->v.DictComp.key); |
| 2876 | if (!value) goto failed; |
| 2877 | if (_PyObject_SetAttrId(result, &PyId_key, value) == -1) |
| 2878 | goto failed; |
| 2879 | Py_DECREF(value); |
| 2880 | value = ast2obj_expr(o->v.DictComp.value); |
| 2881 | if (!value) goto failed; |
| 2882 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2883 | goto failed; |
| 2884 | Py_DECREF(value); |
| 2885 | value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension); |
| 2886 | if (!value) goto failed; |
| 2887 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 2888 | goto failed; |
| 2889 | Py_DECREF(value); |
| 2890 | break; |
| 2891 | case GeneratorExp_kind: |
| 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; |
| 2896 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 2897 | goto failed; |
| 2898 | Py_DECREF(value); |
| 2899 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 2900 | ast2obj_comprehension); |
| 2901 | if (!value) goto failed; |
| 2902 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 2903 | goto failed; |
| 2904 | Py_DECREF(value); |
| 2905 | break; |
| 2906 | case Yield_kind: |
| 2907 | result = PyType_GenericNew(Yield_type, NULL, NULL); |
| 2908 | if (!result) goto failed; |
| 2909 | value = ast2obj_expr(o->v.Yield.value); |
| 2910 | if (!value) goto failed; |
| 2911 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2912 | goto failed; |
| 2913 | Py_DECREF(value); |
| 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); |
| 2919 | if (!value) goto failed; |
| 2920 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2921 | goto failed; |
| 2922 | Py_DECREF(value); |
| 2923 | break; |
| 2924 | case Compare_kind: |
| 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; |
| 2929 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
| 2930 | goto failed; |
| 2931 | Py_DECREF(value); |
| 2932 | { |
| 2933 | Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 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))); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2938 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2939 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2940 | if (_PyObject_SetAttrId(result, &PyId_ops, value) == -1) |
| 2941 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2942 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2943 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2944 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2945 | if (_PyObject_SetAttrId(result, &PyId_comparators, value) == -1) |
| 2946 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2947 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2948 | break; |
| 2949 | case Call_kind: |
| 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; |
| 2954 | if (_PyObject_SetAttrId(result, &PyId_func, value) == -1) |
| 2955 | goto failed; |
| 2956 | Py_DECREF(value); |
| 2957 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 2958 | if (!value) goto failed; |
| 2959 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 2960 | goto failed; |
| 2961 | Py_DECREF(value); |
| 2962 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 2963 | if (!value) goto failed; |
| 2964 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
| 2965 | goto failed; |
| 2966 | Py_DECREF(value); |
| 2967 | value = ast2obj_expr(o->v.Call.starargs); |
| 2968 | if (!value) goto failed; |
| 2969 | if (_PyObject_SetAttrId(result, &PyId_starargs, value) == -1) |
| 2970 | goto failed; |
| 2971 | Py_DECREF(value); |
| 2972 | value = ast2obj_expr(o->v.Call.kwargs); |
| 2973 | if (!value) goto failed; |
| 2974 | if (_PyObject_SetAttrId(result, &PyId_kwargs, value) == -1) |
| 2975 | goto failed; |
| 2976 | Py_DECREF(value); |
| 2977 | break; |
| 2978 | case Num_kind: |
| 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; |
| 2983 | if (_PyObject_SetAttrId(result, &PyId_n, value) == -1) |
| 2984 | goto failed; |
| 2985 | Py_DECREF(value); |
| 2986 | break; |
| 2987 | case Str_kind: |
| 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; |
| 2992 | if (_PyObject_SetAttrId(result, &PyId_s, value) == -1) |
| 2993 | goto failed; |
| 2994 | Py_DECREF(value); |
| 2995 | break; |
| 2996 | case Bytes_kind: |
| 2997 | result = PyType_GenericNew(Bytes_type, NULL, NULL); |
| 2998 | if (!result) goto failed; |
| 2999 | value = ast2obj_bytes(o->v.Bytes.s); |
| 3000 | if (!value) goto failed; |
| 3001 | if (_PyObject_SetAttrId(result, &PyId_s, value) == -1) |
| 3002 | goto failed; |
| 3003 | Py_DECREF(value); |
| 3004 | break; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [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; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3014 | case Ellipsis_kind: |
| 3015 | result = PyType_GenericNew(Ellipsis_type, NULL, NULL); |
| 3016 | if (!result) goto failed; |
| 3017 | break; |
| 3018 | case Attribute_kind: |
| 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; |
| 3023 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3024 | goto failed; |
| 3025 | Py_DECREF(value); |
| 3026 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 3027 | if (!value) goto failed; |
| 3028 | if (_PyObject_SetAttrId(result, &PyId_attr, value) == -1) |
| 3029 | goto failed; |
| 3030 | Py_DECREF(value); |
| 3031 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 3032 | if (!value) goto failed; |
| 3033 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3034 | goto failed; |
| 3035 | Py_DECREF(value); |
| 3036 | break; |
| 3037 | case Subscript_kind: |
| 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; |
| 3042 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3043 | goto failed; |
| 3044 | Py_DECREF(value); |
| 3045 | value = ast2obj_slice(o->v.Subscript.slice); |
| 3046 | if (!value) goto failed; |
| 3047 | if (_PyObject_SetAttrId(result, &PyId_slice, value) == -1) |
| 3048 | goto failed; |
| 3049 | Py_DECREF(value); |
| 3050 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 3051 | if (!value) goto failed; |
| 3052 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3053 | goto failed; |
| 3054 | Py_DECREF(value); |
| 3055 | break; |
| 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; |
| 3061 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3062 | goto failed; |
| 3063 | Py_DECREF(value); |
| 3064 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 3065 | if (!value) goto failed; |
| 3066 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3067 | goto failed; |
| 3068 | Py_DECREF(value); |
| 3069 | break; |
| 3070 | case Name_kind: |
| 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; |
| 3075 | if (_PyObject_SetAttrId(result, &PyId_id, value) == -1) |
| 3076 | goto failed; |
| 3077 | Py_DECREF(value); |
| 3078 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 3079 | if (!value) goto failed; |
| 3080 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3081 | goto failed; |
| 3082 | Py_DECREF(value); |
| 3083 | break; |
| 3084 | case List_kind: |
| 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; |
| 3089 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3090 | goto failed; |
| 3091 | Py_DECREF(value); |
| 3092 | value = ast2obj_expr_context(o->v.List.ctx); |
| 3093 | if (!value) goto failed; |
| 3094 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3095 | goto failed; |
| 3096 | Py_DECREF(value); |
| 3097 | break; |
| 3098 | case Tuple_kind: |
| 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; |
| 3103 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3104 | goto failed; |
| 3105 | Py_DECREF(value); |
| 3106 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 3107 | if (!value) goto failed; |
| 3108 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3109 | goto failed; |
| 3110 | Py_DECREF(value); |
| 3111 | break; |
| 3112 | } |
| 3113 | value = ast2obj_int(o->lineno); |
| 3114 | if (!value) goto failed; |
| 3115 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3116 | goto failed; |
| 3117 | Py_DECREF(value); |
| 3118 | value = ast2obj_int(o->col_offset); |
| 3119 | if (!value) goto failed; |
| 3120 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3121 | goto failed; |
| 3122 | Py_DECREF(value); |
| 3123 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3124 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 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 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [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; |
| 3151 | default: |
| 3152 | /* should never happen, but just in case ... */ |
| 3153 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 3154 | return NULL; |
| 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 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [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 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3166 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3167 | switch (o->kind) { |
| 3168 | case Slice_kind: |
| 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; |
| 3173 | if (_PyObject_SetAttrId(result, &PyId_lower, value) == -1) |
| 3174 | goto failed; |
| 3175 | Py_DECREF(value); |
| 3176 | value = ast2obj_expr(o->v.Slice.upper); |
| 3177 | if (!value) goto failed; |
| 3178 | if (_PyObject_SetAttrId(result, &PyId_upper, value) == -1) |
| 3179 | goto failed; |
| 3180 | Py_DECREF(value); |
| 3181 | value = ast2obj_expr(o->v.Slice.step); |
| 3182 | if (!value) goto failed; |
| 3183 | if (_PyObject_SetAttrId(result, &PyId_step, value) == -1) |
| 3184 | goto failed; |
| 3185 | Py_DECREF(value); |
| 3186 | break; |
| 3187 | case ExtSlice_kind: |
| 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; |
| 3192 | if (_PyObject_SetAttrId(result, &PyId_dims, value) == -1) |
| 3193 | goto failed; |
| 3194 | Py_DECREF(value); |
| 3195 | break; |
| 3196 | case Index_kind: |
| 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; |
| 3201 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3202 | goto failed; |
| 3203 | Py_DECREF(value); |
| 3204 | break; |
| 3205 | } |
| 3206 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3207 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 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 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [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; |
| 3222 | default: |
| 3223 | /* should never happen, but just in case ... */ |
| 3224 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 3225 | return NULL; |
| 3226 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3227 | } |
| 3228 | PyObject* ast2obj_operator(operator_ty o) |
| 3229 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 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; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 3240 | case MatMult: |
| 3241 | Py_INCREF(MatMult_singleton); |
| 3242 | return MatMult_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3243 | case Div: |
| 3244 | Py_INCREF(Div_singleton); |
| 3245 | return Div_singleton; |
| 3246 | case Mod: |
| 3247 | Py_INCREF(Mod_singleton); |
| 3248 | return Mod_singleton; |
| 3249 | case Pow: |
| 3250 | Py_INCREF(Pow_singleton); |
| 3251 | return Pow_singleton; |
| 3252 | case LShift: |
| 3253 | Py_INCREF(LShift_singleton); |
| 3254 | return LShift_singleton; |
| 3255 | case RShift: |
| 3256 | Py_INCREF(RShift_singleton); |
| 3257 | return RShift_singleton; |
| 3258 | case BitOr: |
| 3259 | Py_INCREF(BitOr_singleton); |
| 3260 | return BitOr_singleton; |
| 3261 | case BitXor: |
| 3262 | Py_INCREF(BitXor_singleton); |
| 3263 | return BitXor_singleton; |
| 3264 | case BitAnd: |
| 3265 | Py_INCREF(BitAnd_singleton); |
| 3266 | return BitAnd_singleton; |
| 3267 | case FloorDiv: |
| 3268 | Py_INCREF(FloorDiv_singleton); |
| 3269 | return FloorDiv_singleton; |
| 3270 | default: |
| 3271 | /* should never happen, but just in case ... */ |
| 3272 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 3273 | return NULL; |
| 3274 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3275 | } |
| 3276 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 3277 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3278 | switch(o) { |
| 3279 | case Invert: |
| 3280 | Py_INCREF(Invert_singleton); |
| 3281 | return Invert_singleton; |
| 3282 | case Not: |
| 3283 | Py_INCREF(Not_singleton); |
| 3284 | return Not_singleton; |
| 3285 | case UAdd: |
| 3286 | Py_INCREF(UAdd_singleton); |
| 3287 | return UAdd_singleton; |
| 3288 | case USub: |
| 3289 | Py_INCREF(USub_singleton); |
| 3290 | return USub_singleton; |
| 3291 | default: |
| 3292 | /* should never happen, but just in case ... */ |
| 3293 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 3294 | return NULL; |
| 3295 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3296 | } |
| 3297 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 3298 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3299 | switch(o) { |
| 3300 | case Eq: |
| 3301 | Py_INCREF(Eq_singleton); |
| 3302 | return Eq_singleton; |
| 3303 | case NotEq: |
| 3304 | Py_INCREF(NotEq_singleton); |
| 3305 | return NotEq_singleton; |
| 3306 | case Lt: |
| 3307 | Py_INCREF(Lt_singleton); |
| 3308 | return Lt_singleton; |
| 3309 | case LtE: |
| 3310 | Py_INCREF(LtE_singleton); |
| 3311 | return LtE_singleton; |
| 3312 | case Gt: |
| 3313 | Py_INCREF(Gt_singleton); |
| 3314 | return Gt_singleton; |
| 3315 | case GtE: |
| 3316 | Py_INCREF(GtE_singleton); |
| 3317 | return GtE_singleton; |
| 3318 | case Is: |
| 3319 | Py_INCREF(Is_singleton); |
| 3320 | return Is_singleton; |
| 3321 | case IsNot: |
| 3322 | Py_INCREF(IsNot_singleton); |
| 3323 | return IsNot_singleton; |
| 3324 | case In: |
| 3325 | Py_INCREF(In_singleton); |
| 3326 | return In_singleton; |
| 3327 | case NotIn: |
| 3328 | Py_INCREF(NotIn_singleton); |
| 3329 | return NotIn_singleton; |
| 3330 | default: |
| 3331 | /* should never happen, but just in case ... */ |
| 3332 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 3333 | return NULL; |
| 3334 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3335 | } |
| 3336 | PyObject* |
| 3337 | ast2obj_comprehension(void* _o) |
| 3338 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3339 | comprehension_ty o = (comprehension_ty)_o; |
| 3340 | PyObject *result = NULL, *value = NULL; |
| 3341 | if (!o) { |
| 3342 | Py_INCREF(Py_None); |
| 3343 | return Py_None; |
| 3344 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3345 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3346 | result = PyType_GenericNew(comprehension_type, NULL, NULL); |
| 3347 | if (!result) return NULL; |
| 3348 | value = ast2obj_expr(o->target); |
| 3349 | if (!value) goto failed; |
| 3350 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 3351 | goto failed; |
| 3352 | Py_DECREF(value); |
| 3353 | value = ast2obj_expr(o->iter); |
| 3354 | if (!value) goto failed; |
| 3355 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 3356 | goto failed; |
| 3357 | Py_DECREF(value); |
| 3358 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 3359 | if (!value) goto failed; |
| 3360 | if (_PyObject_SetAttrId(result, &PyId_ifs, value) == -1) |
| 3361 | goto failed; |
| 3362 | Py_DECREF(value); |
| 3363 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3364 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3365 | Py_XDECREF(value); |
| 3366 | Py_XDECREF(result); |
| 3367 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3368 | } |
| 3369 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3370 | PyObject* |
| 3371 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3372 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3373 | excepthandler_ty o = (excepthandler_ty)_o; |
| 3374 | PyObject *result = NULL, *value = NULL; |
| 3375 | if (!o) { |
| 3376 | Py_INCREF(Py_None); |
| 3377 | return Py_None; |
| 3378 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3379 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3380 | switch (o->kind) { |
| 3381 | case ExceptHandler_kind: |
| 3382 | result = PyType_GenericNew(ExceptHandler_type, NULL, NULL); |
| 3383 | if (!result) goto failed; |
| 3384 | value = ast2obj_expr(o->v.ExceptHandler.type); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3385 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3386 | if (_PyObject_SetAttrId(result, &PyId_type, value) == -1) |
| 3387 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3388 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3389 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3390 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3391 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 3392 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3393 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3394 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 3395 | if (!value) goto failed; |
| 3396 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3397 | goto failed; |
| 3398 | Py_DECREF(value); |
| 3399 | break; |
| 3400 | } |
| 3401 | value = ast2obj_int(o->lineno); |
| 3402 | if (!value) goto failed; |
| 3403 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3404 | goto failed; |
| 3405 | Py_DECREF(value); |
| 3406 | value = ast2obj_int(o->col_offset); |
| 3407 | if (!value) goto failed; |
| 3408 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3409 | goto failed; |
| 3410 | Py_DECREF(value); |
| 3411 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3412 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3413 | Py_XDECREF(value); |
| 3414 | Py_XDECREF(result); |
| 3415 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3416 | } |
| 3417 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3418 | PyObject* |
| 3419 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3420 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3421 | arguments_ty o = (arguments_ty)_o; |
| 3422 | PyObject *result = NULL, *value = NULL; |
| 3423 | if (!o) { |
| 3424 | Py_INCREF(Py_None); |
| 3425 | return Py_None; |
| 3426 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3427 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3428 | result = PyType_GenericNew(arguments_type, NULL, NULL); |
| 3429 | if (!result) return NULL; |
| 3430 | value = ast2obj_list(o->args, ast2obj_arg); |
| 3431 | if (!value) goto failed; |
| 3432 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3433 | goto failed; |
| 3434 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3435 | value = ast2obj_arg(o->vararg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3436 | if (!value) goto failed; |
| 3437 | if (_PyObject_SetAttrId(result, &PyId_vararg, value) == -1) |
| 3438 | goto failed; |
| 3439 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3440 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
| 3441 | if (!value) goto failed; |
| 3442 | if (_PyObject_SetAttrId(result, &PyId_kwonlyargs, value) == -1) |
| 3443 | goto failed; |
| 3444 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3445 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3446 | if (!value) goto failed; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3447 | if (_PyObject_SetAttrId(result, &PyId_kw_defaults, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3448 | goto failed; |
| 3449 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3450 | value = ast2obj_arg(o->kwarg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3451 | if (!value) goto failed; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3452 | if (_PyObject_SetAttrId(result, &PyId_kwarg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3453 | goto failed; |
| 3454 | Py_DECREF(value); |
| 3455 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 3456 | if (!value) goto failed; |
| 3457 | if (_PyObject_SetAttrId(result, &PyId_defaults, value) == -1) |
| 3458 | goto failed; |
| 3459 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3460 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3461 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3462 | Py_XDECREF(value); |
| 3463 | Py_XDECREF(result); |
| 3464 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3465 | } |
| 3466 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3467 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3468 | ast2obj_arg(void* _o) |
| 3469 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3470 | arg_ty o = (arg_ty)_o; |
| 3471 | PyObject *result = NULL, *value = NULL; |
| 3472 | if (!o) { |
| 3473 | Py_INCREF(Py_None); |
| 3474 | return Py_None; |
| 3475 | } |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3476 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3477 | result = PyType_GenericNew(arg_type, NULL, NULL); |
| 3478 | if (!result) return NULL; |
| 3479 | value = ast2obj_identifier(o->arg); |
| 3480 | if (!value) goto failed; |
| 3481 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
| 3482 | goto failed; |
| 3483 | Py_DECREF(value); |
| 3484 | value = ast2obj_expr(o->annotation); |
| 3485 | if (!value) goto failed; |
| 3486 | if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) |
| 3487 | goto failed; |
| 3488 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3489 | value = ast2obj_int(o->lineno); |
| 3490 | if (!value) goto failed; |
| 3491 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3492 | goto failed; |
| 3493 | Py_DECREF(value); |
| 3494 | value = ast2obj_int(o->col_offset); |
| 3495 | if (!value) goto failed; |
| 3496 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3497 | goto failed; |
| 3498 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3499 | return result; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3500 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3501 | Py_XDECREF(value); |
| 3502 | Py_XDECREF(result); |
| 3503 | return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3504 | } |
| 3505 | |
| 3506 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3507 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3508 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3509 | keyword_ty o = (keyword_ty)_o; |
| 3510 | PyObject *result = NULL, *value = NULL; |
| 3511 | if (!o) { |
| 3512 | Py_INCREF(Py_None); |
| 3513 | return Py_None; |
| 3514 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3515 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3516 | result = PyType_GenericNew(keyword_type, NULL, NULL); |
| 3517 | if (!result) return NULL; |
| 3518 | value = ast2obj_identifier(o->arg); |
| 3519 | if (!value) goto failed; |
| 3520 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
| 3521 | goto failed; |
| 3522 | Py_DECREF(value); |
| 3523 | value = ast2obj_expr(o->value); |
| 3524 | if (!value) goto failed; |
| 3525 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3526 | goto failed; |
| 3527 | Py_DECREF(value); |
| 3528 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3529 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3530 | Py_XDECREF(value); |
| 3531 | Py_XDECREF(result); |
| 3532 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3533 | } |
| 3534 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3535 | PyObject* |
| 3536 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3537 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3538 | alias_ty o = (alias_ty)_o; |
| 3539 | PyObject *result = NULL, *value = NULL; |
| 3540 | if (!o) { |
| 3541 | Py_INCREF(Py_None); |
| 3542 | return Py_None; |
| 3543 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3544 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3545 | result = PyType_GenericNew(alias_type, NULL, NULL); |
| 3546 | if (!result) return NULL; |
| 3547 | value = ast2obj_identifier(o->name); |
| 3548 | if (!value) goto failed; |
| 3549 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 3550 | goto failed; |
| 3551 | Py_DECREF(value); |
| 3552 | value = ast2obj_identifier(o->asname); |
| 3553 | if (!value) goto failed; |
| 3554 | if (_PyObject_SetAttrId(result, &PyId_asname, value) == -1) |
| 3555 | goto failed; |
| 3556 | Py_DECREF(value); |
| 3557 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3558 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3559 | Py_XDECREF(value); |
| 3560 | Py_XDECREF(result); |
| 3561 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3562 | } |
| 3563 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3564 | PyObject* |
| 3565 | ast2obj_withitem(void* _o) |
| 3566 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3567 | withitem_ty o = (withitem_ty)_o; |
| 3568 | PyObject *result = NULL, *value = NULL; |
| 3569 | if (!o) { |
| 3570 | Py_INCREF(Py_None); |
| 3571 | return Py_None; |
| 3572 | } |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3573 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3574 | result = PyType_GenericNew(withitem_type, NULL, NULL); |
| 3575 | if (!result) return NULL; |
| 3576 | value = ast2obj_expr(o->context_expr); |
| 3577 | if (!value) goto failed; |
| 3578 | if (_PyObject_SetAttrId(result, &PyId_context_expr, value) == -1) |
| 3579 | goto failed; |
| 3580 | Py_DECREF(value); |
| 3581 | value = ast2obj_expr(o->optional_vars); |
| 3582 | if (!value) goto failed; |
| 3583 | if (_PyObject_SetAttrId(result, &PyId_optional_vars, value) == -1) |
| 3584 | goto failed; |
| 3585 | Py_DECREF(value); |
| 3586 | return result; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3587 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3588 | Py_XDECREF(value); |
| 3589 | Py_XDECREF(result); |
| 3590 | return NULL; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3591 | } |
| 3592 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3593 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3594 | int |
| 3595 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 3596 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3597 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3598 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3599 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3600 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3601 | if (obj == Py_None) { |
| 3602 | *out = NULL; |
| 3603 | return 0; |
| 3604 | } |
| 3605 | isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type); |
| 3606 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3607 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3608 | } |
| 3609 | if (isinstance) { |
| 3610 | asdl_seq* body; |
| 3611 | |
| 3612 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 3613 | int res; |
| 3614 | Py_ssize_t len; |
| 3615 | Py_ssize_t i; |
| 3616 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 3617 | if (tmp == NULL) goto failed; |
| 3618 | if (!PyList_Check(tmp)) { |
| 3619 | PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3620 | goto failed; |
| 3621 | } |
| 3622 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 3623 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3624 | if (body == NULL) goto failed; |
| 3625 | for (i = 0; i < len; i++) { |
| 3626 | stmt_ty value; |
| 3627 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3628 | if (res != 0) goto failed; |
| 3629 | asdl_seq_SET(body, i, value); |
| 3630 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 3631 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3632 | } else { |
| 3633 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 3634 | return 1; |
| 3635 | } |
| 3636 | *out = Module(body, arena); |
| 3637 | if (*out == NULL) goto failed; |
| 3638 | return 0; |
| 3639 | } |
| 3640 | isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type); |
| 3641 | if (isinstance == -1) { |
| 3642 | return 1; |
| 3643 | } |
| 3644 | if (isinstance) { |
| 3645 | asdl_seq* body; |
| 3646 | |
| 3647 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 3648 | int res; |
| 3649 | Py_ssize_t len; |
| 3650 | Py_ssize_t i; |
| 3651 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 3652 | if (tmp == NULL) goto failed; |
| 3653 | if (!PyList_Check(tmp)) { |
| 3654 | PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3655 | goto failed; |
| 3656 | } |
| 3657 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 3658 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3659 | if (body == NULL) goto failed; |
| 3660 | for (i = 0; i < len; i++) { |
| 3661 | stmt_ty value; |
| 3662 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3663 | if (res != 0) goto failed; |
| 3664 | asdl_seq_SET(body, i, value); |
| 3665 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 3666 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3667 | } else { |
| 3668 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 3669 | return 1; |
| 3670 | } |
| 3671 | *out = Interactive(body, arena); |
| 3672 | if (*out == NULL) goto failed; |
| 3673 | return 0; |
| 3674 | } |
| 3675 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type); |
| 3676 | if (isinstance == -1) { |
| 3677 | return 1; |
| 3678 | } |
| 3679 | if (isinstance) { |
| 3680 | expr_ty body; |
| 3681 | |
| 3682 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 3683 | int res; |
| 3684 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 3685 | if (tmp == NULL) goto failed; |
| 3686 | res = obj2ast_expr(tmp, &body, arena); |
| 3687 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 3688 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 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 | } |
| 3697 | isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type); |
| 3698 | if (isinstance == -1) { |
| 3699 | return 1; |
| 3700 | } |
| 3701 | if (isinstance) { |
| 3702 | asdl_seq* body; |
| 3703 | |
| 3704 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 3705 | int res; |
| 3706 | Py_ssize_t len; |
| 3707 | Py_ssize_t i; |
| 3708 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 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); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 3715 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 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 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 3723 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3724 | } else { |
| 3725 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite"); |
| 3726 | return 1; |
| 3727 | } |
| 3728 | *out = Suite(body, arena); |
| 3729 | if (*out == NULL) goto failed; |
| 3730 | return 0; |
| 3731 | } |
| 3732 | |
| 3733 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
| 3734 | failed: |
| 3735 | Py_XDECREF(tmp); |
| 3736 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3737 | } |
| 3738 | |
| 3739 | int |
| 3740 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 3741 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3742 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3743 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3744 | PyObject *tmp = NULL; |
| 3745 | int lineno; |
| 3746 | int col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3747 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3748 | if (obj == Py_None) { |
| 3749 | *out = NULL; |
| 3750 | return 0; |
| 3751 | } |
| 3752 | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
| 3753 | int res; |
| 3754 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
| 3755 | if (tmp == NULL) goto failed; |
| 3756 | res = obj2ast_int(tmp, &lineno, arena); |
| 3757 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 3758 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3759 | } else { |
| 3760 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3761 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3762 | } |
| 3763 | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
| 3764 | int res; |
| 3765 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
| 3766 | if (tmp == NULL) goto failed; |
| 3767 | res = obj2ast_int(tmp, &col_offset, arena); |
| 3768 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 3769 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3770 | } else { |
| 3771 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 3772 | return 1; |
| 3773 | } |
| 3774 | isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type); |
| 3775 | if (isinstance == -1) { |
| 3776 | return 1; |
| 3777 | } |
| 3778 | if (isinstance) { |
| 3779 | identifier name; |
| 3780 | arguments_ty args; |
| 3781 | asdl_seq* body; |
| 3782 | asdl_seq* decorator_list; |
| 3783 | expr_ty returns; |
| 3784 | |
| 3785 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
| 3786 | int res; |
| 3787 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
| 3788 | if (tmp == NULL) goto failed; |
| 3789 | res = obj2ast_identifier(tmp, &name, arena); |
| 3790 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 3791 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3792 | } else { |
| 3793 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 3794 | return 1; |
| 3795 | } |
| 3796 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
| 3797 | int res; |
| 3798 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
| 3799 | if (tmp == NULL) goto failed; |
| 3800 | res = obj2ast_arguments(tmp, &args, arena); |
| 3801 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 3802 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3803 | } else { |
| 3804 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 3805 | return 1; |
| 3806 | } |
| 3807 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 3808 | int res; |
| 3809 | Py_ssize_t len; |
| 3810 | Py_ssize_t i; |
| 3811 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 3812 | if (tmp == NULL) goto failed; |
| 3813 | if (!PyList_Check(tmp)) { |
| 3814 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3815 | goto failed; |
| 3816 | } |
| 3817 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 3818 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3819 | if (body == NULL) goto failed; |
| 3820 | for (i = 0; i < len; i++) { |
| 3821 | stmt_ty value; |
| 3822 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3823 | if (res != 0) goto failed; |
| 3824 | asdl_seq_SET(body, i, value); |
| 3825 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 3826 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3827 | } else { |
| 3828 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 3829 | return 1; |
| 3830 | } |
| 3831 | if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) { |
| 3832 | int res; |
| 3833 | Py_ssize_t len; |
| 3834 | Py_ssize_t i; |
| 3835 | tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); |
| 3836 | if (tmp == NULL) goto failed; |
| 3837 | if (!PyList_Check(tmp)) { |
| 3838 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3839 | goto failed; |
| 3840 | } |
| 3841 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 3842 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3843 | if (decorator_list == NULL) goto failed; |
| 3844 | for (i = 0; i < len; i++) { |
| 3845 | expr_ty value; |
| 3846 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3847 | if (res != 0) goto failed; |
| 3848 | asdl_seq_SET(decorator_list, i, value); |
| 3849 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 3850 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3851 | } else { |
| 3852 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 3853 | return 1; |
| 3854 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3855 | if (exists_not_none(obj, &PyId_returns)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3856 | int res; |
| 3857 | tmp = _PyObject_GetAttrId(obj, &PyId_returns); |
| 3858 | if (tmp == NULL) goto failed; |
| 3859 | res = obj2ast_expr(tmp, &returns, arena); |
| 3860 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 3861 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3862 | } else { |
| 3863 | returns = NULL; |
| 3864 | } |
| 3865 | *out = FunctionDef(name, args, body, decorator_list, returns, lineno, |
| 3866 | col_offset, arena); |
| 3867 | if (*out == NULL) goto failed; |
| 3868 | return 0; |
| 3869 | } |
| 3870 | isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type); |
| 3871 | if (isinstance == -1) { |
| 3872 | return 1; |
| 3873 | } |
| 3874 | if (isinstance) { |
| 3875 | identifier name; |
| 3876 | asdl_seq* bases; |
| 3877 | asdl_seq* keywords; |
| 3878 | expr_ty starargs; |
| 3879 | expr_ty kwargs; |
| 3880 | asdl_seq* body; |
| 3881 | asdl_seq* decorator_list; |
| 3882 | |
| 3883 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
| 3884 | int res; |
| 3885 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
| 3886 | if (tmp == NULL) goto failed; |
| 3887 | res = obj2ast_identifier(tmp, &name, arena); |
| 3888 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 3889 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3890 | } else { |
| 3891 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 3892 | return 1; |
| 3893 | } |
| 3894 | if (_PyObject_HasAttrId(obj, &PyId_bases)) { |
| 3895 | int res; |
| 3896 | Py_ssize_t len; |
| 3897 | Py_ssize_t i; |
| 3898 | tmp = _PyObject_GetAttrId(obj, &PyId_bases); |
| 3899 | if (tmp == NULL) goto failed; |
| 3900 | if (!PyList_Check(tmp)) { |
| 3901 | PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3902 | goto failed; |
| 3903 | } |
| 3904 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 3905 | bases = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3906 | if (bases == NULL) goto failed; |
| 3907 | for (i = 0; i < len; i++) { |
| 3908 | expr_ty value; |
| 3909 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3910 | if (res != 0) goto failed; |
| 3911 | asdl_seq_SET(bases, i, value); |
| 3912 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 3913 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3914 | } else { |
| 3915 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 3916 | return 1; |
| 3917 | } |
| 3918 | if (_PyObject_HasAttrId(obj, &PyId_keywords)) { |
| 3919 | int res; |
| 3920 | Py_ssize_t len; |
| 3921 | Py_ssize_t i; |
| 3922 | tmp = _PyObject_GetAttrId(obj, &PyId_keywords); |
| 3923 | if (tmp == NULL) goto failed; |
| 3924 | if (!PyList_Check(tmp)) { |
| 3925 | PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3926 | goto failed; |
| 3927 | } |
| 3928 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 3929 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3930 | if (keywords == NULL) goto failed; |
| 3931 | for (i = 0; i < len; i++) { |
| 3932 | keyword_ty value; |
| 3933 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3934 | if (res != 0) goto failed; |
| 3935 | asdl_seq_SET(keywords, i, value); |
| 3936 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 3937 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3938 | } else { |
| 3939 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 3940 | return 1; |
| 3941 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3942 | if (exists_not_none(obj, &PyId_starargs)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3943 | int res; |
| 3944 | tmp = _PyObject_GetAttrId(obj, &PyId_starargs); |
| 3945 | if (tmp == NULL) goto failed; |
| 3946 | res = obj2ast_expr(tmp, &starargs, arena); |
| 3947 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 3948 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3949 | } else { |
| 3950 | starargs = NULL; |
| 3951 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3952 | if (exists_not_none(obj, &PyId_kwargs)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3953 | int res; |
| 3954 | tmp = _PyObject_GetAttrId(obj, &PyId_kwargs); |
| 3955 | if (tmp == NULL) goto failed; |
| 3956 | res = obj2ast_expr(tmp, &kwargs, arena); |
| 3957 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 3958 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3959 | } else { |
| 3960 | kwargs = NULL; |
| 3961 | } |
| 3962 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 3963 | int res; |
| 3964 | Py_ssize_t len; |
| 3965 | Py_ssize_t i; |
| 3966 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 3967 | if (tmp == NULL) goto failed; |
| 3968 | if (!PyList_Check(tmp)) { |
| 3969 | PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3970 | goto failed; |
| 3971 | } |
| 3972 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 3973 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3974 | if (body == NULL) goto failed; |
| 3975 | for (i = 0; i < len; i++) { |
| 3976 | stmt_ty value; |
| 3977 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3978 | if (res != 0) goto failed; |
| 3979 | asdl_seq_SET(body, i, value); |
| 3980 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 3981 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3982 | } else { |
| 3983 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 3984 | return 1; |
| 3985 | } |
| 3986 | if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) { |
| 3987 | int res; |
| 3988 | Py_ssize_t len; |
| 3989 | Py_ssize_t i; |
| 3990 | tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); |
| 3991 | if (tmp == NULL) goto failed; |
| 3992 | if (!PyList_Check(tmp)) { |
| 3993 | PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3994 | goto failed; |
| 3995 | } |
| 3996 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 3997 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3998 | if (decorator_list == NULL) goto failed; |
| 3999 | for (i = 0; i < len; i++) { |
| 4000 | expr_ty value; |
| 4001 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4002 | if (res != 0) goto failed; |
| 4003 | asdl_seq_SET(decorator_list, i, value); |
| 4004 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4005 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4006 | } else { |
| 4007 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 4008 | return 1; |
| 4009 | } |
| 4010 | *out = ClassDef(name, bases, keywords, starargs, kwargs, body, |
| 4011 | decorator_list, lineno, col_offset, arena); |
| 4012 | if (*out == NULL) goto failed; |
| 4013 | return 0; |
| 4014 | } |
| 4015 | isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type); |
| 4016 | if (isinstance == -1) { |
| 4017 | return 1; |
| 4018 | } |
| 4019 | if (isinstance) { |
| 4020 | expr_ty value; |
| 4021 | |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4022 | if (exists_not_none(obj, &PyId_value)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4023 | int res; |
| 4024 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 4025 | if (tmp == NULL) goto failed; |
| 4026 | res = obj2ast_expr(tmp, &value, arena); |
| 4027 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4028 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4029 | } else { |
| 4030 | value = NULL; |
| 4031 | } |
| 4032 | *out = Return(value, lineno, col_offset, arena); |
| 4033 | if (*out == NULL) goto failed; |
| 4034 | return 0; |
| 4035 | } |
| 4036 | isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type); |
| 4037 | if (isinstance == -1) { |
| 4038 | return 1; |
| 4039 | } |
| 4040 | if (isinstance) { |
| 4041 | asdl_seq* targets; |
| 4042 | |
| 4043 | if (_PyObject_HasAttrId(obj, &PyId_targets)) { |
| 4044 | int res; |
| 4045 | Py_ssize_t len; |
| 4046 | Py_ssize_t i; |
| 4047 | tmp = _PyObject_GetAttrId(obj, &PyId_targets); |
| 4048 | if (tmp == NULL) goto failed; |
| 4049 | if (!PyList_Check(tmp)) { |
| 4050 | PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4051 | goto failed; |
| 4052 | } |
| 4053 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4054 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4055 | if (targets == NULL) goto failed; |
| 4056 | for (i = 0; i < len; i++) { |
| 4057 | expr_ty value; |
| 4058 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4059 | if (res != 0) goto failed; |
| 4060 | asdl_seq_SET(targets, i, value); |
| 4061 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4062 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4063 | } else { |
| 4064 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 4065 | return 1; |
| 4066 | } |
| 4067 | *out = Delete(targets, lineno, col_offset, arena); |
| 4068 | if (*out == NULL) goto failed; |
| 4069 | return 0; |
| 4070 | } |
| 4071 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type); |
| 4072 | if (isinstance == -1) { |
| 4073 | return 1; |
| 4074 | } |
| 4075 | if (isinstance) { |
| 4076 | asdl_seq* targets; |
| 4077 | expr_ty value; |
| 4078 | |
| 4079 | if (_PyObject_HasAttrId(obj, &PyId_targets)) { |
| 4080 | int res; |
| 4081 | Py_ssize_t len; |
| 4082 | Py_ssize_t i; |
| 4083 | tmp = _PyObject_GetAttrId(obj, &PyId_targets); |
| 4084 | if (tmp == NULL) goto failed; |
| 4085 | if (!PyList_Check(tmp)) { |
| 4086 | PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4087 | goto failed; |
| 4088 | } |
| 4089 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4090 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4091 | if (targets == NULL) goto failed; |
| 4092 | for (i = 0; i < len; i++) { |
| 4093 | expr_ty value; |
| 4094 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4095 | if (res != 0) goto failed; |
| 4096 | asdl_seq_SET(targets, i, value); |
| 4097 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4098 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4099 | } else { |
| 4100 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 4101 | return 1; |
| 4102 | } |
| 4103 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 4104 | int res; |
| 4105 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 4106 | if (tmp == NULL) goto failed; |
| 4107 | res = obj2ast_expr(tmp, &value, arena); |
| 4108 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4109 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4110 | } else { |
| 4111 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 4112 | return 1; |
| 4113 | } |
| 4114 | *out = Assign(targets, value, lineno, col_offset, arena); |
| 4115 | if (*out == NULL) goto failed; |
| 4116 | return 0; |
| 4117 | } |
| 4118 | isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type); |
| 4119 | if (isinstance == -1) { |
| 4120 | return 1; |
| 4121 | } |
| 4122 | if (isinstance) { |
| 4123 | expr_ty target; |
| 4124 | operator_ty op; |
| 4125 | expr_ty value; |
| 4126 | |
| 4127 | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
| 4128 | int res; |
| 4129 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
| 4130 | if (tmp == NULL) goto failed; |
| 4131 | res = obj2ast_expr(tmp, &target, arena); |
| 4132 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4133 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4134 | } else { |
| 4135 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 4136 | return 1; |
| 4137 | } |
| 4138 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
| 4139 | int res; |
| 4140 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
| 4141 | if (tmp == NULL) goto failed; |
| 4142 | res = obj2ast_operator(tmp, &op, arena); |
| 4143 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4144 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4145 | } else { |
| 4146 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 4147 | return 1; |
| 4148 | } |
| 4149 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 4150 | int res; |
| 4151 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 4152 | if (tmp == NULL) goto failed; |
| 4153 | res = obj2ast_expr(tmp, &value, arena); |
| 4154 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4155 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4156 | } else { |
| 4157 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 4158 | return 1; |
| 4159 | } |
| 4160 | *out = AugAssign(target, op, value, lineno, col_offset, arena); |
| 4161 | if (*out == NULL) goto failed; |
| 4162 | return 0; |
| 4163 | } |
| 4164 | isinstance = PyObject_IsInstance(obj, (PyObject*)For_type); |
| 4165 | if (isinstance == -1) { |
| 4166 | return 1; |
| 4167 | } |
| 4168 | if (isinstance) { |
| 4169 | expr_ty target; |
| 4170 | expr_ty iter; |
| 4171 | asdl_seq* body; |
| 4172 | asdl_seq* orelse; |
| 4173 | |
| 4174 | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
| 4175 | int res; |
| 4176 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
| 4177 | if (tmp == NULL) goto failed; |
| 4178 | res = obj2ast_expr(tmp, &target, arena); |
| 4179 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4180 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4181 | } else { |
| 4182 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 4183 | return 1; |
| 4184 | } |
| 4185 | if (_PyObject_HasAttrId(obj, &PyId_iter)) { |
| 4186 | int res; |
| 4187 | tmp = _PyObject_GetAttrId(obj, &PyId_iter); |
| 4188 | if (tmp == NULL) goto failed; |
| 4189 | res = obj2ast_expr(tmp, &iter, arena); |
| 4190 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4191 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4192 | } else { |
| 4193 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 4194 | return 1; |
| 4195 | } |
| 4196 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4197 | int res; |
| 4198 | Py_ssize_t len; |
| 4199 | Py_ssize_t i; |
| 4200 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4201 | if (tmp == NULL) goto failed; |
| 4202 | if (!PyList_Check(tmp)) { |
| 4203 | PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4204 | goto failed; |
| 4205 | } |
| 4206 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4207 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4208 | if (body == NULL) goto failed; |
| 4209 | for (i = 0; i < len; i++) { |
| 4210 | stmt_ty value; |
| 4211 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4212 | if (res != 0) goto failed; |
| 4213 | asdl_seq_SET(body, i, value); |
| 4214 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4215 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4216 | } else { |
| 4217 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 4218 | return 1; |
| 4219 | } |
| 4220 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
| 4221 | int res; |
| 4222 | Py_ssize_t len; |
| 4223 | Py_ssize_t i; |
| 4224 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
| 4225 | if (tmp == NULL) goto failed; |
| 4226 | if (!PyList_Check(tmp)) { |
| 4227 | PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4228 | goto failed; |
| 4229 | } |
| 4230 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4231 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4232 | if (orelse == 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(orelse, i, value); |
| 4238 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4239 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4240 | } else { |
| 4241 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 4242 | return 1; |
| 4243 | } |
| 4244 | *out = For(target, iter, body, orelse, lineno, col_offset, arena); |
| 4245 | if (*out == NULL) goto failed; |
| 4246 | return 0; |
| 4247 | } |
| 4248 | isinstance = PyObject_IsInstance(obj, (PyObject*)While_type); |
| 4249 | if (isinstance == -1) { |
| 4250 | return 1; |
| 4251 | } |
| 4252 | if (isinstance) { |
| 4253 | expr_ty test; |
| 4254 | asdl_seq* body; |
| 4255 | asdl_seq* orelse; |
| 4256 | |
| 4257 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
| 4258 | int res; |
| 4259 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
| 4260 | if (tmp == NULL) goto failed; |
| 4261 | res = obj2ast_expr(tmp, &test, arena); |
| 4262 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4263 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4264 | } else { |
| 4265 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 4266 | return 1; |
| 4267 | } |
| 4268 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4269 | int res; |
| 4270 | Py_ssize_t len; |
| 4271 | Py_ssize_t i; |
| 4272 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4273 | if (tmp == NULL) goto failed; |
| 4274 | if (!PyList_Check(tmp)) { |
| 4275 | PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4276 | goto failed; |
| 4277 | } |
| 4278 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4279 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4280 | if (body == NULL) goto failed; |
| 4281 | for (i = 0; i < len; i++) { |
| 4282 | stmt_ty value; |
| 4283 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4284 | if (res != 0) goto failed; |
| 4285 | asdl_seq_SET(body, i, value); |
| 4286 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4287 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4288 | } else { |
| 4289 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 4290 | return 1; |
| 4291 | } |
| 4292 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
| 4293 | int res; |
| 4294 | Py_ssize_t len; |
| 4295 | Py_ssize_t i; |
| 4296 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
| 4297 | if (tmp == NULL) goto failed; |
| 4298 | if (!PyList_Check(tmp)) { |
| 4299 | PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4300 | goto failed; |
| 4301 | } |
| 4302 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4303 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4304 | if (orelse == NULL) goto failed; |
| 4305 | for (i = 0; i < len; i++) { |
| 4306 | stmt_ty value; |
| 4307 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4308 | if (res != 0) goto failed; |
| 4309 | asdl_seq_SET(orelse, i, value); |
| 4310 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4311 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4312 | } else { |
| 4313 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 4314 | return 1; |
| 4315 | } |
| 4316 | *out = While(test, body, orelse, lineno, col_offset, arena); |
| 4317 | if (*out == NULL) goto failed; |
| 4318 | return 0; |
| 4319 | } |
| 4320 | isinstance = PyObject_IsInstance(obj, (PyObject*)If_type); |
| 4321 | if (isinstance == -1) { |
| 4322 | return 1; |
| 4323 | } |
| 4324 | if (isinstance) { |
| 4325 | expr_ty test; |
| 4326 | asdl_seq* body; |
| 4327 | asdl_seq* orelse; |
| 4328 | |
| 4329 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
| 4330 | int res; |
| 4331 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
| 4332 | if (tmp == NULL) goto failed; |
| 4333 | res = obj2ast_expr(tmp, &test, arena); |
| 4334 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4335 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4336 | } else { |
| 4337 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 4338 | return 1; |
| 4339 | } |
| 4340 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4341 | int res; |
| 4342 | Py_ssize_t len; |
| 4343 | Py_ssize_t i; |
| 4344 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4345 | if (tmp == NULL) goto failed; |
| 4346 | if (!PyList_Check(tmp)) { |
| 4347 | PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4348 | goto failed; |
| 4349 | } |
| 4350 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4351 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4352 | if (body == NULL) goto failed; |
| 4353 | for (i = 0; i < len; i++) { |
| 4354 | stmt_ty value; |
| 4355 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4356 | if (res != 0) goto failed; |
| 4357 | asdl_seq_SET(body, i, value); |
| 4358 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4359 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4360 | } else { |
| 4361 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 4362 | return 1; |
| 4363 | } |
| 4364 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
| 4365 | int res; |
| 4366 | Py_ssize_t len; |
| 4367 | Py_ssize_t i; |
| 4368 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
| 4369 | if (tmp == NULL) goto failed; |
| 4370 | if (!PyList_Check(tmp)) { |
| 4371 | PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4372 | goto failed; |
| 4373 | } |
| 4374 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4375 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4376 | if (orelse == NULL) goto failed; |
| 4377 | for (i = 0; i < len; i++) { |
| 4378 | stmt_ty value; |
| 4379 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4380 | if (res != 0) goto failed; |
| 4381 | asdl_seq_SET(orelse, i, value); |
| 4382 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4383 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4384 | } else { |
| 4385 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 4386 | return 1; |
| 4387 | } |
| 4388 | *out = If(test, body, orelse, lineno, col_offset, arena); |
| 4389 | if (*out == NULL) goto failed; |
| 4390 | return 0; |
| 4391 | } |
| 4392 | isinstance = PyObject_IsInstance(obj, (PyObject*)With_type); |
| 4393 | if (isinstance == -1) { |
| 4394 | return 1; |
| 4395 | } |
| 4396 | if (isinstance) { |
| 4397 | asdl_seq* items; |
| 4398 | asdl_seq* body; |
| 4399 | |
| 4400 | if (_PyObject_HasAttrId(obj, &PyId_items)) { |
| 4401 | int res; |
| 4402 | Py_ssize_t len; |
| 4403 | Py_ssize_t i; |
| 4404 | tmp = _PyObject_GetAttrId(obj, &PyId_items); |
| 4405 | if (tmp == NULL) goto failed; |
| 4406 | if (!PyList_Check(tmp)) { |
| 4407 | PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4408 | goto failed; |
| 4409 | } |
| 4410 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4411 | items = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4412 | if (items == NULL) goto failed; |
| 4413 | for (i = 0; i < len; i++) { |
| 4414 | withitem_ty value; |
| 4415 | res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4416 | if (res != 0) goto failed; |
| 4417 | asdl_seq_SET(items, i, value); |
| 4418 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4419 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4420 | } else { |
| 4421 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); |
| 4422 | return 1; |
| 4423 | } |
| 4424 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4425 | int res; |
| 4426 | Py_ssize_t len; |
| 4427 | Py_ssize_t i; |
| 4428 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4429 | if (tmp == NULL) goto failed; |
| 4430 | if (!PyList_Check(tmp)) { |
| 4431 | PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4432 | goto failed; |
| 4433 | } |
| 4434 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4435 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4436 | if (body == NULL) goto failed; |
| 4437 | for (i = 0; i < len; i++) { |
| 4438 | stmt_ty value; |
| 4439 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4440 | if (res != 0) goto failed; |
| 4441 | asdl_seq_SET(body, i, value); |
| 4442 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4443 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4444 | } else { |
| 4445 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 4446 | return 1; |
| 4447 | } |
| 4448 | *out = With(items, body, lineno, col_offset, arena); |
| 4449 | if (*out == NULL) goto failed; |
| 4450 | return 0; |
| 4451 | } |
| 4452 | isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type); |
| 4453 | if (isinstance == -1) { |
| 4454 | return 1; |
| 4455 | } |
| 4456 | if (isinstance) { |
| 4457 | expr_ty exc; |
| 4458 | expr_ty cause; |
| 4459 | |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4460 | if (exists_not_none(obj, &PyId_exc)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4461 | int res; |
| 4462 | tmp = _PyObject_GetAttrId(obj, &PyId_exc); |
| 4463 | if (tmp == NULL) goto failed; |
| 4464 | res = obj2ast_expr(tmp, &exc, arena); |
| 4465 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4466 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4467 | } else { |
| 4468 | exc = NULL; |
| 4469 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4470 | if (exists_not_none(obj, &PyId_cause)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4471 | int res; |
| 4472 | tmp = _PyObject_GetAttrId(obj, &PyId_cause); |
| 4473 | if (tmp == NULL) goto failed; |
| 4474 | res = obj2ast_expr(tmp, &cause, arena); |
| 4475 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4476 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4477 | } else { |
| 4478 | cause = NULL; |
| 4479 | } |
| 4480 | *out = Raise(exc, cause, lineno, col_offset, arena); |
| 4481 | if (*out == NULL) goto failed; |
| 4482 | return 0; |
| 4483 | } |
| 4484 | isinstance = PyObject_IsInstance(obj, (PyObject*)Try_type); |
| 4485 | if (isinstance == -1) { |
| 4486 | return 1; |
| 4487 | } |
| 4488 | if (isinstance) { |
| 4489 | asdl_seq* body; |
| 4490 | asdl_seq* handlers; |
| 4491 | asdl_seq* orelse; |
| 4492 | asdl_seq* finalbody; |
| 4493 | |
| 4494 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4495 | int res; |
| 4496 | Py_ssize_t len; |
| 4497 | Py_ssize_t i; |
| 4498 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4499 | if (tmp == NULL) goto failed; |
| 4500 | if (!PyList_Check(tmp)) { |
| 4501 | PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4502 | goto failed; |
| 4503 | } |
| 4504 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4505 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4506 | if (body == NULL) goto failed; |
| 4507 | for (i = 0; i < len; i++) { |
| 4508 | stmt_ty value; |
| 4509 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4510 | if (res != 0) goto failed; |
| 4511 | asdl_seq_SET(body, i, value); |
| 4512 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4513 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4514 | } else { |
| 4515 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); |
| 4516 | return 1; |
| 4517 | } |
| 4518 | if (_PyObject_HasAttrId(obj, &PyId_handlers)) { |
| 4519 | int res; |
| 4520 | Py_ssize_t len; |
| 4521 | Py_ssize_t i; |
| 4522 | tmp = _PyObject_GetAttrId(obj, &PyId_handlers); |
| 4523 | if (tmp == NULL) goto failed; |
| 4524 | if (!PyList_Check(tmp)) { |
| 4525 | PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4526 | goto failed; |
| 4527 | } |
| 4528 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4529 | handlers = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4530 | if (handlers == NULL) goto failed; |
| 4531 | for (i = 0; i < len; i++) { |
| 4532 | excepthandler_ty value; |
| 4533 | res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4534 | if (res != 0) goto failed; |
| 4535 | asdl_seq_SET(handlers, i, value); |
| 4536 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4537 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4538 | } else { |
| 4539 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); |
| 4540 | return 1; |
| 4541 | } |
| 4542 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
| 4543 | int res; |
| 4544 | Py_ssize_t len; |
| 4545 | Py_ssize_t i; |
| 4546 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
| 4547 | if (tmp == NULL) goto failed; |
| 4548 | if (!PyList_Check(tmp)) { |
| 4549 | PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4550 | goto failed; |
| 4551 | } |
| 4552 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4553 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4554 | if (orelse == NULL) goto failed; |
| 4555 | for (i = 0; i < len; i++) { |
| 4556 | stmt_ty value; |
| 4557 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4558 | if (res != 0) goto failed; |
| 4559 | asdl_seq_SET(orelse, i, value); |
| 4560 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4561 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4562 | } else { |
| 4563 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); |
| 4564 | return 1; |
| 4565 | } |
| 4566 | if (_PyObject_HasAttrId(obj, &PyId_finalbody)) { |
| 4567 | int res; |
| 4568 | Py_ssize_t len; |
| 4569 | Py_ssize_t i; |
| 4570 | tmp = _PyObject_GetAttrId(obj, &PyId_finalbody); |
| 4571 | if (tmp == NULL) goto failed; |
| 4572 | if (!PyList_Check(tmp)) { |
| 4573 | PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4574 | goto failed; |
| 4575 | } |
| 4576 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4577 | finalbody = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4578 | if (finalbody == NULL) goto failed; |
| 4579 | for (i = 0; i < len; i++) { |
| 4580 | stmt_ty value; |
| 4581 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4582 | if (res != 0) goto failed; |
| 4583 | asdl_seq_SET(finalbody, i, value); |
| 4584 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4585 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4586 | } else { |
| 4587 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); |
| 4588 | return 1; |
| 4589 | } |
| 4590 | *out = Try(body, handlers, orelse, finalbody, lineno, col_offset, |
| 4591 | arena); |
| 4592 | if (*out == NULL) goto failed; |
| 4593 | return 0; |
| 4594 | } |
| 4595 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type); |
| 4596 | if (isinstance == -1) { |
| 4597 | return 1; |
| 4598 | } |
| 4599 | if (isinstance) { |
| 4600 | expr_ty test; |
| 4601 | expr_ty msg; |
| 4602 | |
| 4603 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
| 4604 | int res; |
| 4605 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
| 4606 | if (tmp == NULL) goto failed; |
| 4607 | res = obj2ast_expr(tmp, &test, arena); |
| 4608 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4609 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4610 | } else { |
| 4611 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 4612 | return 1; |
| 4613 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4614 | if (exists_not_none(obj, &PyId_msg)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4615 | int res; |
| 4616 | tmp = _PyObject_GetAttrId(obj, &PyId_msg); |
| 4617 | if (tmp == NULL) goto failed; |
| 4618 | res = obj2ast_expr(tmp, &msg, arena); |
| 4619 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4620 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4621 | } else { |
| 4622 | msg = NULL; |
| 4623 | } |
| 4624 | *out = Assert(test, msg, lineno, col_offset, arena); |
| 4625 | if (*out == NULL) goto failed; |
| 4626 | return 0; |
| 4627 | } |
| 4628 | isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type); |
| 4629 | if (isinstance == -1) { |
| 4630 | return 1; |
| 4631 | } |
| 4632 | if (isinstance) { |
| 4633 | asdl_seq* names; |
| 4634 | |
| 4635 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
| 4636 | int res; |
| 4637 | Py_ssize_t len; |
| 4638 | Py_ssize_t i; |
| 4639 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
| 4640 | if (tmp == NULL) goto failed; |
| 4641 | if (!PyList_Check(tmp)) { |
| 4642 | PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4643 | goto failed; |
| 4644 | } |
| 4645 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4646 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4647 | if (names == NULL) goto failed; |
| 4648 | for (i = 0; i < len; i++) { |
| 4649 | alias_ty value; |
| 4650 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4651 | if (res != 0) goto failed; |
| 4652 | asdl_seq_SET(names, i, value); |
| 4653 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4654 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4655 | } else { |
| 4656 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 4657 | return 1; |
| 4658 | } |
| 4659 | *out = Import(names, lineno, col_offset, arena); |
| 4660 | if (*out == NULL) goto failed; |
| 4661 | return 0; |
| 4662 | } |
| 4663 | isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type); |
| 4664 | if (isinstance == -1) { |
| 4665 | return 1; |
| 4666 | } |
| 4667 | if (isinstance) { |
| 4668 | identifier module; |
| 4669 | asdl_seq* names; |
| 4670 | int level; |
| 4671 | |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4672 | if (exists_not_none(obj, &PyId_module)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4673 | int res; |
| 4674 | tmp = _PyObject_GetAttrId(obj, &PyId_module); |
| 4675 | if (tmp == NULL) goto failed; |
| 4676 | res = obj2ast_identifier(tmp, &module, arena); |
| 4677 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4678 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4679 | } else { |
| 4680 | module = NULL; |
| 4681 | } |
| 4682 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
| 4683 | int res; |
| 4684 | Py_ssize_t len; |
| 4685 | Py_ssize_t i; |
| 4686 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
| 4687 | if (tmp == NULL) goto failed; |
| 4688 | if (!PyList_Check(tmp)) { |
| 4689 | PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4690 | goto failed; |
| 4691 | } |
| 4692 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4693 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4694 | if (names == NULL) goto failed; |
| 4695 | for (i = 0; i < len; i++) { |
| 4696 | alias_ty value; |
| 4697 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4698 | if (res != 0) goto failed; |
| 4699 | asdl_seq_SET(names, i, value); |
| 4700 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4701 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4702 | } else { |
| 4703 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 4704 | return 1; |
| 4705 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4706 | if (exists_not_none(obj, &PyId_level)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4707 | int res; |
| 4708 | tmp = _PyObject_GetAttrId(obj, &PyId_level); |
| 4709 | if (tmp == NULL) goto failed; |
| 4710 | res = obj2ast_int(tmp, &level, arena); |
| 4711 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4712 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4713 | } else { |
| 4714 | level = 0; |
| 4715 | } |
| 4716 | *out = ImportFrom(module, names, level, lineno, col_offset, arena); |
| 4717 | if (*out == NULL) goto failed; |
| 4718 | return 0; |
| 4719 | } |
| 4720 | isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type); |
| 4721 | if (isinstance == -1) { |
| 4722 | return 1; |
| 4723 | } |
| 4724 | if (isinstance) { |
| 4725 | asdl_seq* names; |
| 4726 | |
| 4727 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
| 4728 | int res; |
| 4729 | Py_ssize_t len; |
| 4730 | Py_ssize_t i; |
| 4731 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
| 4732 | if (tmp == NULL) goto failed; |
| 4733 | if (!PyList_Check(tmp)) { |
| 4734 | PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4735 | goto failed; |
| 4736 | } |
| 4737 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4738 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4739 | if (names == NULL) goto failed; |
| 4740 | for (i = 0; i < len; i++) { |
| 4741 | identifier value; |
| 4742 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4743 | if (res != 0) goto failed; |
| 4744 | asdl_seq_SET(names, i, value); |
| 4745 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4746 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4747 | } else { |
| 4748 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 4749 | return 1; |
| 4750 | } |
| 4751 | *out = Global(names, lineno, col_offset, arena); |
| 4752 | if (*out == NULL) goto failed; |
| 4753 | return 0; |
| 4754 | } |
| 4755 | isinstance = PyObject_IsInstance(obj, (PyObject*)Nonlocal_type); |
| 4756 | if (isinstance == -1) { |
| 4757 | return 1; |
| 4758 | } |
| 4759 | if (isinstance) { |
| 4760 | asdl_seq* names; |
| 4761 | |
| 4762 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
| 4763 | int res; |
| 4764 | Py_ssize_t len; |
| 4765 | Py_ssize_t i; |
| 4766 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
| 4767 | if (tmp == NULL) goto failed; |
| 4768 | if (!PyList_Check(tmp)) { |
| 4769 | PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4770 | goto failed; |
| 4771 | } |
| 4772 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4773 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4774 | if (names == NULL) goto failed; |
| 4775 | for (i = 0; i < len; i++) { |
| 4776 | identifier value; |
| 4777 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4778 | if (res != 0) goto failed; |
| 4779 | asdl_seq_SET(names, i, value); |
| 4780 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4781 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4782 | } else { |
| 4783 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 4784 | return 1; |
| 4785 | } |
| 4786 | *out = Nonlocal(names, lineno, col_offset, arena); |
| 4787 | if (*out == NULL) goto failed; |
| 4788 | return 0; |
| 4789 | } |
| 4790 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type); |
| 4791 | if (isinstance == -1) { |
| 4792 | return 1; |
| 4793 | } |
| 4794 | if (isinstance) { |
| 4795 | expr_ty value; |
| 4796 | |
| 4797 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 4798 | int res; |
| 4799 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 4800 | if (tmp == NULL) goto failed; |
| 4801 | res = obj2ast_expr(tmp, &value, arena); |
| 4802 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4803 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4804 | } else { |
| 4805 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 4806 | return 1; |
| 4807 | } |
| 4808 | *out = Expr(value, lineno, col_offset, arena); |
| 4809 | if (*out == NULL) goto failed; |
| 4810 | return 0; |
| 4811 | } |
| 4812 | isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type); |
| 4813 | if (isinstance == -1) { |
| 4814 | return 1; |
| 4815 | } |
| 4816 | if (isinstance) { |
| 4817 | |
| 4818 | *out = Pass(lineno, col_offset, arena); |
| 4819 | if (*out == NULL) goto failed; |
| 4820 | return 0; |
| 4821 | } |
| 4822 | isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type); |
| 4823 | if (isinstance == -1) { |
| 4824 | return 1; |
| 4825 | } |
| 4826 | if (isinstance) { |
| 4827 | |
| 4828 | *out = Break(lineno, col_offset, arena); |
| 4829 | if (*out == NULL) goto failed; |
| 4830 | return 0; |
| 4831 | } |
| 4832 | isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type); |
| 4833 | if (isinstance == -1) { |
| 4834 | return 1; |
| 4835 | } |
| 4836 | if (isinstance) { |
| 4837 | |
| 4838 | *out = Continue(lineno, col_offset, arena); |
| 4839 | if (*out == NULL) goto failed; |
| 4840 | return 0; |
| 4841 | } |
| 4842 | |
| 4843 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
| 4844 | failed: |
| 4845 | Py_XDECREF(tmp); |
| 4846 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4847 | } |
| 4848 | |
| 4849 | int |
| 4850 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 4851 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4852 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4853 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4854 | PyObject *tmp = NULL; |
| 4855 | int lineno; |
| 4856 | int col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4857 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4858 | if (obj == Py_None) { |
| 4859 | *out = NULL; |
| 4860 | return 0; |
| 4861 | } |
| 4862 | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
| 4863 | int res; |
| 4864 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
| 4865 | if (tmp == NULL) goto failed; |
| 4866 | res = obj2ast_int(tmp, &lineno, arena); |
| 4867 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4868 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4869 | } else { |
| 4870 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4871 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4872 | } |
| 4873 | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
| 4874 | int res; |
| 4875 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
| 4876 | if (tmp == NULL) goto failed; |
| 4877 | res = obj2ast_int(tmp, &col_offset, arena); |
| 4878 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4879 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4880 | } else { |
| 4881 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 4882 | return 1; |
| 4883 | } |
| 4884 | isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type); |
| 4885 | if (isinstance == -1) { |
| 4886 | return 1; |
| 4887 | } |
| 4888 | if (isinstance) { |
| 4889 | boolop_ty op; |
| 4890 | asdl_seq* values; |
| 4891 | |
| 4892 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
| 4893 | int res; |
| 4894 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
| 4895 | if (tmp == NULL) goto failed; |
| 4896 | res = obj2ast_boolop(tmp, &op, arena); |
| 4897 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4898 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4899 | } else { |
| 4900 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 4901 | return 1; |
| 4902 | } |
| 4903 | if (_PyObject_HasAttrId(obj, &PyId_values)) { |
| 4904 | int res; |
| 4905 | Py_ssize_t len; |
| 4906 | Py_ssize_t i; |
| 4907 | tmp = _PyObject_GetAttrId(obj, &PyId_values); |
| 4908 | if (tmp == NULL) goto failed; |
| 4909 | if (!PyList_Check(tmp)) { |
| 4910 | PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4911 | goto failed; |
| 4912 | } |
| 4913 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4914 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4915 | if (values == NULL) goto failed; |
| 4916 | for (i = 0; i < len; i++) { |
| 4917 | expr_ty value; |
| 4918 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4919 | if (res != 0) goto failed; |
| 4920 | asdl_seq_SET(values, i, value); |
| 4921 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4922 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4923 | } else { |
| 4924 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 4925 | return 1; |
| 4926 | } |
| 4927 | *out = BoolOp(op, values, lineno, col_offset, arena); |
| 4928 | if (*out == NULL) goto failed; |
| 4929 | return 0; |
| 4930 | } |
| 4931 | isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type); |
| 4932 | if (isinstance == -1) { |
| 4933 | return 1; |
| 4934 | } |
| 4935 | if (isinstance) { |
| 4936 | expr_ty left; |
| 4937 | operator_ty op; |
| 4938 | expr_ty right; |
| 4939 | |
| 4940 | if (_PyObject_HasAttrId(obj, &PyId_left)) { |
| 4941 | int res; |
| 4942 | tmp = _PyObject_GetAttrId(obj, &PyId_left); |
| 4943 | if (tmp == NULL) goto failed; |
| 4944 | res = obj2ast_expr(tmp, &left, arena); |
| 4945 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4946 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4947 | } else { |
| 4948 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 4949 | return 1; |
| 4950 | } |
| 4951 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
| 4952 | int res; |
| 4953 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
| 4954 | if (tmp == NULL) goto failed; |
| 4955 | res = obj2ast_operator(tmp, &op, arena); |
| 4956 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4957 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4958 | } else { |
| 4959 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 4960 | return 1; |
| 4961 | } |
| 4962 | if (_PyObject_HasAttrId(obj, &PyId_right)) { |
| 4963 | int res; |
| 4964 | tmp = _PyObject_GetAttrId(obj, &PyId_right); |
| 4965 | if (tmp == NULL) goto failed; |
| 4966 | res = obj2ast_expr(tmp, &right, arena); |
| 4967 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4968 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4969 | } else { |
| 4970 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 4971 | return 1; |
| 4972 | } |
| 4973 | *out = BinOp(left, op, right, lineno, col_offset, arena); |
| 4974 | if (*out == NULL) goto failed; |
| 4975 | return 0; |
| 4976 | } |
| 4977 | isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type); |
| 4978 | if (isinstance == -1) { |
| 4979 | return 1; |
| 4980 | } |
| 4981 | if (isinstance) { |
| 4982 | unaryop_ty op; |
| 4983 | expr_ty operand; |
| 4984 | |
| 4985 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
| 4986 | int res; |
| 4987 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
| 4988 | if (tmp == NULL) goto failed; |
| 4989 | res = obj2ast_unaryop(tmp, &op, arena); |
| 4990 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4991 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4992 | } else { |
| 4993 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 4994 | return 1; |
| 4995 | } |
| 4996 | if (_PyObject_HasAttrId(obj, &PyId_operand)) { |
| 4997 | int res; |
| 4998 | tmp = _PyObject_GetAttrId(obj, &PyId_operand); |
| 4999 | if (tmp == NULL) goto failed; |
| 5000 | res = obj2ast_expr(tmp, &operand, arena); |
| 5001 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5002 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5003 | } else { |
| 5004 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 5005 | return 1; |
| 5006 | } |
| 5007 | *out = UnaryOp(op, operand, lineno, col_offset, arena); |
| 5008 | if (*out == NULL) goto failed; |
| 5009 | return 0; |
| 5010 | } |
| 5011 | isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type); |
| 5012 | if (isinstance == -1) { |
| 5013 | return 1; |
| 5014 | } |
| 5015 | if (isinstance) { |
| 5016 | arguments_ty args; |
| 5017 | expr_ty body; |
| 5018 | |
| 5019 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
| 5020 | int res; |
| 5021 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
| 5022 | if (tmp == NULL) goto failed; |
| 5023 | res = obj2ast_arguments(tmp, &args, arena); |
| 5024 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5025 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5026 | } else { |
| 5027 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 5028 | return 1; |
| 5029 | } |
| 5030 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 5031 | int res; |
| 5032 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 5033 | if (tmp == NULL) goto failed; |
| 5034 | res = obj2ast_expr(tmp, &body, arena); |
| 5035 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5036 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5037 | } else { |
| 5038 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 5039 | return 1; |
| 5040 | } |
| 5041 | *out = Lambda(args, body, lineno, col_offset, arena); |
| 5042 | if (*out == NULL) goto failed; |
| 5043 | return 0; |
| 5044 | } |
| 5045 | isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type); |
| 5046 | if (isinstance == -1) { |
| 5047 | return 1; |
| 5048 | } |
| 5049 | if (isinstance) { |
| 5050 | expr_ty test; |
| 5051 | expr_ty body; |
| 5052 | expr_ty orelse; |
| 5053 | |
| 5054 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
| 5055 | int res; |
| 5056 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
| 5057 | if (tmp == NULL) goto failed; |
| 5058 | res = obj2ast_expr(tmp, &test, arena); |
| 5059 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5060 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5061 | } else { |
| 5062 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 5063 | return 1; |
| 5064 | } |
| 5065 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 5066 | int res; |
| 5067 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 5068 | if (tmp == NULL) goto failed; |
| 5069 | res = obj2ast_expr(tmp, &body, arena); |
| 5070 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5071 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5072 | } else { |
| 5073 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 5074 | return 1; |
| 5075 | } |
| 5076 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
| 5077 | int res; |
| 5078 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
| 5079 | if (tmp == NULL) goto failed; |
| 5080 | res = obj2ast_expr(tmp, &orelse, arena); |
| 5081 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5082 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5083 | } else { |
| 5084 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 5085 | return 1; |
| 5086 | } |
| 5087 | *out = IfExp(test, body, orelse, lineno, col_offset, arena); |
| 5088 | if (*out == NULL) goto failed; |
| 5089 | return 0; |
| 5090 | } |
| 5091 | isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type); |
| 5092 | if (isinstance == -1) { |
| 5093 | return 1; |
| 5094 | } |
| 5095 | if (isinstance) { |
| 5096 | asdl_seq* keys; |
| 5097 | asdl_seq* values; |
| 5098 | |
| 5099 | if (_PyObject_HasAttrId(obj, &PyId_keys)) { |
| 5100 | int res; |
| 5101 | Py_ssize_t len; |
| 5102 | Py_ssize_t i; |
| 5103 | tmp = _PyObject_GetAttrId(obj, &PyId_keys); |
| 5104 | if (tmp == NULL) goto failed; |
| 5105 | if (!PyList_Check(tmp)) { |
| 5106 | PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5107 | goto failed; |
| 5108 | } |
| 5109 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5110 | keys = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5111 | if (keys == NULL) goto failed; |
| 5112 | for (i = 0; i < len; i++) { |
| 5113 | expr_ty value; |
| 5114 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5115 | if (res != 0) goto failed; |
| 5116 | asdl_seq_SET(keys, i, value); |
| 5117 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5118 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5119 | } else { |
| 5120 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 5121 | return 1; |
| 5122 | } |
| 5123 | if (_PyObject_HasAttrId(obj, &PyId_values)) { |
| 5124 | int res; |
| 5125 | Py_ssize_t len; |
| 5126 | Py_ssize_t i; |
| 5127 | tmp = _PyObject_GetAttrId(obj, &PyId_values); |
| 5128 | if (tmp == NULL) goto failed; |
| 5129 | if (!PyList_Check(tmp)) { |
| 5130 | PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5131 | goto failed; |
| 5132 | } |
| 5133 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5134 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5135 | if (values == NULL) goto failed; |
| 5136 | for (i = 0; i < len; i++) { |
| 5137 | expr_ty value; |
| 5138 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5139 | if (res != 0) goto failed; |
| 5140 | asdl_seq_SET(values, i, value); |
| 5141 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5142 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5143 | } else { |
| 5144 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 5145 | return 1; |
| 5146 | } |
| 5147 | *out = Dict(keys, values, lineno, col_offset, arena); |
| 5148 | if (*out == NULL) goto failed; |
| 5149 | return 0; |
| 5150 | } |
| 5151 | isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type); |
| 5152 | if (isinstance == -1) { |
| 5153 | return 1; |
| 5154 | } |
| 5155 | if (isinstance) { |
| 5156 | asdl_seq* elts; |
| 5157 | |
| 5158 | if (_PyObject_HasAttrId(obj, &PyId_elts)) { |
| 5159 | int res; |
| 5160 | Py_ssize_t len; |
| 5161 | Py_ssize_t i; |
| 5162 | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
| 5163 | if (tmp == NULL) goto failed; |
| 5164 | if (!PyList_Check(tmp)) { |
| 5165 | PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5166 | goto failed; |
| 5167 | } |
| 5168 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5169 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5170 | if (elts == NULL) goto failed; |
| 5171 | for (i = 0; i < len; i++) { |
| 5172 | expr_ty value; |
| 5173 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5174 | if (res != 0) goto failed; |
| 5175 | asdl_seq_SET(elts, i, value); |
| 5176 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5177 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5178 | } else { |
| 5179 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 5180 | return 1; |
| 5181 | } |
| 5182 | *out = Set(elts, lineno, col_offset, arena); |
| 5183 | if (*out == NULL) goto failed; |
| 5184 | return 0; |
| 5185 | } |
| 5186 | isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type); |
| 5187 | if (isinstance == -1) { |
| 5188 | return 1; |
| 5189 | } |
| 5190 | if (isinstance) { |
| 5191 | expr_ty elt; |
| 5192 | asdl_seq* generators; |
| 5193 | |
| 5194 | if (_PyObject_HasAttrId(obj, &PyId_elt)) { |
| 5195 | int res; |
| 5196 | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
| 5197 | if (tmp == NULL) goto failed; |
| 5198 | res = obj2ast_expr(tmp, &elt, arena); |
| 5199 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5200 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5201 | } else { |
| 5202 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 5203 | return 1; |
| 5204 | } |
| 5205 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
| 5206 | int res; |
| 5207 | Py_ssize_t len; |
| 5208 | Py_ssize_t i; |
| 5209 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
| 5210 | if (tmp == NULL) goto failed; |
| 5211 | if (!PyList_Check(tmp)) { |
| 5212 | PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5213 | goto failed; |
| 5214 | } |
| 5215 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5216 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5217 | if (generators == NULL) goto failed; |
| 5218 | for (i = 0; i < len; i++) { |
| 5219 | comprehension_ty value; |
| 5220 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5221 | if (res != 0) goto failed; |
| 5222 | asdl_seq_SET(generators, i, value); |
| 5223 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5224 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5225 | } else { |
| 5226 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 5227 | return 1; |
| 5228 | } |
| 5229 | *out = ListComp(elt, generators, lineno, col_offset, arena); |
| 5230 | if (*out == NULL) goto failed; |
| 5231 | return 0; |
| 5232 | } |
| 5233 | isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type); |
| 5234 | if (isinstance == -1) { |
| 5235 | return 1; |
| 5236 | } |
| 5237 | if (isinstance) { |
| 5238 | expr_ty elt; |
| 5239 | asdl_seq* generators; |
| 5240 | |
| 5241 | if (_PyObject_HasAttrId(obj, &PyId_elt)) { |
| 5242 | int res; |
| 5243 | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
| 5244 | if (tmp == NULL) goto failed; |
| 5245 | res = obj2ast_expr(tmp, &elt, arena); |
| 5246 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5247 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5248 | } else { |
| 5249 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 5250 | return 1; |
| 5251 | } |
| 5252 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
| 5253 | int res; |
| 5254 | Py_ssize_t len; |
| 5255 | Py_ssize_t i; |
| 5256 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
| 5257 | if (tmp == NULL) goto failed; |
| 5258 | if (!PyList_Check(tmp)) { |
| 5259 | PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5260 | goto failed; |
| 5261 | } |
| 5262 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5263 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5264 | if (generators == NULL) goto failed; |
| 5265 | for (i = 0; i < len; i++) { |
| 5266 | comprehension_ty value; |
| 5267 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5268 | if (res != 0) goto failed; |
| 5269 | asdl_seq_SET(generators, i, value); |
| 5270 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5271 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5272 | } else { |
| 5273 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 5274 | return 1; |
| 5275 | } |
| 5276 | *out = SetComp(elt, generators, lineno, col_offset, arena); |
| 5277 | if (*out == NULL) goto failed; |
| 5278 | return 0; |
| 5279 | } |
| 5280 | isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type); |
| 5281 | if (isinstance == -1) { |
| 5282 | return 1; |
| 5283 | } |
| 5284 | if (isinstance) { |
| 5285 | expr_ty key; |
| 5286 | expr_ty value; |
| 5287 | asdl_seq* generators; |
| 5288 | |
| 5289 | if (_PyObject_HasAttrId(obj, &PyId_key)) { |
| 5290 | int res; |
| 5291 | tmp = _PyObject_GetAttrId(obj, &PyId_key); |
| 5292 | if (tmp == NULL) goto failed; |
| 5293 | res = obj2ast_expr(tmp, &key, arena); |
| 5294 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5295 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5296 | } else { |
| 5297 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 5298 | return 1; |
| 5299 | } |
| 5300 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 5301 | int res; |
| 5302 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 5303 | if (tmp == NULL) goto failed; |
| 5304 | res = obj2ast_expr(tmp, &value, arena); |
| 5305 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5306 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5307 | } else { |
| 5308 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 5309 | return 1; |
| 5310 | } |
| 5311 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
| 5312 | int res; |
| 5313 | Py_ssize_t len; |
| 5314 | Py_ssize_t i; |
| 5315 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
| 5316 | if (tmp == NULL) goto failed; |
| 5317 | if (!PyList_Check(tmp)) { |
| 5318 | PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5319 | goto failed; |
| 5320 | } |
| 5321 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5322 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5323 | if (generators == NULL) goto failed; |
| 5324 | for (i = 0; i < len; i++) { |
| 5325 | comprehension_ty value; |
| 5326 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5327 | if (res != 0) goto failed; |
| 5328 | asdl_seq_SET(generators, i, value); |
| 5329 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5330 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5331 | } else { |
| 5332 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 5333 | return 1; |
| 5334 | } |
| 5335 | *out = DictComp(key, value, generators, lineno, col_offset, arena); |
| 5336 | if (*out == NULL) goto failed; |
| 5337 | return 0; |
| 5338 | } |
| 5339 | isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type); |
| 5340 | if (isinstance == -1) { |
| 5341 | return 1; |
| 5342 | } |
| 5343 | if (isinstance) { |
| 5344 | expr_ty elt; |
| 5345 | asdl_seq* generators; |
| 5346 | |
| 5347 | if (_PyObject_HasAttrId(obj, &PyId_elt)) { |
| 5348 | int res; |
| 5349 | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
| 5350 | if (tmp == NULL) goto failed; |
| 5351 | res = obj2ast_expr(tmp, &elt, arena); |
| 5352 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5353 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5354 | } else { |
| 5355 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 5356 | return 1; |
| 5357 | } |
| 5358 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
| 5359 | int res; |
| 5360 | Py_ssize_t len; |
| 5361 | Py_ssize_t i; |
| 5362 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
| 5363 | if (tmp == NULL) goto failed; |
| 5364 | if (!PyList_Check(tmp)) { |
| 5365 | PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5366 | goto failed; |
| 5367 | } |
| 5368 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5369 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5370 | if (generators == NULL) goto failed; |
| 5371 | for (i = 0; i < len; i++) { |
| 5372 | comprehension_ty value; |
| 5373 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5374 | if (res != 0) goto failed; |
| 5375 | asdl_seq_SET(generators, i, value); |
| 5376 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5377 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5378 | } else { |
| 5379 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 5380 | return 1; |
| 5381 | } |
| 5382 | *out = GeneratorExp(elt, generators, lineno, col_offset, arena); |
| 5383 | if (*out == NULL) goto failed; |
| 5384 | return 0; |
| 5385 | } |
| 5386 | isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); |
| 5387 | if (isinstance == -1) { |
| 5388 | return 1; |
| 5389 | } |
| 5390 | if (isinstance) { |
| 5391 | expr_ty value; |
| 5392 | |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 5393 | if (exists_not_none(obj, &PyId_value)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5394 | int res; |
| 5395 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 5396 | if (tmp == NULL) goto failed; |
| 5397 | res = obj2ast_expr(tmp, &value, arena); |
| 5398 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5399 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5400 | } else { |
| 5401 | value = NULL; |
| 5402 | } |
| 5403 | *out = Yield(value, lineno, col_offset, arena); |
| 5404 | if (*out == NULL) goto failed; |
| 5405 | return 0; |
| 5406 | } |
| 5407 | isinstance = PyObject_IsInstance(obj, (PyObject*)YieldFrom_type); |
| 5408 | if (isinstance == -1) { |
| 5409 | return 1; |
| 5410 | } |
| 5411 | if (isinstance) { |
| 5412 | expr_ty value; |
| 5413 | |
| 5414 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 5415 | int res; |
| 5416 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 5417 | if (tmp == NULL) goto failed; |
| 5418 | res = obj2ast_expr(tmp, &value, arena); |
| 5419 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5420 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5421 | } else { |
| 5422 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom"); |
| 5423 | return 1; |
| 5424 | } |
| 5425 | *out = YieldFrom(value, lineno, col_offset, arena); |
| 5426 | if (*out == NULL) goto failed; |
| 5427 | return 0; |
| 5428 | } |
| 5429 | isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); |
| 5430 | if (isinstance == -1) { |
| 5431 | return 1; |
| 5432 | } |
| 5433 | if (isinstance) { |
| 5434 | expr_ty left; |
| 5435 | asdl_int_seq* ops; |
| 5436 | asdl_seq* comparators; |
| 5437 | |
| 5438 | if (_PyObject_HasAttrId(obj, &PyId_left)) { |
| 5439 | int res; |
| 5440 | tmp = _PyObject_GetAttrId(obj, &PyId_left); |
| 5441 | if (tmp == NULL) goto failed; |
| 5442 | res = obj2ast_expr(tmp, &left, arena); |
| 5443 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5444 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5445 | } else { |
| 5446 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 5447 | return 1; |
| 5448 | } |
| 5449 | if (_PyObject_HasAttrId(obj, &PyId_ops)) { |
| 5450 | int res; |
| 5451 | Py_ssize_t len; |
| 5452 | Py_ssize_t i; |
| 5453 | tmp = _PyObject_GetAttrId(obj, &PyId_ops); |
| 5454 | if (tmp == NULL) goto failed; |
| 5455 | if (!PyList_Check(tmp)) { |
| 5456 | PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5457 | goto failed; |
| 5458 | } |
| 5459 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5460 | ops = _Py_asdl_int_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5461 | if (ops == NULL) goto failed; |
| 5462 | for (i = 0; i < len; i++) { |
| 5463 | cmpop_ty value; |
| 5464 | res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5465 | if (res != 0) goto failed; |
| 5466 | asdl_seq_SET(ops, i, value); |
| 5467 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5468 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5469 | } else { |
| 5470 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 5471 | return 1; |
| 5472 | } |
| 5473 | if (_PyObject_HasAttrId(obj, &PyId_comparators)) { |
| 5474 | int res; |
| 5475 | Py_ssize_t len; |
| 5476 | Py_ssize_t i; |
| 5477 | tmp = _PyObject_GetAttrId(obj, &PyId_comparators); |
| 5478 | if (tmp == NULL) goto failed; |
| 5479 | if (!PyList_Check(tmp)) { |
| 5480 | PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5481 | goto failed; |
| 5482 | } |
| 5483 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5484 | comparators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5485 | if (comparators == NULL) goto failed; |
| 5486 | for (i = 0; i < len; i++) { |
| 5487 | expr_ty value; |
| 5488 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5489 | if (res != 0) goto failed; |
| 5490 | asdl_seq_SET(comparators, i, value); |
| 5491 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5492 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5493 | } else { |
| 5494 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 5495 | return 1; |
| 5496 | } |
| 5497 | *out = Compare(left, ops, comparators, lineno, col_offset, arena); |
| 5498 | if (*out == NULL) goto failed; |
| 5499 | return 0; |
| 5500 | } |
| 5501 | isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type); |
| 5502 | if (isinstance == -1) { |
| 5503 | return 1; |
| 5504 | } |
| 5505 | if (isinstance) { |
| 5506 | expr_ty func; |
| 5507 | asdl_seq* args; |
| 5508 | asdl_seq* keywords; |
| 5509 | expr_ty starargs; |
| 5510 | expr_ty kwargs; |
| 5511 | |
| 5512 | if (_PyObject_HasAttrId(obj, &PyId_func)) { |
| 5513 | int res; |
| 5514 | tmp = _PyObject_GetAttrId(obj, &PyId_func); |
| 5515 | if (tmp == NULL) goto failed; |
| 5516 | res = obj2ast_expr(tmp, &func, arena); |
| 5517 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5518 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5519 | } else { |
| 5520 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 5521 | return 1; |
| 5522 | } |
| 5523 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
| 5524 | int res; |
| 5525 | Py_ssize_t len; |
| 5526 | Py_ssize_t i; |
| 5527 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
| 5528 | if (tmp == NULL) goto failed; |
| 5529 | if (!PyList_Check(tmp)) { |
| 5530 | PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5531 | goto failed; |
| 5532 | } |
| 5533 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5534 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5535 | if (args == NULL) goto failed; |
| 5536 | for (i = 0; i < len; i++) { |
| 5537 | expr_ty value; |
| 5538 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5539 | if (res != 0) goto failed; |
| 5540 | asdl_seq_SET(args, i, value); |
| 5541 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5542 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5543 | } else { |
| 5544 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 5545 | return 1; |
| 5546 | } |
| 5547 | if (_PyObject_HasAttrId(obj, &PyId_keywords)) { |
| 5548 | int res; |
| 5549 | Py_ssize_t len; |
| 5550 | Py_ssize_t i; |
| 5551 | tmp = _PyObject_GetAttrId(obj, &PyId_keywords); |
| 5552 | if (tmp == NULL) goto failed; |
| 5553 | if (!PyList_Check(tmp)) { |
| 5554 | PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5555 | goto failed; |
| 5556 | } |
| 5557 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5558 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5559 | if (keywords == NULL) goto failed; |
| 5560 | for (i = 0; i < len; i++) { |
| 5561 | keyword_ty value; |
| 5562 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5563 | if (res != 0) goto failed; |
| 5564 | asdl_seq_SET(keywords, i, value); |
| 5565 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5566 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5567 | } else { |
| 5568 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 5569 | return 1; |
| 5570 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 5571 | if (exists_not_none(obj, &PyId_starargs)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5572 | int res; |
| 5573 | tmp = _PyObject_GetAttrId(obj, &PyId_starargs); |
| 5574 | if (tmp == NULL) goto failed; |
| 5575 | res = obj2ast_expr(tmp, &starargs, arena); |
| 5576 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5577 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5578 | } else { |
| 5579 | starargs = NULL; |
| 5580 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 5581 | if (exists_not_none(obj, &PyId_kwargs)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5582 | int res; |
| 5583 | tmp = _PyObject_GetAttrId(obj, &PyId_kwargs); |
| 5584 | if (tmp == NULL) goto failed; |
| 5585 | res = obj2ast_expr(tmp, &kwargs, arena); |
| 5586 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5587 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5588 | } else { |
| 5589 | kwargs = NULL; |
| 5590 | } |
| 5591 | *out = Call(func, args, keywords, starargs, kwargs, lineno, col_offset, |
| 5592 | arena); |
| 5593 | if (*out == NULL) goto failed; |
| 5594 | return 0; |
| 5595 | } |
| 5596 | isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type); |
| 5597 | if (isinstance == -1) { |
| 5598 | return 1; |
| 5599 | } |
| 5600 | if (isinstance) { |
| 5601 | object n; |
| 5602 | |
| 5603 | if (_PyObject_HasAttrId(obj, &PyId_n)) { |
| 5604 | int res; |
| 5605 | tmp = _PyObject_GetAttrId(obj, &PyId_n); |
| 5606 | if (tmp == NULL) goto failed; |
| 5607 | res = obj2ast_object(tmp, &n, arena); |
| 5608 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5609 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5610 | } else { |
| 5611 | PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num"); |
| 5612 | return 1; |
| 5613 | } |
| 5614 | *out = Num(n, lineno, col_offset, arena); |
| 5615 | if (*out == NULL) goto failed; |
| 5616 | return 0; |
| 5617 | } |
| 5618 | isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type); |
| 5619 | if (isinstance == -1) { |
| 5620 | return 1; |
| 5621 | } |
| 5622 | if (isinstance) { |
| 5623 | string s; |
| 5624 | |
| 5625 | if (_PyObject_HasAttrId(obj, &PyId_s)) { |
| 5626 | int res; |
| 5627 | tmp = _PyObject_GetAttrId(obj, &PyId_s); |
| 5628 | if (tmp == NULL) goto failed; |
| 5629 | res = obj2ast_string(tmp, &s, arena); |
| 5630 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5631 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5632 | } else { |
| 5633 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str"); |
| 5634 | return 1; |
| 5635 | } |
| 5636 | *out = Str(s, lineno, col_offset, arena); |
| 5637 | if (*out == NULL) goto failed; |
| 5638 | return 0; |
| 5639 | } |
| 5640 | isinstance = PyObject_IsInstance(obj, (PyObject*)Bytes_type); |
| 5641 | if (isinstance == -1) { |
| 5642 | return 1; |
| 5643 | } |
| 5644 | if (isinstance) { |
| 5645 | bytes s; |
| 5646 | |
| 5647 | if (_PyObject_HasAttrId(obj, &PyId_s)) { |
| 5648 | int res; |
| 5649 | tmp = _PyObject_GetAttrId(obj, &PyId_s); |
| 5650 | if (tmp == NULL) goto failed; |
| 5651 | res = obj2ast_bytes(tmp, &s, arena); |
| 5652 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5653 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5654 | } else { |
| 5655 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Bytes"); |
| 5656 | return 1; |
| 5657 | } |
| 5658 | *out = Bytes(s, lineno, col_offset, arena); |
| 5659 | if (*out == NULL) goto failed; |
| 5660 | return 0; |
| 5661 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 5662 | isinstance = PyObject_IsInstance(obj, (PyObject*)NameConstant_type); |
| 5663 | if (isinstance == -1) { |
| 5664 | return 1; |
| 5665 | } |
| 5666 | if (isinstance) { |
| 5667 | singleton value; |
| 5668 | |
| 5669 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 5670 | int res; |
| 5671 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 5672 | if (tmp == NULL) goto failed; |
| 5673 | res = obj2ast_singleton(tmp, &value, arena); |
| 5674 | if (res != 0) goto failed; |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 5675 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 5676 | } else { |
| 5677 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NameConstant"); |
| 5678 | return 1; |
| 5679 | } |
| 5680 | *out = NameConstant(value, lineno, col_offset, arena); |
| 5681 | if (*out == NULL) goto failed; |
| 5682 | return 0; |
| 5683 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5684 | isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type); |
| 5685 | if (isinstance == -1) { |
| 5686 | return 1; |
| 5687 | } |
| 5688 | if (isinstance) { |
| 5689 | |
| 5690 | *out = Ellipsis(lineno, col_offset, arena); |
| 5691 | if (*out == NULL) goto failed; |
| 5692 | return 0; |
| 5693 | } |
| 5694 | isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type); |
| 5695 | if (isinstance == -1) { |
| 5696 | return 1; |
| 5697 | } |
| 5698 | if (isinstance) { |
| 5699 | expr_ty value; |
| 5700 | identifier attr; |
| 5701 | expr_context_ty ctx; |
| 5702 | |
| 5703 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 5704 | int res; |
| 5705 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 5706 | if (tmp == NULL) goto failed; |
| 5707 | res = obj2ast_expr(tmp, &value, arena); |
| 5708 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5709 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5710 | } else { |
| 5711 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 5712 | return 1; |
| 5713 | } |
| 5714 | if (_PyObject_HasAttrId(obj, &PyId_attr)) { |
| 5715 | int res; |
| 5716 | tmp = _PyObject_GetAttrId(obj, &PyId_attr); |
| 5717 | if (tmp == NULL) goto failed; |
| 5718 | res = obj2ast_identifier(tmp, &attr, arena); |
| 5719 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5720 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5721 | } else { |
| 5722 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 5723 | return 1; |
| 5724 | } |
| 5725 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
| 5726 | int res; |
| 5727 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
| 5728 | if (tmp == NULL) goto failed; |
| 5729 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5730 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5731 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5732 | } else { |
| 5733 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 5734 | return 1; |
| 5735 | } |
| 5736 | *out = Attribute(value, attr, ctx, lineno, col_offset, arena); |
| 5737 | if (*out == NULL) goto failed; |
| 5738 | return 0; |
| 5739 | } |
| 5740 | isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type); |
| 5741 | if (isinstance == -1) { |
| 5742 | return 1; |
| 5743 | } |
| 5744 | if (isinstance) { |
| 5745 | expr_ty value; |
| 5746 | slice_ty slice; |
| 5747 | expr_context_ty ctx; |
| 5748 | |
| 5749 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 5750 | int res; |
| 5751 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 5752 | if (tmp == NULL) goto failed; |
| 5753 | res = obj2ast_expr(tmp, &value, arena); |
| 5754 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5755 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5756 | } else { |
| 5757 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 5758 | return 1; |
| 5759 | } |
| 5760 | if (_PyObject_HasAttrId(obj, &PyId_slice)) { |
| 5761 | int res; |
| 5762 | tmp = _PyObject_GetAttrId(obj, &PyId_slice); |
| 5763 | if (tmp == NULL) goto failed; |
| 5764 | res = obj2ast_slice(tmp, &slice, arena); |
| 5765 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5766 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5767 | } else { |
| 5768 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 5769 | return 1; |
| 5770 | } |
| 5771 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
| 5772 | int res; |
| 5773 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
| 5774 | if (tmp == NULL) goto failed; |
| 5775 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5776 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5777 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5778 | } else { |
| 5779 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 5780 | return 1; |
| 5781 | } |
| 5782 | *out = Subscript(value, slice, ctx, lineno, col_offset, arena); |
| 5783 | if (*out == NULL) goto failed; |
| 5784 | return 0; |
| 5785 | } |
| 5786 | isinstance = PyObject_IsInstance(obj, (PyObject*)Starred_type); |
| 5787 | if (isinstance == -1) { |
| 5788 | return 1; |
| 5789 | } |
| 5790 | if (isinstance) { |
| 5791 | expr_ty value; |
| 5792 | expr_context_ty ctx; |
| 5793 | |
| 5794 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 5795 | int res; |
| 5796 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 5797 | if (tmp == NULL) goto failed; |
| 5798 | res = obj2ast_expr(tmp, &value, arena); |
| 5799 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5800 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5801 | } else { |
| 5802 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 5803 | return 1; |
| 5804 | } |
| 5805 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
| 5806 | int res; |
| 5807 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
| 5808 | if (tmp == NULL) goto failed; |
| 5809 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5810 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5811 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5812 | } else { |
| 5813 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 5814 | return 1; |
| 5815 | } |
| 5816 | *out = Starred(value, ctx, lineno, col_offset, arena); |
| 5817 | if (*out == NULL) goto failed; |
| 5818 | return 0; |
| 5819 | } |
| 5820 | isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type); |
| 5821 | if (isinstance == -1) { |
| 5822 | return 1; |
| 5823 | } |
| 5824 | if (isinstance) { |
| 5825 | identifier id; |
| 5826 | expr_context_ty ctx; |
| 5827 | |
| 5828 | if (_PyObject_HasAttrId(obj, &PyId_id)) { |
| 5829 | int res; |
| 5830 | tmp = _PyObject_GetAttrId(obj, &PyId_id); |
| 5831 | if (tmp == NULL) goto failed; |
| 5832 | res = obj2ast_identifier(tmp, &id, arena); |
| 5833 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5834 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5835 | } else { |
| 5836 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 5837 | return 1; |
| 5838 | } |
| 5839 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
| 5840 | int res; |
| 5841 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
| 5842 | if (tmp == NULL) goto failed; |
| 5843 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5844 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5845 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5846 | } else { |
| 5847 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 5848 | return 1; |
| 5849 | } |
| 5850 | *out = Name(id, ctx, lineno, col_offset, arena); |
| 5851 | if (*out == NULL) goto failed; |
| 5852 | return 0; |
| 5853 | } |
| 5854 | isinstance = PyObject_IsInstance(obj, (PyObject*)List_type); |
| 5855 | if (isinstance == -1) { |
| 5856 | return 1; |
| 5857 | } |
| 5858 | if (isinstance) { |
| 5859 | asdl_seq* elts; |
| 5860 | expr_context_ty ctx; |
| 5861 | |
| 5862 | if (_PyObject_HasAttrId(obj, &PyId_elts)) { |
| 5863 | int res; |
| 5864 | Py_ssize_t len; |
| 5865 | Py_ssize_t i; |
| 5866 | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
| 5867 | if (tmp == NULL) goto failed; |
| 5868 | if (!PyList_Check(tmp)) { |
| 5869 | PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5870 | goto failed; |
| 5871 | } |
| 5872 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5873 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5874 | if (elts == NULL) goto failed; |
| 5875 | for (i = 0; i < len; i++) { |
| 5876 | expr_ty value; |
| 5877 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5878 | if (res != 0) goto failed; |
| 5879 | asdl_seq_SET(elts, i, value); |
| 5880 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5881 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5882 | } else { |
| 5883 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 5884 | return 1; |
| 5885 | } |
| 5886 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
| 5887 | int res; |
| 5888 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
| 5889 | if (tmp == NULL) goto failed; |
| 5890 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5891 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5892 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5893 | } else { |
| 5894 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 5895 | return 1; |
| 5896 | } |
| 5897 | *out = List(elts, ctx, lineno, col_offset, arena); |
| 5898 | if (*out == NULL) goto failed; |
| 5899 | return 0; |
| 5900 | } |
| 5901 | isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type); |
| 5902 | if (isinstance == -1) { |
| 5903 | return 1; |
| 5904 | } |
| 5905 | if (isinstance) { |
| 5906 | asdl_seq* elts; |
| 5907 | expr_context_ty ctx; |
| 5908 | |
| 5909 | if (_PyObject_HasAttrId(obj, &PyId_elts)) { |
| 5910 | int res; |
| 5911 | Py_ssize_t len; |
| 5912 | Py_ssize_t i; |
| 5913 | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
| 5914 | if (tmp == NULL) goto failed; |
| 5915 | if (!PyList_Check(tmp)) { |
| 5916 | PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5917 | goto failed; |
| 5918 | } |
| 5919 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5920 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5921 | if (elts == NULL) goto failed; |
| 5922 | for (i = 0; i < len; i++) { |
| 5923 | expr_ty value; |
| 5924 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5925 | if (res != 0) goto failed; |
| 5926 | asdl_seq_SET(elts, i, value); |
| 5927 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5928 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5929 | } else { |
| 5930 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 5931 | return 1; |
| 5932 | } |
| 5933 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
| 5934 | int res; |
| 5935 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
| 5936 | if (tmp == NULL) goto failed; |
| 5937 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5938 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5939 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5940 | } else { |
| 5941 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 5942 | return 1; |
| 5943 | } |
| 5944 | *out = Tuple(elts, ctx, lineno, col_offset, arena); |
| 5945 | if (*out == NULL) goto failed; |
| 5946 | return 0; |
| 5947 | } |
| 5948 | |
| 5949 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
| 5950 | failed: |
| 5951 | Py_XDECREF(tmp); |
| 5952 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5953 | } |
| 5954 | |
| 5955 | int |
| 5956 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 5957 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5958 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5959 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5960 | isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); |
| 5961 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5962 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5963 | } |
| 5964 | if (isinstance) { |
| 5965 | *out = Load; |
| 5966 | return 0; |
| 5967 | } |
| 5968 | isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type); |
| 5969 | if (isinstance == -1) { |
| 5970 | return 1; |
| 5971 | } |
| 5972 | if (isinstance) { |
| 5973 | *out = Store; |
| 5974 | return 0; |
| 5975 | } |
| 5976 | isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type); |
| 5977 | if (isinstance == -1) { |
| 5978 | return 1; |
| 5979 | } |
| 5980 | if (isinstance) { |
| 5981 | *out = Del; |
| 5982 | return 0; |
| 5983 | } |
| 5984 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type); |
| 5985 | if (isinstance == -1) { |
| 5986 | return 1; |
| 5987 | } |
| 5988 | if (isinstance) { |
| 5989 | *out = AugLoad; |
| 5990 | return 0; |
| 5991 | } |
| 5992 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type); |
| 5993 | if (isinstance == -1) { |
| 5994 | return 1; |
| 5995 | } |
| 5996 | if (isinstance) { |
| 5997 | *out = AugStore; |
| 5998 | return 0; |
| 5999 | } |
| 6000 | isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type); |
| 6001 | if (isinstance == -1) { |
| 6002 | return 1; |
| 6003 | } |
| 6004 | if (isinstance) { |
| 6005 | *out = Param; |
| 6006 | return 0; |
| 6007 | } |
| 6008 | |
| 6009 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj); |
| 6010 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6011 | } |
| 6012 | |
| 6013 | int |
| 6014 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
| 6015 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6016 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6017 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6018 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6019 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6020 | if (obj == Py_None) { |
| 6021 | *out = NULL; |
| 6022 | return 0; |
| 6023 | } |
| 6024 | isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type); |
| 6025 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6026 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6027 | } |
| 6028 | if (isinstance) { |
| 6029 | expr_ty lower; |
| 6030 | expr_ty upper; |
| 6031 | expr_ty step; |
| 6032 | |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6033 | if (exists_not_none(obj, &PyId_lower)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6034 | int res; |
| 6035 | tmp = _PyObject_GetAttrId(obj, &PyId_lower); |
| 6036 | if (tmp == NULL) goto failed; |
| 6037 | res = obj2ast_expr(tmp, &lower, arena); |
| 6038 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6039 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6040 | } else { |
| 6041 | lower = NULL; |
| 6042 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6043 | if (exists_not_none(obj, &PyId_upper)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6044 | int res; |
| 6045 | tmp = _PyObject_GetAttrId(obj, &PyId_upper); |
| 6046 | if (tmp == NULL) goto failed; |
| 6047 | res = obj2ast_expr(tmp, &upper, arena); |
| 6048 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6049 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6050 | } else { |
| 6051 | upper = NULL; |
| 6052 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6053 | if (exists_not_none(obj, &PyId_step)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6054 | int res; |
| 6055 | tmp = _PyObject_GetAttrId(obj, &PyId_step); |
| 6056 | if (tmp == NULL) goto failed; |
| 6057 | res = obj2ast_expr(tmp, &step, arena); |
| 6058 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6059 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6060 | } else { |
| 6061 | step = NULL; |
| 6062 | } |
| 6063 | *out = Slice(lower, upper, step, arena); |
| 6064 | if (*out == NULL) goto failed; |
| 6065 | return 0; |
| 6066 | } |
| 6067 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type); |
| 6068 | if (isinstance == -1) { |
| 6069 | return 1; |
| 6070 | } |
| 6071 | if (isinstance) { |
| 6072 | asdl_seq* dims; |
| 6073 | |
| 6074 | if (_PyObject_HasAttrId(obj, &PyId_dims)) { |
| 6075 | int res; |
| 6076 | Py_ssize_t len; |
| 6077 | Py_ssize_t i; |
| 6078 | tmp = _PyObject_GetAttrId(obj, &PyId_dims); |
| 6079 | if (tmp == NULL) goto failed; |
| 6080 | if (!PyList_Check(tmp)) { |
| 6081 | PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6082 | goto failed; |
| 6083 | } |
| 6084 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6085 | dims = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6086 | if (dims == NULL) goto failed; |
| 6087 | for (i = 0; i < len; i++) { |
| 6088 | slice_ty value; |
| 6089 | res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6090 | if (res != 0) goto failed; |
| 6091 | asdl_seq_SET(dims, i, value); |
| 6092 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6093 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6094 | } else { |
| 6095 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
| 6096 | return 1; |
| 6097 | } |
| 6098 | *out = ExtSlice(dims, arena); |
| 6099 | if (*out == NULL) goto failed; |
| 6100 | return 0; |
| 6101 | } |
| 6102 | isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type); |
| 6103 | if (isinstance == -1) { |
| 6104 | return 1; |
| 6105 | } |
| 6106 | if (isinstance) { |
| 6107 | expr_ty value; |
| 6108 | |
| 6109 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 6110 | int res; |
| 6111 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 6112 | if (tmp == NULL) goto failed; |
| 6113 | res = obj2ast_expr(tmp, &value, arena); |
| 6114 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6115 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6116 | } else { |
| 6117 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
| 6118 | return 1; |
| 6119 | } |
| 6120 | *out = Index(value, arena); |
| 6121 | if (*out == NULL) goto failed; |
| 6122 | return 0; |
| 6123 | } |
| 6124 | |
| 6125 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj); |
| 6126 | failed: |
| 6127 | Py_XDECREF(tmp); |
| 6128 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6129 | } |
| 6130 | |
| 6131 | int |
| 6132 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 6133 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6134 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6135 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6136 | isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); |
| 6137 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6138 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6139 | } |
| 6140 | if (isinstance) { |
| 6141 | *out = And; |
| 6142 | return 0; |
| 6143 | } |
| 6144 | isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type); |
| 6145 | if (isinstance == -1) { |
| 6146 | return 1; |
| 6147 | } |
| 6148 | if (isinstance) { |
| 6149 | *out = Or; |
| 6150 | return 0; |
| 6151 | } |
| 6152 | |
| 6153 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj); |
| 6154 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6155 | } |
| 6156 | |
| 6157 | int |
| 6158 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 6159 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6160 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6161 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6162 | isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); |
| 6163 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6164 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6165 | } |
| 6166 | if (isinstance) { |
| 6167 | *out = Add; |
| 6168 | return 0; |
| 6169 | } |
| 6170 | isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type); |
| 6171 | if (isinstance == -1) { |
| 6172 | return 1; |
| 6173 | } |
| 6174 | if (isinstance) { |
| 6175 | *out = Sub; |
| 6176 | return 0; |
| 6177 | } |
| 6178 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type); |
| 6179 | if (isinstance == -1) { |
| 6180 | return 1; |
| 6181 | } |
| 6182 | if (isinstance) { |
| 6183 | *out = Mult; |
| 6184 | return 0; |
| 6185 | } |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 6186 | isinstance = PyObject_IsInstance(obj, (PyObject *)MatMult_type); |
| 6187 | if (isinstance == -1) { |
| 6188 | return 1; |
| 6189 | } |
| 6190 | if (isinstance) { |
| 6191 | *out = MatMult; |
| 6192 | return 0; |
| 6193 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6194 | isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type); |
| 6195 | if (isinstance == -1) { |
| 6196 | return 1; |
| 6197 | } |
| 6198 | if (isinstance) { |
| 6199 | *out = Div; |
| 6200 | return 0; |
| 6201 | } |
| 6202 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type); |
| 6203 | if (isinstance == -1) { |
| 6204 | return 1; |
| 6205 | } |
| 6206 | if (isinstance) { |
| 6207 | *out = Mod; |
| 6208 | return 0; |
| 6209 | } |
| 6210 | isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type); |
| 6211 | if (isinstance == -1) { |
| 6212 | return 1; |
| 6213 | } |
| 6214 | if (isinstance) { |
| 6215 | *out = Pow; |
| 6216 | return 0; |
| 6217 | } |
| 6218 | isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type); |
| 6219 | if (isinstance == -1) { |
| 6220 | return 1; |
| 6221 | } |
| 6222 | if (isinstance) { |
| 6223 | *out = LShift; |
| 6224 | return 0; |
| 6225 | } |
| 6226 | isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type); |
| 6227 | if (isinstance == -1) { |
| 6228 | return 1; |
| 6229 | } |
| 6230 | if (isinstance) { |
| 6231 | *out = RShift; |
| 6232 | return 0; |
| 6233 | } |
| 6234 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type); |
| 6235 | if (isinstance == -1) { |
| 6236 | return 1; |
| 6237 | } |
| 6238 | if (isinstance) { |
| 6239 | *out = BitOr; |
| 6240 | return 0; |
| 6241 | } |
| 6242 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type); |
| 6243 | if (isinstance == -1) { |
| 6244 | return 1; |
| 6245 | } |
| 6246 | if (isinstance) { |
| 6247 | *out = BitXor; |
| 6248 | return 0; |
| 6249 | } |
| 6250 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type); |
| 6251 | if (isinstance == -1) { |
| 6252 | return 1; |
| 6253 | } |
| 6254 | if (isinstance) { |
| 6255 | *out = BitAnd; |
| 6256 | return 0; |
| 6257 | } |
| 6258 | isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type); |
| 6259 | if (isinstance == -1) { |
| 6260 | return 1; |
| 6261 | } |
| 6262 | if (isinstance) { |
| 6263 | *out = FloorDiv; |
| 6264 | return 0; |
| 6265 | } |
| 6266 | |
| 6267 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj); |
| 6268 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6269 | } |
| 6270 | |
| 6271 | int |
| 6272 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 6273 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6274 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6275 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6276 | isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); |
| 6277 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6278 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6279 | } |
| 6280 | if (isinstance) { |
| 6281 | *out = Invert; |
| 6282 | return 0; |
| 6283 | } |
| 6284 | isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type); |
| 6285 | if (isinstance == -1) { |
| 6286 | return 1; |
| 6287 | } |
| 6288 | if (isinstance) { |
| 6289 | *out = Not; |
| 6290 | return 0; |
| 6291 | } |
| 6292 | isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type); |
| 6293 | if (isinstance == -1) { |
| 6294 | return 1; |
| 6295 | } |
| 6296 | if (isinstance) { |
| 6297 | *out = UAdd; |
| 6298 | return 0; |
| 6299 | } |
| 6300 | isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type); |
| 6301 | if (isinstance == -1) { |
| 6302 | return 1; |
| 6303 | } |
| 6304 | if (isinstance) { |
| 6305 | *out = USub; |
| 6306 | return 0; |
| 6307 | } |
| 6308 | |
| 6309 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj); |
| 6310 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6311 | } |
| 6312 | |
| 6313 | int |
| 6314 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 6315 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6316 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6317 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6318 | isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); |
| 6319 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6320 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6321 | } |
| 6322 | if (isinstance) { |
| 6323 | *out = Eq; |
| 6324 | return 0; |
| 6325 | } |
| 6326 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type); |
| 6327 | if (isinstance == -1) { |
| 6328 | return 1; |
| 6329 | } |
| 6330 | if (isinstance) { |
| 6331 | *out = NotEq; |
| 6332 | return 0; |
| 6333 | } |
| 6334 | isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type); |
| 6335 | if (isinstance == -1) { |
| 6336 | return 1; |
| 6337 | } |
| 6338 | if (isinstance) { |
| 6339 | *out = Lt; |
| 6340 | return 0; |
| 6341 | } |
| 6342 | isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type); |
| 6343 | if (isinstance == -1) { |
| 6344 | return 1; |
| 6345 | } |
| 6346 | if (isinstance) { |
| 6347 | *out = LtE; |
| 6348 | return 0; |
| 6349 | } |
| 6350 | isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type); |
| 6351 | if (isinstance == -1) { |
| 6352 | return 1; |
| 6353 | } |
| 6354 | if (isinstance) { |
| 6355 | *out = Gt; |
| 6356 | return 0; |
| 6357 | } |
| 6358 | isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type); |
| 6359 | if (isinstance == -1) { |
| 6360 | return 1; |
| 6361 | } |
| 6362 | if (isinstance) { |
| 6363 | *out = GtE; |
| 6364 | return 0; |
| 6365 | } |
| 6366 | isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type); |
| 6367 | if (isinstance == -1) { |
| 6368 | return 1; |
| 6369 | } |
| 6370 | if (isinstance) { |
| 6371 | *out = Is; |
| 6372 | return 0; |
| 6373 | } |
| 6374 | isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type); |
| 6375 | if (isinstance == -1) { |
| 6376 | return 1; |
| 6377 | } |
| 6378 | if (isinstance) { |
| 6379 | *out = IsNot; |
| 6380 | return 0; |
| 6381 | } |
| 6382 | isinstance = PyObject_IsInstance(obj, (PyObject *)In_type); |
| 6383 | if (isinstance == -1) { |
| 6384 | return 1; |
| 6385 | } |
| 6386 | if (isinstance) { |
| 6387 | *out = In; |
| 6388 | return 0; |
| 6389 | } |
| 6390 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type); |
| 6391 | if (isinstance == -1) { |
| 6392 | return 1; |
| 6393 | } |
| 6394 | if (isinstance) { |
| 6395 | *out = NotIn; |
| 6396 | return 0; |
| 6397 | } |
| 6398 | |
| 6399 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj); |
| 6400 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6401 | } |
| 6402 | |
| 6403 | int |
| 6404 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 6405 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6406 | PyObject* tmp = NULL; |
| 6407 | expr_ty target; |
| 6408 | expr_ty iter; |
| 6409 | asdl_seq* ifs; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6410 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6411 | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
| 6412 | int res; |
| 6413 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
| 6414 | if (tmp == NULL) goto failed; |
| 6415 | res = obj2ast_expr(tmp, &target, arena); |
| 6416 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6417 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6418 | } else { |
| 6419 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6420 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6421 | } |
| 6422 | if (_PyObject_HasAttrId(obj, &PyId_iter)) { |
| 6423 | int res; |
| 6424 | tmp = _PyObject_GetAttrId(obj, &PyId_iter); |
| 6425 | if (tmp == NULL) goto failed; |
| 6426 | res = obj2ast_expr(tmp, &iter, arena); |
| 6427 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6428 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6429 | } else { |
| 6430 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 6431 | return 1; |
| 6432 | } |
| 6433 | if (_PyObject_HasAttrId(obj, &PyId_ifs)) { |
| 6434 | int res; |
| 6435 | Py_ssize_t len; |
| 6436 | Py_ssize_t i; |
| 6437 | tmp = _PyObject_GetAttrId(obj, &PyId_ifs); |
| 6438 | if (tmp == NULL) goto failed; |
| 6439 | if (!PyList_Check(tmp)) { |
| 6440 | PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6441 | goto failed; |
| 6442 | } |
| 6443 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6444 | ifs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6445 | if (ifs == NULL) goto failed; |
| 6446 | for (i = 0; i < len; i++) { |
| 6447 | expr_ty value; |
| 6448 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6449 | if (res != 0) goto failed; |
| 6450 | asdl_seq_SET(ifs, i, value); |
| 6451 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6452 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6453 | } else { |
| 6454 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 6455 | return 1; |
| 6456 | } |
| 6457 | *out = comprehension(target, iter, ifs, arena); |
| 6458 | return 0; |
| 6459 | failed: |
| 6460 | Py_XDECREF(tmp); |
| 6461 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6462 | } |
| 6463 | |
| 6464 | int |
| 6465 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 6466 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6467 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6468 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6469 | PyObject *tmp = NULL; |
| 6470 | int lineno; |
| 6471 | int col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6472 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6473 | if (obj == Py_None) { |
| 6474 | *out = NULL; |
| 6475 | return 0; |
| 6476 | } |
| 6477 | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
| 6478 | int res; |
| 6479 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
| 6480 | if (tmp == NULL) goto failed; |
| 6481 | res = obj2ast_int(tmp, &lineno, arena); |
| 6482 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6483 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6484 | } else { |
| 6485 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6486 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6487 | } |
| 6488 | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
| 6489 | int res; |
| 6490 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
| 6491 | if (tmp == NULL) goto failed; |
| 6492 | res = obj2ast_int(tmp, &col_offset, arena); |
| 6493 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6494 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6495 | } else { |
| 6496 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 6497 | return 1; |
| 6498 | } |
| 6499 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type); |
| 6500 | if (isinstance == -1) { |
| 6501 | return 1; |
| 6502 | } |
| 6503 | if (isinstance) { |
| 6504 | expr_ty type; |
| 6505 | identifier name; |
| 6506 | asdl_seq* body; |
| 6507 | |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6508 | if (exists_not_none(obj, &PyId_type)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6509 | int res; |
| 6510 | tmp = _PyObject_GetAttrId(obj, &PyId_type); |
| 6511 | if (tmp == NULL) goto failed; |
| 6512 | res = obj2ast_expr(tmp, &type, arena); |
| 6513 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6514 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6515 | } else { |
| 6516 | type = NULL; |
| 6517 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6518 | if (exists_not_none(obj, &PyId_name)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6519 | int res; |
| 6520 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
| 6521 | if (tmp == NULL) goto failed; |
| 6522 | res = obj2ast_identifier(tmp, &name, arena); |
| 6523 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6524 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6525 | } else { |
| 6526 | name = NULL; |
| 6527 | } |
| 6528 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 6529 | int res; |
| 6530 | Py_ssize_t len; |
| 6531 | Py_ssize_t i; |
| 6532 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 6533 | if (tmp == NULL) goto failed; |
| 6534 | if (!PyList_Check(tmp)) { |
| 6535 | PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6536 | goto failed; |
| 6537 | } |
| 6538 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6539 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6540 | if (body == NULL) goto failed; |
| 6541 | for (i = 0; i < len; i++) { |
| 6542 | stmt_ty value; |
| 6543 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6544 | if (res != 0) goto failed; |
| 6545 | asdl_seq_SET(body, i, value); |
| 6546 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6547 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6548 | } else { |
| 6549 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 6550 | return 1; |
| 6551 | } |
| 6552 | *out = ExceptHandler(type, name, body, lineno, col_offset, arena); |
| 6553 | if (*out == NULL) goto failed; |
| 6554 | return 0; |
| 6555 | } |
| 6556 | |
| 6557 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
| 6558 | failed: |
| 6559 | Py_XDECREF(tmp); |
| 6560 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6561 | } |
| 6562 | |
| 6563 | int |
| 6564 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 6565 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6566 | PyObject* tmp = NULL; |
| 6567 | asdl_seq* args; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6568 | arg_ty vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6569 | asdl_seq* kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6570 | asdl_seq* kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6571 | arg_ty kwarg; |
| 6572 | asdl_seq* defaults; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6573 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6574 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
| 6575 | int res; |
| 6576 | Py_ssize_t len; |
| 6577 | Py_ssize_t i; |
| 6578 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
| 6579 | if (tmp == NULL) goto failed; |
| 6580 | if (!PyList_Check(tmp)) { |
| 6581 | PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6582 | goto failed; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6583 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6584 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6585 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6586 | if (args == NULL) goto failed; |
| 6587 | for (i = 0; i < len; i++) { |
| 6588 | arg_ty value; |
| 6589 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6590 | if (res != 0) goto failed; |
| 6591 | asdl_seq_SET(args, i, value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6592 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6593 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6594 | } else { |
| 6595 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6596 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6597 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6598 | if (exists_not_none(obj, &PyId_vararg)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6599 | int res; |
| 6600 | tmp = _PyObject_GetAttrId(obj, &PyId_vararg); |
| 6601 | if (tmp == NULL) goto failed; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6602 | res = obj2ast_arg(tmp, &vararg, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6603 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6604 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6605 | } else { |
| 6606 | vararg = NULL; |
| 6607 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6608 | if (_PyObject_HasAttrId(obj, &PyId_kwonlyargs)) { |
| 6609 | int res; |
| 6610 | Py_ssize_t len; |
| 6611 | Py_ssize_t i; |
| 6612 | tmp = _PyObject_GetAttrId(obj, &PyId_kwonlyargs); |
| 6613 | if (tmp == NULL) goto failed; |
| 6614 | if (!PyList_Check(tmp)) { |
| 6615 | PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6616 | goto failed; |
| 6617 | } |
| 6618 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6619 | kwonlyargs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6620 | if (kwonlyargs == NULL) goto failed; |
| 6621 | for (i = 0; i < len; i++) { |
| 6622 | arg_ty value; |
| 6623 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6624 | if (res != 0) goto failed; |
| 6625 | asdl_seq_SET(kwonlyargs, i, value); |
| 6626 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6627 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6628 | } else { |
| 6629 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 6630 | return 1; |
| 6631 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6632 | if (_PyObject_HasAttrId(obj, &PyId_kw_defaults)) { |
| 6633 | int res; |
| 6634 | Py_ssize_t len; |
| 6635 | Py_ssize_t i; |
| 6636 | tmp = _PyObject_GetAttrId(obj, &PyId_kw_defaults); |
| 6637 | if (tmp == NULL) goto failed; |
| 6638 | if (!PyList_Check(tmp)) { |
| 6639 | PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6640 | goto failed; |
| 6641 | } |
| 6642 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6643 | kw_defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6644 | if (kw_defaults == NULL) goto failed; |
| 6645 | for (i = 0; i < len; i++) { |
| 6646 | expr_ty value; |
| 6647 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6648 | if (res != 0) goto failed; |
| 6649 | asdl_seq_SET(kw_defaults, i, value); |
| 6650 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6651 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6652 | } else { |
| 6653 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 6654 | return 1; |
| 6655 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6656 | if (exists_not_none(obj, &PyId_kwarg)) { |
| 6657 | int res; |
| 6658 | tmp = _PyObject_GetAttrId(obj, &PyId_kwarg); |
| 6659 | if (tmp == NULL) goto failed; |
| 6660 | res = obj2ast_arg(tmp, &kwarg, arena); |
| 6661 | if (res != 0) goto failed; |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 6662 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6663 | } else { |
| 6664 | kwarg = NULL; |
| 6665 | } |
| 6666 | if (_PyObject_HasAttrId(obj, &PyId_defaults)) { |
| 6667 | int res; |
| 6668 | Py_ssize_t len; |
| 6669 | Py_ssize_t i; |
| 6670 | tmp = _PyObject_GetAttrId(obj, &PyId_defaults); |
| 6671 | if (tmp == NULL) goto failed; |
| 6672 | if (!PyList_Check(tmp)) { |
| 6673 | PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6674 | goto failed; |
| 6675 | } |
| 6676 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6677 | defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6678 | if (defaults == NULL) goto failed; |
| 6679 | for (i = 0; i < len; i++) { |
| 6680 | expr_ty value; |
| 6681 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6682 | if (res != 0) goto failed; |
| 6683 | asdl_seq_SET(defaults, i, value); |
| 6684 | } |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 6685 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6686 | } else { |
| 6687 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 6688 | return 1; |
| 6689 | } |
| 6690 | *out = arguments(args, vararg, kwonlyargs, kw_defaults, kwarg, defaults, |
| 6691 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6692 | return 0; |
| 6693 | failed: |
| 6694 | Py_XDECREF(tmp); |
| 6695 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6696 | } |
| 6697 | |
| 6698 | int |
| 6699 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 6700 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6701 | PyObject* tmp = NULL; |
| 6702 | identifier arg; |
| 6703 | expr_ty annotation; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6704 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6705 | if (_PyObject_HasAttrId(obj, &PyId_arg)) { |
| 6706 | int res; |
| 6707 | tmp = _PyObject_GetAttrId(obj, &PyId_arg); |
| 6708 | if (tmp == NULL) goto failed; |
| 6709 | res = obj2ast_identifier(tmp, &arg, arena); |
| 6710 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6711 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6712 | } else { |
| 6713 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6714 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6715 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6716 | if (exists_not_none(obj, &PyId_annotation)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6717 | int res; |
| 6718 | tmp = _PyObject_GetAttrId(obj, &PyId_annotation); |
| 6719 | if (tmp == NULL) goto failed; |
| 6720 | res = obj2ast_expr(tmp, &annotation, arena); |
| 6721 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6722 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6723 | } else { |
| 6724 | annotation = NULL; |
| 6725 | } |
| 6726 | *out = arg(arg, annotation, arena); |
| 6727 | return 0; |
| 6728 | failed: |
| 6729 | Py_XDECREF(tmp); |
| 6730 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6731 | } |
| 6732 | |
| 6733 | int |
| 6734 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 6735 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6736 | PyObject* tmp = NULL; |
| 6737 | identifier arg; |
| 6738 | expr_ty value; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6739 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6740 | if (_PyObject_HasAttrId(obj, &PyId_arg)) { |
| 6741 | int res; |
| 6742 | tmp = _PyObject_GetAttrId(obj, &PyId_arg); |
| 6743 | if (tmp == NULL) goto failed; |
| 6744 | res = obj2ast_identifier(tmp, &arg, arena); |
| 6745 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6746 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6747 | } else { |
| 6748 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from keyword"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6749 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6750 | } |
| 6751 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 6752 | int res; |
| 6753 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 6754 | if (tmp == NULL) goto failed; |
| 6755 | res = obj2ast_expr(tmp, &value, arena); |
| 6756 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6757 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6758 | } else { |
| 6759 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 6760 | return 1; |
| 6761 | } |
| 6762 | *out = keyword(arg, value, arena); |
| 6763 | return 0; |
| 6764 | failed: |
| 6765 | Py_XDECREF(tmp); |
| 6766 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6767 | } |
| 6768 | |
| 6769 | int |
| 6770 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 6771 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6772 | PyObject* tmp = NULL; |
| 6773 | identifier name; |
| 6774 | identifier asname; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6775 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6776 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
| 6777 | int res; |
| 6778 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
| 6779 | if (tmp == NULL) goto failed; |
| 6780 | res = obj2ast_identifier(tmp, &name, arena); |
| 6781 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6782 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6783 | } else { |
| 6784 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6785 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6786 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6787 | if (exists_not_none(obj, &PyId_asname)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6788 | int res; |
| 6789 | tmp = _PyObject_GetAttrId(obj, &PyId_asname); |
| 6790 | if (tmp == NULL) goto failed; |
| 6791 | res = obj2ast_identifier(tmp, &asname, arena); |
| 6792 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6793 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6794 | } else { |
| 6795 | asname = NULL; |
| 6796 | } |
| 6797 | *out = alias(name, asname, arena); |
| 6798 | return 0; |
| 6799 | failed: |
| 6800 | Py_XDECREF(tmp); |
| 6801 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6802 | } |
| 6803 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6804 | int |
| 6805 | obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) |
| 6806 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6807 | PyObject* tmp = NULL; |
| 6808 | expr_ty context_expr; |
| 6809 | expr_ty optional_vars; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6810 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6811 | if (_PyObject_HasAttrId(obj, &PyId_context_expr)) { |
| 6812 | int res; |
| 6813 | tmp = _PyObject_GetAttrId(obj, &PyId_context_expr); |
| 6814 | if (tmp == NULL) goto failed; |
| 6815 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 6816 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6817 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6818 | } else { |
| 6819 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6820 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6821 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6822 | if (exists_not_none(obj, &PyId_optional_vars)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6823 | int res; |
| 6824 | tmp = _PyObject_GetAttrId(obj, &PyId_optional_vars); |
| 6825 | if (tmp == NULL) goto failed; |
| 6826 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 6827 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6828 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6829 | } else { |
| 6830 | optional_vars = NULL; |
| 6831 | } |
| 6832 | *out = withitem(context_expr, optional_vars, arena); |
| 6833 | return 0; |
| 6834 | failed: |
| 6835 | Py_XDECREF(tmp); |
| 6836 | return 1; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6837 | } |
| 6838 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6839 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6840 | static struct PyModuleDef _astmodule = { |
| 6841 | PyModuleDef_HEAD_INIT, "_ast" |
| 6842 | }; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6843 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6844 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6845 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6846 | PyObject *m, *d; |
| 6847 | if (!init_types()) return NULL; |
| 6848 | m = PyModule_Create(&_astmodule); |
| 6849 | if (!m) return NULL; |
| 6850 | d = PyModule_GetDict(m); |
| 6851 | if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return NULL; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6852 | if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6853 | return NULL; |
| 6854 | if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return NULL; |
| 6855 | if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) return |
| 6856 | NULL; |
| 6857 | if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) < |
| 6858 | 0) return NULL; |
| 6859 | if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < 0) |
| 6860 | return NULL; |
| 6861 | if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return |
| 6862 | NULL; |
| 6863 | if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return NULL; |
| 6864 | if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) < |
| 6865 | 0) return NULL; |
| 6866 | if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) |
| 6867 | return NULL; |
| 6868 | if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) return |
| 6869 | NULL; |
| 6870 | if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) return |
| 6871 | NULL; |
| 6872 | if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) return |
| 6873 | NULL; |
| 6874 | if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < 0) |
| 6875 | return NULL; |
| 6876 | if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return NULL; |
| 6877 | if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return |
| 6878 | NULL; |
| 6879 | if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return NULL; |
| 6880 | if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return NULL; |
| 6881 | if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return |
| 6882 | NULL; |
| 6883 | if (PyDict_SetItemString(d, "Try", (PyObject*)Try_type) < 0) return NULL; |
| 6884 | if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) return |
| 6885 | NULL; |
| 6886 | if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) return |
| 6887 | NULL; |
| 6888 | if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < 0) |
| 6889 | return NULL; |
| 6890 | if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) return |
| 6891 | NULL; |
| 6892 | if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0) |
| 6893 | return NULL; |
| 6894 | if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return NULL; |
| 6895 | if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return NULL; |
| 6896 | if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return |
| 6897 | NULL; |
| 6898 | if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) |
| 6899 | return NULL; |
| 6900 | if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return NULL; |
| 6901 | if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) return |
| 6902 | NULL; |
| 6903 | if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return |
| 6904 | NULL; |
| 6905 | if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) return |
| 6906 | NULL; |
| 6907 | if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) return |
| 6908 | NULL; |
| 6909 | if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return |
| 6910 | NULL; |
| 6911 | if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return NULL; |
| 6912 | if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return NULL; |
| 6913 | if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) |
| 6914 | return NULL; |
| 6915 | if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) return |
| 6916 | NULL; |
| 6917 | if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0) |
| 6918 | return NULL; |
| 6919 | if (PyDict_SetItemString(d, "GeneratorExp", (PyObject*)GeneratorExp_type) < |
| 6920 | 0) return NULL; |
| 6921 | if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return |
| 6922 | NULL; |
| 6923 | if (PyDict_SetItemString(d, "YieldFrom", (PyObject*)YieldFrom_type) < 0) |
| 6924 | return NULL; |
| 6925 | if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) return |
| 6926 | NULL; |
| 6927 | if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return NULL; |
| 6928 | if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return NULL; |
| 6929 | if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return NULL; |
| 6930 | if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return |
| 6931 | NULL; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6932 | if (PyDict_SetItemString(d, "NameConstant", (PyObject*)NameConstant_type) < |
| 6933 | 0) return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6934 | if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0) |
| 6935 | return NULL; |
| 6936 | if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < 0) |
| 6937 | return NULL; |
| 6938 | if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < 0) |
| 6939 | return NULL; |
| 6940 | if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0) return |
| 6941 | NULL; |
| 6942 | if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return NULL; |
| 6943 | if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return NULL; |
| 6944 | if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return |
| 6945 | NULL; |
| 6946 | if (PyDict_SetItemString(d, "expr_context", (PyObject*)expr_context_type) < |
| 6947 | 0) return NULL; |
| 6948 | if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return NULL; |
| 6949 | if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return |
| 6950 | NULL; |
| 6951 | if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return NULL; |
| 6952 | if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) return |
| 6953 | NULL; |
| 6954 | if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) |
| 6955 | return NULL; |
| 6956 | if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return |
| 6957 | NULL; |
| 6958 | if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return |
| 6959 | NULL; |
| 6960 | if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return |
| 6961 | NULL; |
| 6962 | if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) |
| 6963 | return NULL; |
| 6964 | if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return |
| 6965 | NULL; |
| 6966 | if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) return |
| 6967 | NULL; |
| 6968 | if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return NULL; |
| 6969 | if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return NULL; |
| 6970 | if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) |
| 6971 | return NULL; |
| 6972 | if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return NULL; |
| 6973 | if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return NULL; |
| 6974 | if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return NULL; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 6975 | if (PyDict_SetItemString(d, "MatMult", (PyObject*)MatMult_type) < 0) return |
| 6976 | NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6977 | if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return NULL; |
| 6978 | if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return NULL; |
| 6979 | if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return NULL; |
| 6980 | if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) return |
| 6981 | NULL; |
| 6982 | if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) return |
| 6983 | NULL; |
| 6984 | if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return |
| 6985 | NULL; |
| 6986 | if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) return |
| 6987 | NULL; |
| 6988 | if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) return |
| 6989 | NULL; |
| 6990 | if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) |
| 6991 | return NULL; |
| 6992 | if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) return |
| 6993 | NULL; |
| 6994 | if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) return |
| 6995 | NULL; |
| 6996 | if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return NULL; |
| 6997 | if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return NULL; |
| 6998 | if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return NULL; |
| 6999 | if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return |
| 7000 | NULL; |
| 7001 | if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return NULL; |
| 7002 | if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return |
| 7003 | NULL; |
| 7004 | if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return NULL; |
| 7005 | if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return NULL; |
| 7006 | if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return NULL; |
| 7007 | if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return NULL; |
| 7008 | if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return NULL; |
| 7009 | if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return |
| 7010 | NULL; |
| 7011 | if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return NULL; |
| 7012 | if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return |
| 7013 | NULL; |
| 7014 | if (PyDict_SetItemString(d, "comprehension", (PyObject*)comprehension_type) |
| 7015 | < 0) return NULL; |
| 7016 | if (PyDict_SetItemString(d, "excepthandler", (PyObject*)excepthandler_type) |
| 7017 | < 0) return NULL; |
| 7018 | if (PyDict_SetItemString(d, "ExceptHandler", (PyObject*)ExceptHandler_type) |
| 7019 | < 0) return NULL; |
| 7020 | if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < 0) |
| 7021 | return NULL; |
| 7022 | if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return NULL; |
| 7023 | if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) return |
| 7024 | NULL; |
| 7025 | if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return |
| 7026 | NULL; |
| 7027 | if (PyDict_SetItemString(d, "withitem", (PyObject*)withitem_type) < 0) |
| 7028 | return NULL; |
| 7029 | return m; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 7030 | } |
| 7031 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 7032 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 7033 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 7034 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 7035 | if (!init_types()) |
| 7036 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 7037 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 7038 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 7039 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7040 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 7041 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7042 | { |
| 7043 | mod_ty res; |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 7044 | PyObject *req_type[3]; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7045 | char *req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 7046 | int isinstance; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 7047 | |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 7048 | req_type[0] = (PyObject*)Module_type; |
| 7049 | req_type[1] = (PyObject*)Expression_type; |
| 7050 | req_type[2] = (PyObject*)Interactive_type; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 7051 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7052 | assert(0 <= mode && mode <= 2); |
| 7053 | |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 7054 | if (!init_types()) |
| 7055 | return NULL; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7056 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 7057 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 7058 | if (isinstance == -1) |
| 7059 | return NULL; |
| 7060 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7061 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
| 7062 | req_name[mode], Py_TYPE(ast)->tp_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7063 | return NULL; |
| 7064 | } |
| 7065 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 7066 | return NULL; |
| 7067 | else |
| 7068 | return res; |
| 7069 | } |
| 7070 | |
| 7071 | int PyAST_Check(PyObject* obj) |
| 7072 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 7073 | if (!init_types()) |
| 7074 | return -1; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 7075 | return PyObject_IsInstance(obj, (PyObject*)&AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7076 | } |
| 7077 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 7078 | |