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 | }; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 48 | static PyTypeObject *AsyncFunctionDef_type; |
| 49 | static char *AsyncFunctionDef_fields[]={ |
| 50 | "name", |
| 51 | "args", |
| 52 | "body", |
| 53 | "decorator_list", |
| 54 | "returns", |
| 55 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 56 | static PyTypeObject *ClassDef_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 57 | _Py_IDENTIFIER(bases); |
| 58 | _Py_IDENTIFIER(keywords); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 59 | static char *ClassDef_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 60 | "name", |
| 61 | "bases", |
| 62 | "keywords", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 63 | "body", |
| 64 | "decorator_list", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 65 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 66 | static PyTypeObject *Return_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 67 | _Py_IDENTIFIER(value); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 68 | static char *Return_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 69 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 70 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 71 | static PyTypeObject *Delete_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 72 | _Py_IDENTIFIER(targets); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 73 | static char *Delete_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 74 | "targets", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 75 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 76 | static PyTypeObject *Assign_type; |
| 77 | static char *Assign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 78 | "targets", |
| 79 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 80 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 81 | static PyTypeObject *AugAssign_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 82 | _Py_IDENTIFIER(target); |
| 83 | _Py_IDENTIFIER(op); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 84 | static char *AugAssign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 85 | "target", |
| 86 | "op", |
| 87 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 88 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 89 | static PyTypeObject *For_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 90 | _Py_IDENTIFIER(iter); |
| 91 | _Py_IDENTIFIER(orelse); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 92 | static char *For_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 93 | "target", |
| 94 | "iter", |
| 95 | "body", |
| 96 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 97 | }; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 98 | static PyTypeObject *AsyncFor_type; |
| 99 | static char *AsyncFor_fields[]={ |
| 100 | "target", |
| 101 | "iter", |
| 102 | "body", |
| 103 | "orelse", |
| 104 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 105 | static PyTypeObject *While_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 106 | _Py_IDENTIFIER(test); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 107 | static char *While_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 108 | "test", |
| 109 | "body", |
| 110 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 111 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 112 | static PyTypeObject *If_type; |
| 113 | static char *If_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 114 | "test", |
| 115 | "body", |
| 116 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 117 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 118 | static PyTypeObject *With_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 119 | _Py_IDENTIFIER(items); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 120 | static char *With_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 121 | "items", |
| 122 | "body", |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 123 | }; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 124 | static PyTypeObject *AsyncWith_type; |
| 125 | static char *AsyncWith_fields[]={ |
| 126 | "items", |
| 127 | "body", |
| 128 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 129 | static PyTypeObject *Raise_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 130 | _Py_IDENTIFIER(exc); |
| 131 | _Py_IDENTIFIER(cause); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 132 | static char *Raise_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 133 | "exc", |
| 134 | "cause", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 135 | }; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 136 | static PyTypeObject *Try_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 137 | _Py_IDENTIFIER(handlers); |
| 138 | _Py_IDENTIFIER(finalbody); |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 139 | static char *Try_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 140 | "body", |
| 141 | "handlers", |
| 142 | "orelse", |
| 143 | "finalbody", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 144 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 145 | static PyTypeObject *Assert_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 146 | _Py_IDENTIFIER(msg); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 147 | static char *Assert_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 148 | "test", |
| 149 | "msg", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 150 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 151 | static PyTypeObject *Import_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 152 | _Py_IDENTIFIER(names); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 153 | static char *Import_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 154 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 155 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 156 | static PyTypeObject *ImportFrom_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 157 | _Py_IDENTIFIER(module); |
| 158 | _Py_IDENTIFIER(level); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 159 | static char *ImportFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 160 | "module", |
| 161 | "names", |
| 162 | "level", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 163 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 164 | static PyTypeObject *Global_type; |
| 165 | static char *Global_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 166 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 167 | }; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 168 | static PyTypeObject *Nonlocal_type; |
| 169 | static char *Nonlocal_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 170 | "names", |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 171 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 172 | static PyTypeObject *Expr_type; |
| 173 | static char *Expr_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 174 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 175 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 176 | static PyTypeObject *Pass_type; |
| 177 | static PyTypeObject *Break_type; |
| 178 | static PyTypeObject *Continue_type; |
| 179 | static PyTypeObject *expr_type; |
| 180 | static char *expr_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 181 | "lineno", |
| 182 | "col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 183 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 184 | static PyObject* ast2obj_expr(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 185 | static PyTypeObject *BoolOp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 186 | _Py_IDENTIFIER(values); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 187 | static char *BoolOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 188 | "op", |
| 189 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 190 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 191 | static PyTypeObject *BinOp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 192 | _Py_IDENTIFIER(left); |
| 193 | _Py_IDENTIFIER(right); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 194 | static char *BinOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 195 | "left", |
| 196 | "op", |
| 197 | "right", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 198 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 199 | static PyTypeObject *UnaryOp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 200 | _Py_IDENTIFIER(operand); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 201 | static char *UnaryOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 202 | "op", |
| 203 | "operand", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 204 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 205 | static PyTypeObject *Lambda_type; |
| 206 | static char *Lambda_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 207 | "args", |
| 208 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 209 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 210 | static PyTypeObject *IfExp_type; |
| 211 | static char *IfExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 212 | "test", |
| 213 | "body", |
| 214 | "orelse", |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 215 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 216 | static PyTypeObject *Dict_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 217 | _Py_IDENTIFIER(keys); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 218 | static char *Dict_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 219 | "keys", |
| 220 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 221 | }; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 222 | static PyTypeObject *Set_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 223 | _Py_IDENTIFIER(elts); |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 224 | static char *Set_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 225 | "elts", |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 226 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 227 | static PyTypeObject *ListComp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 228 | _Py_IDENTIFIER(elt); |
| 229 | _Py_IDENTIFIER(generators); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 230 | static char *ListComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 231 | "elt", |
| 232 | "generators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 233 | }; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 234 | static PyTypeObject *SetComp_type; |
| 235 | static char *SetComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 236 | "elt", |
| 237 | "generators", |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 238 | }; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 239 | static PyTypeObject *DictComp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 240 | _Py_IDENTIFIER(key); |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 241 | static char *DictComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 242 | "key", |
| 243 | "value", |
| 244 | "generators", |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 245 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 246 | static PyTypeObject *GeneratorExp_type; |
| 247 | static char *GeneratorExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 248 | "elt", |
| 249 | "generators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 250 | }; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 251 | static PyTypeObject *Await_type; |
| 252 | static char *Await_fields[]={ |
| 253 | "value", |
| 254 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 255 | static PyTypeObject *Yield_type; |
| 256 | static char *Yield_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 257 | "value", |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 258 | }; |
| 259 | static PyTypeObject *YieldFrom_type; |
| 260 | static char *YieldFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 261 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 262 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 263 | static PyTypeObject *Compare_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 264 | _Py_IDENTIFIER(ops); |
| 265 | _Py_IDENTIFIER(comparators); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 266 | static char *Compare_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 267 | "left", |
| 268 | "ops", |
| 269 | "comparators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 270 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 271 | static PyTypeObject *Call_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 272 | _Py_IDENTIFIER(func); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 273 | static char *Call_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 274 | "func", |
| 275 | "args", |
| 276 | "keywords", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 277 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 278 | static PyTypeObject *Num_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 279 | _Py_IDENTIFIER(n); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 280 | static char *Num_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 281 | "n", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 282 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 283 | static PyTypeObject *Str_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 284 | _Py_IDENTIFIER(s); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 285 | static char *Str_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 286 | "s", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 287 | }; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 288 | static PyTypeObject *FormattedValue_type; |
| 289 | _Py_IDENTIFIER(conversion); |
| 290 | _Py_IDENTIFIER(format_spec); |
| 291 | static char *FormattedValue_fields[]={ |
| 292 | "value", |
| 293 | "conversion", |
| 294 | "format_spec", |
| 295 | }; |
| 296 | static PyTypeObject *JoinedStr_type; |
| 297 | static char *JoinedStr_fields[]={ |
| 298 | "values", |
| 299 | }; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 300 | static PyTypeObject *Bytes_type; |
| 301 | static char *Bytes_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 302 | "s", |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 303 | }; |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 304 | static PyTypeObject *NameConstant_type; |
| 305 | static char *NameConstant_fields[]={ |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 306 | "value", |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 307 | }; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 308 | static PyTypeObject *Ellipsis_type; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 309 | static PyTypeObject *Constant_type; |
| 310 | static char *Constant_fields[]={ |
| 311 | "value", |
| 312 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 313 | static PyTypeObject *Attribute_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 314 | _Py_IDENTIFIER(attr); |
| 315 | _Py_IDENTIFIER(ctx); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 316 | static char *Attribute_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 317 | "value", |
| 318 | "attr", |
| 319 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 320 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 321 | static PyTypeObject *Subscript_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 322 | _Py_IDENTIFIER(slice); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 323 | static char *Subscript_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 324 | "value", |
| 325 | "slice", |
| 326 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 327 | }; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 328 | static PyTypeObject *Starred_type; |
| 329 | static char *Starred_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 330 | "value", |
| 331 | "ctx", |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 332 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 333 | static PyTypeObject *Name_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 334 | _Py_IDENTIFIER(id); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 335 | static char *Name_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 336 | "id", |
| 337 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 338 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 339 | static PyTypeObject *List_type; |
| 340 | static char *List_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 341 | "elts", |
| 342 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 343 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 344 | static PyTypeObject *Tuple_type; |
| 345 | static char *Tuple_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 346 | "elts", |
| 347 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 348 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 349 | static PyTypeObject *expr_context_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 350 | static PyObject *Load_singleton, *Store_singleton, *Del_singleton, |
| 351 | *AugLoad_singleton, *AugStore_singleton, *Param_singleton; |
| 352 | static PyObject* ast2obj_expr_context(expr_context_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 353 | static PyTypeObject *Load_type; |
| 354 | static PyTypeObject *Store_type; |
| 355 | static PyTypeObject *Del_type; |
| 356 | static PyTypeObject *AugLoad_type; |
| 357 | static PyTypeObject *AugStore_type; |
| 358 | static PyTypeObject *Param_type; |
| 359 | static PyTypeObject *slice_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 360 | static PyObject* ast2obj_slice(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 361 | static PyTypeObject *Slice_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 362 | _Py_IDENTIFIER(lower); |
| 363 | _Py_IDENTIFIER(upper); |
| 364 | _Py_IDENTIFIER(step); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 365 | static char *Slice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 366 | "lower", |
| 367 | "upper", |
| 368 | "step", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 369 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 370 | static PyTypeObject *ExtSlice_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 371 | _Py_IDENTIFIER(dims); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 372 | static char *ExtSlice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 373 | "dims", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 374 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 375 | static PyTypeObject *Index_type; |
| 376 | static char *Index_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 377 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 378 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 379 | static PyTypeObject *boolop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 380 | static PyObject *And_singleton, *Or_singleton; |
| 381 | static PyObject* ast2obj_boolop(boolop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 382 | static PyTypeObject *And_type; |
| 383 | static PyTypeObject *Or_type; |
| 384 | static PyTypeObject *operator_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 385 | static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton, |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 386 | *MatMult_singleton, *Div_singleton, *Mod_singleton, *Pow_singleton, |
| 387 | *LShift_singleton, *RShift_singleton, *BitOr_singleton, *BitXor_singleton, |
| 388 | *BitAnd_singleton, *FloorDiv_singleton; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 389 | static PyObject* ast2obj_operator(operator_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 390 | static PyTypeObject *Add_type; |
| 391 | static PyTypeObject *Sub_type; |
| 392 | static PyTypeObject *Mult_type; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 393 | static PyTypeObject *MatMult_type; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 394 | static PyTypeObject *Div_type; |
| 395 | static PyTypeObject *Mod_type; |
| 396 | static PyTypeObject *Pow_type; |
| 397 | static PyTypeObject *LShift_type; |
| 398 | static PyTypeObject *RShift_type; |
| 399 | static PyTypeObject *BitOr_type; |
| 400 | static PyTypeObject *BitXor_type; |
| 401 | static PyTypeObject *BitAnd_type; |
| 402 | static PyTypeObject *FloorDiv_type; |
| 403 | static PyTypeObject *unaryop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 404 | static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton, |
| 405 | *USub_singleton; |
| 406 | static PyObject* ast2obj_unaryop(unaryop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 407 | static PyTypeObject *Invert_type; |
| 408 | static PyTypeObject *Not_type; |
| 409 | static PyTypeObject *UAdd_type; |
| 410 | static PyTypeObject *USub_type; |
| 411 | static PyTypeObject *cmpop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 412 | static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton, |
| 413 | *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton, |
| 414 | *NotIn_singleton; |
| 415 | static PyObject* ast2obj_cmpop(cmpop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 416 | static PyTypeObject *Eq_type; |
| 417 | static PyTypeObject *NotEq_type; |
| 418 | static PyTypeObject *Lt_type; |
| 419 | static PyTypeObject *LtE_type; |
| 420 | static PyTypeObject *Gt_type; |
| 421 | static PyTypeObject *GtE_type; |
| 422 | static PyTypeObject *Is_type; |
| 423 | static PyTypeObject *IsNot_type; |
| 424 | static PyTypeObject *In_type; |
| 425 | static PyTypeObject *NotIn_type; |
| 426 | static PyTypeObject *comprehension_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 427 | static PyObject* ast2obj_comprehension(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 428 | _Py_IDENTIFIER(ifs); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 429 | static char *comprehension_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 430 | "target", |
| 431 | "iter", |
| 432 | "ifs", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 433 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 434 | static PyTypeObject *excepthandler_type; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 435 | static char *excepthandler_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 436 | "lineno", |
| 437 | "col_offset", |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 438 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 439 | static PyObject* ast2obj_excepthandler(void*); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 440 | static PyTypeObject *ExceptHandler_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 441 | _Py_IDENTIFIER(type); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 442 | static char *ExceptHandler_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 443 | "type", |
| 444 | "name", |
| 445 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 446 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 447 | static PyTypeObject *arguments_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 448 | static PyObject* ast2obj_arguments(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 449 | _Py_IDENTIFIER(vararg); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 450 | _Py_IDENTIFIER(kwonlyargs); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 451 | _Py_IDENTIFIER(kw_defaults); |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 452 | _Py_IDENTIFIER(kwarg); |
| 453 | _Py_IDENTIFIER(defaults); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 454 | static char *arguments_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 455 | "args", |
| 456 | "vararg", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 457 | "kwonlyargs", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 458 | "kw_defaults", |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 459 | "kwarg", |
| 460 | "defaults", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 461 | }; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 462 | static PyTypeObject *arg_type; |
| 463 | static PyObject* ast2obj_arg(void*); |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 464 | static char *arg_attributes[] = { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 465 | "lineno", |
| 466 | "col_offset", |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 467 | }; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 468 | _Py_IDENTIFIER(arg); |
| 469 | _Py_IDENTIFIER(annotation); |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 470 | static char *arg_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 471 | "arg", |
| 472 | "annotation", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 473 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 474 | static PyTypeObject *keyword_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 475 | static PyObject* ast2obj_keyword(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 476 | static char *keyword_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 477 | "arg", |
| 478 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 479 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 480 | static PyTypeObject *alias_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 481 | static PyObject* ast2obj_alias(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 482 | _Py_IDENTIFIER(asname); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 483 | static char *alias_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 484 | "name", |
| 485 | "asname", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 486 | }; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 487 | static PyTypeObject *withitem_type; |
| 488 | static PyObject* ast2obj_withitem(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 489 | _Py_IDENTIFIER(context_expr); |
| 490 | _Py_IDENTIFIER(optional_vars); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 491 | static char *withitem_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 492 | "context_expr", |
| 493 | "optional_vars", |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 494 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 495 | |
| 496 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 497 | typedef struct { |
Victor Stinner | 45e50de | 2012-03-13 01:17:31 +0100 | [diff] [blame] | 498 | PyObject_HEAD |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 499 | PyObject *dict; |
| 500 | } AST_object; |
| 501 | |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 502 | static void |
| 503 | ast_dealloc(AST_object *self) |
| 504 | { |
| 505 | Py_CLEAR(self->dict); |
Antoine Pitrou | 5075074 | 2012-07-08 12:43:32 +0200 | [diff] [blame] | 506 | Py_TYPE(self)->tp_free(self); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 507 | } |
| 508 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 509 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 510 | ast_traverse(AST_object *self, visitproc visit, void *arg) |
| 511 | { |
| 512 | Py_VISIT(self->dict); |
| 513 | return 0; |
| 514 | } |
| 515 | |
| 516 | static void |
| 517 | ast_clear(AST_object *self) |
| 518 | { |
| 519 | Py_CLEAR(self->dict); |
| 520 | } |
| 521 | |
| 522 | static int |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 523 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 524 | { |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 525 | _Py_IDENTIFIER(_fields); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 526 | Py_ssize_t i, numfields = 0; |
| 527 | int res = -1; |
| 528 | PyObject *key, *value, *fields; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 529 | fields = _PyObject_GetAttrId((PyObject*)Py_TYPE(self), &PyId__fields); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 530 | if (!fields) |
| 531 | PyErr_Clear(); |
| 532 | if (fields) { |
| 533 | numfields = PySequence_Size(fields); |
| 534 | if (numfields == -1) |
| 535 | goto cleanup; |
| 536 | } |
| 537 | res = 0; /* if no error occurs, this stays 0 to the end */ |
| 538 | if (PyTuple_GET_SIZE(args) > 0) { |
| 539 | if (numfields != PyTuple_GET_SIZE(args)) { |
| 540 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes %s" |
Amaury Forgeot d'Arc | 245c70b | 2008-09-10 22:24:24 +0000 | [diff] [blame] | 541 | "%zd positional argument%s", |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 542 | Py_TYPE(self)->tp_name, |
| 543 | numfields == 0 ? "" : "either 0 or ", |
| 544 | numfields, numfields == 1 ? "" : "s"); |
| 545 | res = -1; |
| 546 | goto cleanup; |
| 547 | } |
| 548 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
| 549 | /* cannot be reached when fields is NULL */ |
| 550 | PyObject *name = PySequence_GetItem(fields, i); |
| 551 | if (!name) { |
| 552 | res = -1; |
| 553 | goto cleanup; |
| 554 | } |
| 555 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
| 556 | Py_DECREF(name); |
| 557 | if (res < 0) |
| 558 | goto cleanup; |
| 559 | } |
| 560 | } |
| 561 | if (kw) { |
| 562 | i = 0; /* needed by PyDict_Next */ |
| 563 | while (PyDict_Next(kw, &i, &key, &value)) { |
| 564 | res = PyObject_SetAttr(self, key, value); |
| 565 | if (res < 0) |
| 566 | goto cleanup; |
| 567 | } |
| 568 | } |
| 569 | cleanup: |
| 570 | Py_XDECREF(fields); |
| 571 | return res; |
| 572 | } |
| 573 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 574 | /* Pickling support */ |
| 575 | static PyObject * |
| 576 | ast_type_reduce(PyObject *self, PyObject *unused) |
| 577 | { |
| 578 | PyObject *res; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 579 | _Py_IDENTIFIER(__dict__); |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 580 | PyObject *dict = _PyObject_GetAttrId(self, &PyId___dict__); |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 581 | if (dict == NULL) { |
| 582 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) |
| 583 | PyErr_Clear(); |
| 584 | else |
| 585 | return NULL; |
| 586 | } |
| 587 | if (dict) { |
| 588 | res = Py_BuildValue("O()O", Py_TYPE(self), dict); |
| 589 | Py_DECREF(dict); |
| 590 | return res; |
| 591 | } |
| 592 | return Py_BuildValue("O()", Py_TYPE(self)); |
| 593 | } |
| 594 | |
| 595 | static PyMethodDef ast_type_methods[] = { |
| 596 | {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, |
| 597 | {NULL} |
| 598 | }; |
| 599 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 600 | static PyGetSetDef ast_type_getsets[] = { |
| 601 | {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict}, |
| 602 | {NULL} |
| 603 | }; |
| 604 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 605 | static PyTypeObject AST_type = { |
| 606 | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 607 | "_ast.AST", |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 608 | sizeof(AST_object), |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 609 | 0, |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 610 | (destructor)ast_dealloc, /* tp_dealloc */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 611 | 0, /* tp_print */ |
| 612 | 0, /* tp_getattr */ |
| 613 | 0, /* tp_setattr */ |
Mark Dickinson | e94c679 | 2009-02-02 20:36:42 +0000 | [diff] [blame] | 614 | 0, /* tp_reserved */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 615 | 0, /* tp_repr */ |
| 616 | 0, /* tp_as_number */ |
| 617 | 0, /* tp_as_sequence */ |
| 618 | 0, /* tp_as_mapping */ |
| 619 | 0, /* tp_hash */ |
| 620 | 0, /* tp_call */ |
| 621 | 0, /* tp_str */ |
| 622 | PyObject_GenericGetAttr, /* tp_getattro */ |
| 623 | PyObject_GenericSetAttr, /* tp_setattro */ |
| 624 | 0, /* tp_as_buffer */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 625 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 626 | 0, /* tp_doc */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 627 | (traverseproc)ast_traverse, /* tp_traverse */ |
| 628 | (inquiry)ast_clear, /* tp_clear */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 629 | 0, /* tp_richcompare */ |
| 630 | 0, /* tp_weaklistoffset */ |
| 631 | 0, /* tp_iter */ |
| 632 | 0, /* tp_iternext */ |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 633 | ast_type_methods, /* tp_methods */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 634 | 0, /* tp_members */ |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 635 | ast_type_getsets, /* tp_getset */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 636 | 0, /* tp_base */ |
| 637 | 0, /* tp_dict */ |
| 638 | 0, /* tp_descr_get */ |
| 639 | 0, /* tp_descr_set */ |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 640 | offsetof(AST_object, dict),/* tp_dictoffset */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 641 | (initproc)ast_type_init, /* tp_init */ |
| 642 | PyType_GenericAlloc, /* tp_alloc */ |
| 643 | PyType_GenericNew, /* tp_new */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 644 | PyObject_GC_Del, /* tp_free */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 645 | }; |
| 646 | |
| 647 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 648 | static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields) |
| 649 | { |
| 650 | PyObject *fnames, *result; |
| 651 | int i; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 652 | fnames = PyTuple_New(num_fields); |
| 653 | if (!fnames) return NULL; |
| 654 | for (i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 655 | PyObject *field = PyUnicode_FromString(fields[i]); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 656 | if (!field) { |
| 657 | Py_DECREF(fnames); |
| 658 | return NULL; |
| 659 | } |
| 660 | PyTuple_SET_ITEM(fnames, i, field); |
| 661 | } |
Victor Stinner | 7eeb5b5 | 2010-06-07 19:57:46 +0000 | [diff] [blame] | 662 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 663 | type, base, "_fields", fnames, "__module__", "_ast"); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 664 | Py_DECREF(fnames); |
| 665 | return (PyTypeObject*)result; |
| 666 | } |
| 667 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 668 | static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) |
| 669 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 670 | int i, result; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 671 | _Py_IDENTIFIER(_attributes); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 672 | PyObject *s, *l = PyTuple_New(num_fields); |
Benjamin Peterson | 3e5cd1d | 2010-06-27 21:45:24 +0000 | [diff] [blame] | 673 | if (!l) |
| 674 | return 0; |
| 675 | for (i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 676 | s = PyUnicode_FromString(attrs[i]); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 677 | if (!s) { |
| 678 | Py_DECREF(l); |
| 679 | return 0; |
| 680 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 681 | PyTuple_SET_ITEM(l, i, s); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 682 | } |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 683 | result = _PyObject_SetAttrId((PyObject*)type, &PyId__attributes, l) >= 0; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 684 | Py_DECREF(l); |
| 685 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 686 | } |
| 687 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 688 | /* Conversion AST -> Python */ |
| 689 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 690 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 691 | { |
Benjamin Peterson | 77fa937 | 2012-05-15 10:10:27 -0700 | [diff] [blame] | 692 | Py_ssize_t i, n = asdl_seq_LEN(seq); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 693 | PyObject *result = PyList_New(n); |
| 694 | PyObject *value; |
| 695 | if (!result) |
| 696 | return NULL; |
| 697 | for (i = 0; i < n; i++) { |
| 698 | value = func(asdl_seq_GET(seq, i)); |
| 699 | if (!value) { |
| 700 | Py_DECREF(result); |
| 701 | return NULL; |
| 702 | } |
| 703 | PyList_SET_ITEM(result, i, value); |
| 704 | } |
| 705 | return result; |
| 706 | } |
| 707 | |
| 708 | static PyObject* ast2obj_object(void *o) |
| 709 | { |
| 710 | if (!o) |
| 711 | o = Py_None; |
| 712 | Py_INCREF((PyObject*)o); |
| 713 | return (PyObject*)o; |
| 714 | } |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 715 | #define ast2obj_singleton ast2obj_object |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 716 | #define ast2obj_constant ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 717 | #define ast2obj_identifier ast2obj_object |
| 718 | #define ast2obj_string ast2obj_object |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 719 | #define ast2obj_bytes ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 720 | |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 721 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 722 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 723 | return PyLong_FromLong(b); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 724 | } |
| 725 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 726 | /* Conversion Python -> AST */ |
| 727 | |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 728 | static int obj2ast_singleton(PyObject *obj, PyObject** out, PyArena* arena) |
| 729 | { |
| 730 | if (obj != Py_None && obj != Py_True && obj != Py_False) { |
| 731 | PyErr_SetString(PyExc_ValueError, |
| 732 | "AST singleton must be True, False, or None"); |
| 733 | return 1; |
| 734 | } |
| 735 | *out = obj; |
| 736 | return 0; |
| 737 | } |
| 738 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 739 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 740 | { |
| 741 | if (obj == Py_None) |
| 742 | obj = NULL; |
Christian Heimes | 70c94e7 | 2013-07-27 00:33:13 +0200 | [diff] [blame] | 743 | if (obj) { |
| 744 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 745 | *out = NULL; |
| 746 | return -1; |
| 747 | } |
| 748 | Py_INCREF(obj); |
| 749 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 750 | *out = obj; |
| 751 | return 0; |
| 752 | } |
| 753 | |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 754 | static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena) |
| 755 | { |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 756 | if (obj) { |
| 757 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 758 | *out = NULL; |
| 759 | return -1; |
| 760 | } |
| 761 | Py_INCREF(obj); |
| 762 | } |
| 763 | *out = obj; |
| 764 | return 0; |
| 765 | } |
| 766 | |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 767 | static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 768 | { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 769 | if (!PyUnicode_CheckExact(obj) && obj != Py_None) { |
| 770 | PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 771 | return 1; |
| 772 | } |
| 773 | return obj2ast_object(obj, out, arena); |
| 774 | } |
| 775 | |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 776 | static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) |
| 777 | { |
Benjamin Peterson | 0224d4e | 2011-08-31 22:13:03 -0400 | [diff] [blame] | 778 | if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 779 | PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); |
| 780 | return 1; |
| 781 | } |
| 782 | return obj2ast_object(obj, out, arena); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 783 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 784 | |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 785 | static int obj2ast_bytes(PyObject* obj, PyObject** out, PyArena* arena) |
| 786 | { |
| 787 | if (!PyBytes_CheckExact(obj)) { |
| 788 | PyErr_SetString(PyExc_TypeError, "AST bytes must be of type bytes"); |
| 789 | return 1; |
| 790 | } |
| 791 | return obj2ast_object(obj, out, arena); |
| 792 | } |
| 793 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 794 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 795 | { |
| 796 | int i; |
| 797 | if (!PyLong_Check(obj)) { |
Amaury Forgeot d'Arc | 5e8f810 | 2011-11-22 21:52:30 +0100 | [diff] [blame] | 798 | PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 799 | return 1; |
| 800 | } |
| 801 | |
Serhiy Storchaka | 56f6e76 | 2015-09-06 21:25:30 +0300 | [diff] [blame] | 802 | i = _PyLong_AsInt(obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 803 | if (i == -1 && PyErr_Occurred()) |
| 804 | return 1; |
| 805 | *out = i; |
| 806 | return 0; |
| 807 | } |
| 808 | |
Benjamin Peterson | 1a6e0d0 | 2008-10-25 15:49:17 +0000 | [diff] [blame] | 809 | static int add_ast_fields(void) |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 810 | { |
| 811 | PyObject *empty_tuple, *d; |
| 812 | if (PyType_Ready(&AST_type) < 0) |
| 813 | return -1; |
| 814 | d = AST_type.tp_dict; |
| 815 | empty_tuple = PyTuple_New(0); |
| 816 | if (!empty_tuple || |
| 817 | PyDict_SetItemString(d, "_fields", empty_tuple) < 0 || |
| 818 | PyDict_SetItemString(d, "_attributes", empty_tuple) < 0) { |
| 819 | Py_XDECREF(empty_tuple); |
| 820 | return -1; |
| 821 | } |
| 822 | Py_DECREF(empty_tuple); |
| 823 | return 0; |
| 824 | } |
| 825 | |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 826 | static int exists_not_none(PyObject *obj, _Py_Identifier *id) |
| 827 | { |
Benjamin Peterson | 3a61943 | 2013-03-18 23:40:53 -0700 | [diff] [blame] | 828 | int isnone; |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 829 | PyObject *attr = _PyObject_GetAttrId(obj, id); |
| 830 | if (!attr) { |
| 831 | PyErr_Clear(); |
| 832 | return 0; |
| 833 | } |
Benjamin Peterson | 3a61943 | 2013-03-18 23:40:53 -0700 | [diff] [blame] | 834 | isnone = attr == Py_None; |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 835 | Py_DECREF(attr); |
| 836 | return !isnone; |
| 837 | } |
| 838 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 839 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 840 | static int init_types(void) |
| 841 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 842 | static int initialized; |
| 843 | if (initialized) return 1; |
| 844 | if (add_ast_fields() < 0) return 0; |
| 845 | mod_type = make_type("mod", &AST_type, NULL, 0); |
| 846 | if (!mod_type) return 0; |
| 847 | if (!add_attributes(mod_type, NULL, 0)) return 0; |
| 848 | Module_type = make_type("Module", mod_type, Module_fields, 1); |
| 849 | if (!Module_type) return 0; |
| 850 | Interactive_type = make_type("Interactive", mod_type, Interactive_fields, |
| 851 | 1); |
| 852 | if (!Interactive_type) return 0; |
| 853 | Expression_type = make_type("Expression", mod_type, Expression_fields, 1); |
| 854 | if (!Expression_type) return 0; |
| 855 | Suite_type = make_type("Suite", mod_type, Suite_fields, 1); |
| 856 | if (!Suite_type) return 0; |
| 857 | stmt_type = make_type("stmt", &AST_type, NULL, 0); |
| 858 | if (!stmt_type) return 0; |
| 859 | if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0; |
| 860 | FunctionDef_type = make_type("FunctionDef", stmt_type, FunctionDef_fields, |
| 861 | 5); |
| 862 | if (!FunctionDef_type) return 0; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 863 | AsyncFunctionDef_type = make_type("AsyncFunctionDef", stmt_type, |
| 864 | AsyncFunctionDef_fields, 5); |
| 865 | if (!AsyncFunctionDef_type) return 0; |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 866 | ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 5); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 867 | if (!ClassDef_type) return 0; |
| 868 | Return_type = make_type("Return", stmt_type, Return_fields, 1); |
| 869 | if (!Return_type) return 0; |
| 870 | Delete_type = make_type("Delete", stmt_type, Delete_fields, 1); |
| 871 | if (!Delete_type) return 0; |
| 872 | Assign_type = make_type("Assign", stmt_type, Assign_fields, 2); |
| 873 | if (!Assign_type) return 0; |
| 874 | AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); |
| 875 | if (!AugAssign_type) return 0; |
| 876 | For_type = make_type("For", stmt_type, For_fields, 4); |
| 877 | if (!For_type) return 0; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 878 | AsyncFor_type = make_type("AsyncFor", stmt_type, AsyncFor_fields, 4); |
| 879 | if (!AsyncFor_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 880 | While_type = make_type("While", stmt_type, While_fields, 3); |
| 881 | if (!While_type) return 0; |
| 882 | If_type = make_type("If", stmt_type, If_fields, 3); |
| 883 | if (!If_type) return 0; |
| 884 | With_type = make_type("With", stmt_type, With_fields, 2); |
| 885 | if (!With_type) return 0; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 886 | AsyncWith_type = make_type("AsyncWith", stmt_type, AsyncWith_fields, 2); |
| 887 | if (!AsyncWith_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 888 | Raise_type = make_type("Raise", stmt_type, Raise_fields, 2); |
| 889 | if (!Raise_type) return 0; |
| 890 | Try_type = make_type("Try", stmt_type, Try_fields, 4); |
| 891 | if (!Try_type) return 0; |
| 892 | Assert_type = make_type("Assert", stmt_type, Assert_fields, 2); |
| 893 | if (!Assert_type) return 0; |
| 894 | Import_type = make_type("Import", stmt_type, Import_fields, 1); |
| 895 | if (!Import_type) return 0; |
| 896 | ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, 3); |
| 897 | if (!ImportFrom_type) return 0; |
| 898 | Global_type = make_type("Global", stmt_type, Global_fields, 1); |
| 899 | if (!Global_type) return 0; |
| 900 | Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1); |
| 901 | if (!Nonlocal_type) return 0; |
| 902 | Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); |
| 903 | if (!Expr_type) return 0; |
| 904 | Pass_type = make_type("Pass", stmt_type, NULL, 0); |
| 905 | if (!Pass_type) return 0; |
| 906 | Break_type = make_type("Break", stmt_type, NULL, 0); |
| 907 | if (!Break_type) return 0; |
| 908 | Continue_type = make_type("Continue", stmt_type, NULL, 0); |
| 909 | if (!Continue_type) return 0; |
| 910 | expr_type = make_type("expr", &AST_type, NULL, 0); |
| 911 | if (!expr_type) return 0; |
| 912 | if (!add_attributes(expr_type, expr_attributes, 2)) return 0; |
| 913 | BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2); |
| 914 | if (!BoolOp_type) return 0; |
| 915 | BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3); |
| 916 | if (!BinOp_type) return 0; |
| 917 | UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2); |
| 918 | if (!UnaryOp_type) return 0; |
| 919 | Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2); |
| 920 | if (!Lambda_type) return 0; |
| 921 | IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); |
| 922 | if (!IfExp_type) return 0; |
| 923 | Dict_type = make_type("Dict", expr_type, Dict_fields, 2); |
| 924 | if (!Dict_type) return 0; |
| 925 | Set_type = make_type("Set", expr_type, Set_fields, 1); |
| 926 | if (!Set_type) return 0; |
| 927 | ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); |
| 928 | if (!ListComp_type) return 0; |
| 929 | SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2); |
| 930 | if (!SetComp_type) return 0; |
| 931 | DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3); |
| 932 | if (!DictComp_type) return 0; |
| 933 | GeneratorExp_type = make_type("GeneratorExp", expr_type, |
| 934 | GeneratorExp_fields, 2); |
| 935 | if (!GeneratorExp_type) return 0; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 936 | Await_type = make_type("Await", expr_type, Await_fields, 1); |
| 937 | if (!Await_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 938 | Yield_type = make_type("Yield", expr_type, Yield_fields, 1); |
| 939 | if (!Yield_type) return 0; |
| 940 | YieldFrom_type = make_type("YieldFrom", expr_type, YieldFrom_fields, 1); |
| 941 | if (!YieldFrom_type) return 0; |
| 942 | Compare_type = make_type("Compare", expr_type, Compare_fields, 3); |
| 943 | if (!Compare_type) return 0; |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 944 | Call_type = make_type("Call", expr_type, Call_fields, 3); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 945 | if (!Call_type) return 0; |
| 946 | Num_type = make_type("Num", expr_type, Num_fields, 1); |
| 947 | if (!Num_type) return 0; |
| 948 | Str_type = make_type("Str", expr_type, Str_fields, 1); |
| 949 | if (!Str_type) return 0; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 950 | FormattedValue_type = make_type("FormattedValue", expr_type, |
| 951 | FormattedValue_fields, 3); |
| 952 | if (!FormattedValue_type) return 0; |
| 953 | JoinedStr_type = make_type("JoinedStr", expr_type, JoinedStr_fields, 1); |
| 954 | if (!JoinedStr_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 955 | Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1); |
| 956 | if (!Bytes_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 957 | NameConstant_type = make_type("NameConstant", expr_type, |
| 958 | NameConstant_fields, 1); |
| 959 | if (!NameConstant_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 960 | Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0); |
| 961 | if (!Ellipsis_type) return 0; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 962 | Constant_type = make_type("Constant", expr_type, Constant_fields, 1); |
| 963 | if (!Constant_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 964 | Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); |
| 965 | if (!Attribute_type) return 0; |
| 966 | Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); |
| 967 | if (!Subscript_type) return 0; |
| 968 | Starred_type = make_type("Starred", expr_type, Starred_fields, 2); |
| 969 | if (!Starred_type) return 0; |
| 970 | Name_type = make_type("Name", expr_type, Name_fields, 2); |
| 971 | if (!Name_type) return 0; |
| 972 | List_type = make_type("List", expr_type, List_fields, 2); |
| 973 | if (!List_type) return 0; |
| 974 | Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2); |
| 975 | if (!Tuple_type) return 0; |
| 976 | expr_context_type = make_type("expr_context", &AST_type, NULL, 0); |
| 977 | if (!expr_context_type) return 0; |
| 978 | if (!add_attributes(expr_context_type, NULL, 0)) return 0; |
| 979 | Load_type = make_type("Load", expr_context_type, NULL, 0); |
| 980 | if (!Load_type) return 0; |
| 981 | Load_singleton = PyType_GenericNew(Load_type, NULL, NULL); |
| 982 | if (!Load_singleton) return 0; |
| 983 | Store_type = make_type("Store", expr_context_type, NULL, 0); |
| 984 | if (!Store_type) return 0; |
| 985 | Store_singleton = PyType_GenericNew(Store_type, NULL, NULL); |
| 986 | if (!Store_singleton) return 0; |
| 987 | Del_type = make_type("Del", expr_context_type, NULL, 0); |
| 988 | if (!Del_type) return 0; |
| 989 | Del_singleton = PyType_GenericNew(Del_type, NULL, NULL); |
| 990 | if (!Del_singleton) return 0; |
| 991 | AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0); |
| 992 | if (!AugLoad_type) return 0; |
| 993 | AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL); |
| 994 | if (!AugLoad_singleton) return 0; |
| 995 | AugStore_type = make_type("AugStore", expr_context_type, NULL, 0); |
| 996 | if (!AugStore_type) return 0; |
| 997 | AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL); |
| 998 | if (!AugStore_singleton) return 0; |
| 999 | Param_type = make_type("Param", expr_context_type, NULL, 0); |
| 1000 | if (!Param_type) return 0; |
| 1001 | Param_singleton = PyType_GenericNew(Param_type, NULL, NULL); |
| 1002 | if (!Param_singleton) return 0; |
| 1003 | slice_type = make_type("slice", &AST_type, NULL, 0); |
| 1004 | if (!slice_type) return 0; |
| 1005 | if (!add_attributes(slice_type, NULL, 0)) return 0; |
| 1006 | Slice_type = make_type("Slice", slice_type, Slice_fields, 3); |
| 1007 | if (!Slice_type) return 0; |
| 1008 | ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); |
| 1009 | if (!ExtSlice_type) return 0; |
| 1010 | Index_type = make_type("Index", slice_type, Index_fields, 1); |
| 1011 | if (!Index_type) return 0; |
| 1012 | boolop_type = make_type("boolop", &AST_type, NULL, 0); |
| 1013 | if (!boolop_type) return 0; |
| 1014 | if (!add_attributes(boolop_type, NULL, 0)) return 0; |
| 1015 | And_type = make_type("And", boolop_type, NULL, 0); |
| 1016 | if (!And_type) return 0; |
| 1017 | And_singleton = PyType_GenericNew(And_type, NULL, NULL); |
| 1018 | if (!And_singleton) return 0; |
| 1019 | Or_type = make_type("Or", boolop_type, NULL, 0); |
| 1020 | if (!Or_type) return 0; |
| 1021 | Or_singleton = PyType_GenericNew(Or_type, NULL, NULL); |
| 1022 | if (!Or_singleton) return 0; |
| 1023 | operator_type = make_type("operator", &AST_type, NULL, 0); |
| 1024 | if (!operator_type) return 0; |
| 1025 | if (!add_attributes(operator_type, NULL, 0)) return 0; |
| 1026 | Add_type = make_type("Add", operator_type, NULL, 0); |
| 1027 | if (!Add_type) return 0; |
| 1028 | Add_singleton = PyType_GenericNew(Add_type, NULL, NULL); |
| 1029 | if (!Add_singleton) return 0; |
| 1030 | Sub_type = make_type("Sub", operator_type, NULL, 0); |
| 1031 | if (!Sub_type) return 0; |
| 1032 | Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL); |
| 1033 | if (!Sub_singleton) return 0; |
| 1034 | Mult_type = make_type("Mult", operator_type, NULL, 0); |
| 1035 | if (!Mult_type) return 0; |
| 1036 | Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL); |
| 1037 | if (!Mult_singleton) return 0; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 1038 | MatMult_type = make_type("MatMult", operator_type, NULL, 0); |
| 1039 | if (!MatMult_type) return 0; |
| 1040 | MatMult_singleton = PyType_GenericNew(MatMult_type, NULL, NULL); |
| 1041 | if (!MatMult_singleton) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1042 | Div_type = make_type("Div", operator_type, NULL, 0); |
| 1043 | if (!Div_type) return 0; |
| 1044 | Div_singleton = PyType_GenericNew(Div_type, NULL, NULL); |
| 1045 | if (!Div_singleton) return 0; |
| 1046 | Mod_type = make_type("Mod", operator_type, NULL, 0); |
| 1047 | if (!Mod_type) return 0; |
| 1048 | Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL); |
| 1049 | if (!Mod_singleton) return 0; |
| 1050 | Pow_type = make_type("Pow", operator_type, NULL, 0); |
| 1051 | if (!Pow_type) return 0; |
| 1052 | Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL); |
| 1053 | if (!Pow_singleton) return 0; |
| 1054 | LShift_type = make_type("LShift", operator_type, NULL, 0); |
| 1055 | if (!LShift_type) return 0; |
| 1056 | LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL); |
| 1057 | if (!LShift_singleton) return 0; |
| 1058 | RShift_type = make_type("RShift", operator_type, NULL, 0); |
| 1059 | if (!RShift_type) return 0; |
| 1060 | RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL); |
| 1061 | if (!RShift_singleton) return 0; |
| 1062 | BitOr_type = make_type("BitOr", operator_type, NULL, 0); |
| 1063 | if (!BitOr_type) return 0; |
| 1064 | BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL); |
| 1065 | if (!BitOr_singleton) return 0; |
| 1066 | BitXor_type = make_type("BitXor", operator_type, NULL, 0); |
| 1067 | if (!BitXor_type) return 0; |
| 1068 | BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL); |
| 1069 | if (!BitXor_singleton) return 0; |
| 1070 | BitAnd_type = make_type("BitAnd", operator_type, NULL, 0); |
| 1071 | if (!BitAnd_type) return 0; |
| 1072 | BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL); |
| 1073 | if (!BitAnd_singleton) return 0; |
| 1074 | FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0); |
| 1075 | if (!FloorDiv_type) return 0; |
| 1076 | FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL); |
| 1077 | if (!FloorDiv_singleton) return 0; |
| 1078 | unaryop_type = make_type("unaryop", &AST_type, NULL, 0); |
| 1079 | if (!unaryop_type) return 0; |
| 1080 | if (!add_attributes(unaryop_type, NULL, 0)) return 0; |
| 1081 | Invert_type = make_type("Invert", unaryop_type, NULL, 0); |
| 1082 | if (!Invert_type) return 0; |
| 1083 | Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL); |
| 1084 | if (!Invert_singleton) return 0; |
| 1085 | Not_type = make_type("Not", unaryop_type, NULL, 0); |
| 1086 | if (!Not_type) return 0; |
| 1087 | Not_singleton = PyType_GenericNew(Not_type, NULL, NULL); |
| 1088 | if (!Not_singleton) return 0; |
| 1089 | UAdd_type = make_type("UAdd", unaryop_type, NULL, 0); |
| 1090 | if (!UAdd_type) return 0; |
| 1091 | UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL); |
| 1092 | if (!UAdd_singleton) return 0; |
| 1093 | USub_type = make_type("USub", unaryop_type, NULL, 0); |
| 1094 | if (!USub_type) return 0; |
| 1095 | USub_singleton = PyType_GenericNew(USub_type, NULL, NULL); |
| 1096 | if (!USub_singleton) return 0; |
| 1097 | cmpop_type = make_type("cmpop", &AST_type, NULL, 0); |
| 1098 | if (!cmpop_type) return 0; |
| 1099 | if (!add_attributes(cmpop_type, NULL, 0)) return 0; |
| 1100 | Eq_type = make_type("Eq", cmpop_type, NULL, 0); |
| 1101 | if (!Eq_type) return 0; |
| 1102 | Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL); |
| 1103 | if (!Eq_singleton) return 0; |
| 1104 | NotEq_type = make_type("NotEq", cmpop_type, NULL, 0); |
| 1105 | if (!NotEq_type) return 0; |
| 1106 | NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL); |
| 1107 | if (!NotEq_singleton) return 0; |
| 1108 | Lt_type = make_type("Lt", cmpop_type, NULL, 0); |
| 1109 | if (!Lt_type) return 0; |
| 1110 | Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL); |
| 1111 | if (!Lt_singleton) return 0; |
| 1112 | LtE_type = make_type("LtE", cmpop_type, NULL, 0); |
| 1113 | if (!LtE_type) return 0; |
| 1114 | LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL); |
| 1115 | if (!LtE_singleton) return 0; |
| 1116 | Gt_type = make_type("Gt", cmpop_type, NULL, 0); |
| 1117 | if (!Gt_type) return 0; |
| 1118 | Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL); |
| 1119 | if (!Gt_singleton) return 0; |
| 1120 | GtE_type = make_type("GtE", cmpop_type, NULL, 0); |
| 1121 | if (!GtE_type) return 0; |
| 1122 | GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL); |
| 1123 | if (!GtE_singleton) return 0; |
| 1124 | Is_type = make_type("Is", cmpop_type, NULL, 0); |
| 1125 | if (!Is_type) return 0; |
| 1126 | Is_singleton = PyType_GenericNew(Is_type, NULL, NULL); |
| 1127 | if (!Is_singleton) return 0; |
| 1128 | IsNot_type = make_type("IsNot", cmpop_type, NULL, 0); |
| 1129 | if (!IsNot_type) return 0; |
| 1130 | IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL); |
| 1131 | if (!IsNot_singleton) return 0; |
| 1132 | In_type = make_type("In", cmpop_type, NULL, 0); |
| 1133 | if (!In_type) return 0; |
| 1134 | In_singleton = PyType_GenericNew(In_type, NULL, NULL); |
| 1135 | if (!In_singleton) return 0; |
| 1136 | NotIn_type = make_type("NotIn", cmpop_type, NULL, 0); |
| 1137 | if (!NotIn_type) return 0; |
| 1138 | NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL); |
| 1139 | if (!NotIn_singleton) return 0; |
| 1140 | comprehension_type = make_type("comprehension", &AST_type, |
| 1141 | comprehension_fields, 3); |
| 1142 | if (!comprehension_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1143 | if (!add_attributes(comprehension_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1144 | excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0); |
| 1145 | if (!excepthandler_type) return 0; |
| 1146 | if (!add_attributes(excepthandler_type, excepthandler_attributes, 2)) |
| 1147 | return 0; |
| 1148 | ExceptHandler_type = make_type("ExceptHandler", excepthandler_type, |
| 1149 | ExceptHandler_fields, 3); |
| 1150 | if (!ExceptHandler_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1151 | arguments_type = make_type("arguments", &AST_type, arguments_fields, 6); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1152 | if (!arguments_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1153 | if (!add_attributes(arguments_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1154 | arg_type = make_type("arg", &AST_type, arg_fields, 2); |
| 1155 | if (!arg_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1156 | if (!add_attributes(arg_type, arg_attributes, 2)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1157 | keyword_type = make_type("keyword", &AST_type, keyword_fields, 2); |
| 1158 | if (!keyword_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1159 | if (!add_attributes(keyword_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1160 | alias_type = make_type("alias", &AST_type, alias_fields, 2); |
| 1161 | if (!alias_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1162 | if (!add_attributes(alias_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1163 | withitem_type = make_type("withitem", &AST_type, withitem_fields, 2); |
| 1164 | if (!withitem_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1165 | if (!add_attributes(withitem_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1166 | initialized = 1; |
| 1167 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1168 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 1169 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1170 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 1171 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 1172 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 1173 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 1174 | arena); |
| 1175 | static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena); |
| 1176 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 1177 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 1178 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 1179 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 1180 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 1181 | arena); |
| 1182 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 1183 | arena); |
| 1184 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 1185 | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
| 1186 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 1187 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1188 | 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] | 1189 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1190 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1191 | Module(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1192 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1193 | mod_ty p; |
| 1194 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1195 | if (!p) |
| 1196 | return NULL; |
| 1197 | p->kind = Module_kind; |
| 1198 | p->v.Module.body = body; |
| 1199 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1203 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1204 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1205 | mod_ty p; |
| 1206 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1207 | if (!p) |
| 1208 | return NULL; |
| 1209 | p->kind = Interactive_kind; |
| 1210 | p->v.Interactive.body = body; |
| 1211 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1212 | } |
| 1213 | |
| 1214 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1215 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1216 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1217 | mod_ty p; |
| 1218 | if (!body) { |
| 1219 | PyErr_SetString(PyExc_ValueError, |
| 1220 | "field body is required for Expression"); |
| 1221 | return NULL; |
| 1222 | } |
| 1223 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1224 | if (!p) |
| 1225 | return NULL; |
| 1226 | p->kind = Expression_kind; |
| 1227 | p->v.Expression.body = body; |
| 1228 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1232 | Suite(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1233 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1234 | mod_ty p; |
| 1235 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1236 | if (!p) |
| 1237 | return NULL; |
| 1238 | p->kind = Suite_kind; |
| 1239 | p->v.Suite.body = body; |
| 1240 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | stmt_ty |
| 1244 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1245 | decorator_list, expr_ty returns, int lineno, int col_offset, |
| 1246 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1247 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1248 | stmt_ty p; |
| 1249 | if (!name) { |
| 1250 | PyErr_SetString(PyExc_ValueError, |
| 1251 | "field name is required for FunctionDef"); |
| 1252 | return NULL; |
| 1253 | } |
| 1254 | if (!args) { |
| 1255 | PyErr_SetString(PyExc_ValueError, |
| 1256 | "field args is required for FunctionDef"); |
| 1257 | return NULL; |
| 1258 | } |
| 1259 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1260 | if (!p) |
| 1261 | return NULL; |
| 1262 | p->kind = FunctionDef_kind; |
| 1263 | p->v.FunctionDef.name = name; |
| 1264 | p->v.FunctionDef.args = args; |
| 1265 | p->v.FunctionDef.body = body; |
| 1266 | p->v.FunctionDef.decorator_list = decorator_list; |
| 1267 | p->v.FunctionDef.returns = returns; |
| 1268 | p->lineno = lineno; |
| 1269 | p->col_offset = col_offset; |
| 1270 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1271 | } |
| 1272 | |
| 1273 | stmt_ty |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1274 | AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq |
| 1275 | * decorator_list, expr_ty returns, int lineno, int col_offset, |
| 1276 | PyArena *arena) |
| 1277 | { |
| 1278 | stmt_ty p; |
| 1279 | if (!name) { |
| 1280 | PyErr_SetString(PyExc_ValueError, |
| 1281 | "field name is required for AsyncFunctionDef"); |
| 1282 | return NULL; |
| 1283 | } |
| 1284 | if (!args) { |
| 1285 | PyErr_SetString(PyExc_ValueError, |
| 1286 | "field args is required for AsyncFunctionDef"); |
| 1287 | return NULL; |
| 1288 | } |
| 1289 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1290 | if (!p) |
| 1291 | return NULL; |
| 1292 | p->kind = AsyncFunctionDef_kind; |
| 1293 | p->v.AsyncFunctionDef.name = name; |
| 1294 | p->v.AsyncFunctionDef.args = args; |
| 1295 | p->v.AsyncFunctionDef.body = body; |
| 1296 | p->v.AsyncFunctionDef.decorator_list = decorator_list; |
| 1297 | p->v.AsyncFunctionDef.returns = returns; |
| 1298 | p->lineno = lineno; |
| 1299 | p->col_offset = col_offset; |
| 1300 | return p; |
| 1301 | } |
| 1302 | |
| 1303 | stmt_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 1304 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq * |
| 1305 | body, asdl_seq * decorator_list, int lineno, int col_offset, PyArena |
| 1306 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1307 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1308 | stmt_ty p; |
| 1309 | if (!name) { |
| 1310 | PyErr_SetString(PyExc_ValueError, |
| 1311 | "field name is required for ClassDef"); |
| 1312 | return NULL; |
| 1313 | } |
| 1314 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1315 | if (!p) |
| 1316 | return NULL; |
| 1317 | p->kind = ClassDef_kind; |
| 1318 | p->v.ClassDef.name = name; |
| 1319 | p->v.ClassDef.bases = bases; |
| 1320 | p->v.ClassDef.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1321 | p->v.ClassDef.body = body; |
| 1322 | p->v.ClassDef.decorator_list = decorator_list; |
| 1323 | p->lineno = lineno; |
| 1324 | p->col_offset = col_offset; |
| 1325 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1326 | } |
| 1327 | |
| 1328 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1329 | Return(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1330 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1331 | stmt_ty p; |
| 1332 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1333 | if (!p) |
| 1334 | return NULL; |
| 1335 | p->kind = Return_kind; |
| 1336 | p->v.Return.value = value; |
| 1337 | p->lineno = lineno; |
| 1338 | p->col_offset = col_offset; |
| 1339 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1340 | } |
| 1341 | |
| 1342 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1343 | Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1344 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1345 | stmt_ty p; |
| 1346 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1347 | if (!p) |
| 1348 | return NULL; |
| 1349 | p->kind = Delete_kind; |
| 1350 | p->v.Delete.targets = targets; |
| 1351 | p->lineno = lineno; |
| 1352 | p->col_offset = col_offset; |
| 1353 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1357 | Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena |
| 1358 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1359 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1360 | stmt_ty p; |
| 1361 | if (!value) { |
| 1362 | PyErr_SetString(PyExc_ValueError, |
| 1363 | "field value is required for Assign"); |
| 1364 | return NULL; |
| 1365 | } |
| 1366 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1367 | if (!p) |
| 1368 | return NULL; |
| 1369 | p->kind = Assign_kind; |
| 1370 | p->v.Assign.targets = targets; |
| 1371 | p->v.Assign.value = value; |
| 1372 | p->lineno = lineno; |
| 1373 | p->col_offset = col_offset; |
| 1374 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1378 | AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int |
| 1379 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1380 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1381 | stmt_ty p; |
| 1382 | if (!target) { |
| 1383 | PyErr_SetString(PyExc_ValueError, |
| 1384 | "field target is required for AugAssign"); |
| 1385 | return NULL; |
| 1386 | } |
| 1387 | if (!op) { |
| 1388 | PyErr_SetString(PyExc_ValueError, |
| 1389 | "field op is required for AugAssign"); |
| 1390 | return NULL; |
| 1391 | } |
| 1392 | if (!value) { |
| 1393 | PyErr_SetString(PyExc_ValueError, |
| 1394 | "field value is required for AugAssign"); |
| 1395 | return NULL; |
| 1396 | } |
| 1397 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1398 | if (!p) |
| 1399 | return NULL; |
| 1400 | p->kind = AugAssign_kind; |
| 1401 | p->v.AugAssign.target = target; |
| 1402 | p->v.AugAssign.op = op; |
| 1403 | p->v.AugAssign.value = value; |
| 1404 | p->lineno = lineno; |
| 1405 | p->col_offset = col_offset; |
| 1406 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1407 | } |
| 1408 | |
| 1409 | stmt_ty |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1410 | 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] | 1411 | lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1412 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1413 | stmt_ty p; |
| 1414 | if (!target) { |
| 1415 | PyErr_SetString(PyExc_ValueError, |
| 1416 | "field target is required for For"); |
| 1417 | return NULL; |
| 1418 | } |
| 1419 | if (!iter) { |
| 1420 | PyErr_SetString(PyExc_ValueError, |
| 1421 | "field iter is required for For"); |
| 1422 | return NULL; |
| 1423 | } |
| 1424 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1425 | if (!p) |
| 1426 | return NULL; |
| 1427 | p->kind = For_kind; |
| 1428 | p->v.For.target = target; |
| 1429 | p->v.For.iter = iter; |
| 1430 | p->v.For.body = body; |
| 1431 | p->v.For.orelse = orelse; |
| 1432 | p->lineno = lineno; |
| 1433 | p->col_offset = col_offset; |
| 1434 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1435 | } |
| 1436 | |
| 1437 | stmt_ty |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1438 | AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int |
| 1439 | lineno, int col_offset, PyArena *arena) |
| 1440 | { |
| 1441 | stmt_ty p; |
| 1442 | if (!target) { |
| 1443 | PyErr_SetString(PyExc_ValueError, |
| 1444 | "field target is required for AsyncFor"); |
| 1445 | return NULL; |
| 1446 | } |
| 1447 | if (!iter) { |
| 1448 | PyErr_SetString(PyExc_ValueError, |
| 1449 | "field iter is required for AsyncFor"); |
| 1450 | return NULL; |
| 1451 | } |
| 1452 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1453 | if (!p) |
| 1454 | return NULL; |
| 1455 | p->kind = AsyncFor_kind; |
| 1456 | p->v.AsyncFor.target = target; |
| 1457 | p->v.AsyncFor.iter = iter; |
| 1458 | p->v.AsyncFor.body = body; |
| 1459 | p->v.AsyncFor.orelse = orelse; |
| 1460 | p->lineno = lineno; |
| 1461 | p->col_offset = col_offset; |
| 1462 | return p; |
| 1463 | } |
| 1464 | |
| 1465 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1466 | While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1467 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1468 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1469 | stmt_ty p; |
| 1470 | if (!test) { |
| 1471 | PyErr_SetString(PyExc_ValueError, |
| 1472 | "field test is required for While"); |
| 1473 | return NULL; |
| 1474 | } |
| 1475 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1476 | if (!p) |
| 1477 | return NULL; |
| 1478 | p->kind = While_kind; |
| 1479 | p->v.While.test = test; |
| 1480 | p->v.While.body = body; |
| 1481 | p->v.While.orelse = orelse; |
| 1482 | p->lineno = lineno; |
| 1483 | p->col_offset = col_offset; |
| 1484 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1485 | } |
| 1486 | |
| 1487 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1488 | If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1489 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1490 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1491 | stmt_ty p; |
| 1492 | if (!test) { |
| 1493 | PyErr_SetString(PyExc_ValueError, |
| 1494 | "field test is required for If"); |
| 1495 | return NULL; |
| 1496 | } |
| 1497 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1498 | if (!p) |
| 1499 | return NULL; |
| 1500 | p->kind = If_kind; |
| 1501 | p->v.If.test = test; |
| 1502 | p->v.If.body = body; |
| 1503 | p->v.If.orelse = orelse; |
| 1504 | p->lineno = lineno; |
| 1505 | p->col_offset = col_offset; |
| 1506 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1507 | } |
| 1508 | |
| 1509 | stmt_ty |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1510 | With(asdl_seq * items, asdl_seq * body, int lineno, int col_offset, PyArena |
| 1511 | *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1512 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1513 | stmt_ty p; |
| 1514 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1515 | if (!p) |
| 1516 | return NULL; |
| 1517 | p->kind = With_kind; |
| 1518 | p->v.With.items = items; |
| 1519 | p->v.With.body = body; |
| 1520 | p->lineno = lineno; |
| 1521 | p->col_offset = col_offset; |
| 1522 | return p; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1523 | } |
| 1524 | |
| 1525 | stmt_ty |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1526 | AsyncWith(asdl_seq * items, asdl_seq * body, int lineno, int col_offset, |
| 1527 | PyArena *arena) |
| 1528 | { |
| 1529 | stmt_ty p; |
| 1530 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1531 | if (!p) |
| 1532 | return NULL; |
| 1533 | p->kind = AsyncWith_kind; |
| 1534 | p->v.AsyncWith.items = items; |
| 1535 | p->v.AsyncWith.body = body; |
| 1536 | p->lineno = lineno; |
| 1537 | p->col_offset = col_offset; |
| 1538 | return p; |
| 1539 | } |
| 1540 | |
| 1541 | stmt_ty |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 1542 | 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] | 1543 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1544 | stmt_ty p; |
| 1545 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1546 | if (!p) |
| 1547 | return NULL; |
| 1548 | p->kind = Raise_kind; |
| 1549 | p->v.Raise.exc = exc; |
| 1550 | p->v.Raise.cause = cause; |
| 1551 | p->lineno = lineno; |
| 1552 | p->col_offset = col_offset; |
| 1553 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1554 | } |
| 1555 | |
| 1556 | stmt_ty |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 1557 | Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * |
| 1558 | finalbody, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1559 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1560 | stmt_ty p; |
| 1561 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1562 | if (!p) |
| 1563 | return NULL; |
| 1564 | p->kind = Try_kind; |
| 1565 | p->v.Try.body = body; |
| 1566 | p->v.Try.handlers = handlers; |
| 1567 | p->v.Try.orelse = orelse; |
| 1568 | p->v.Try.finalbody = finalbody; |
| 1569 | p->lineno = lineno; |
| 1570 | p->col_offset = col_offset; |
| 1571 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1572 | } |
| 1573 | |
| 1574 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1575 | 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] | 1576 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1577 | stmt_ty p; |
| 1578 | if (!test) { |
| 1579 | PyErr_SetString(PyExc_ValueError, |
| 1580 | "field test is required for Assert"); |
| 1581 | return NULL; |
| 1582 | } |
| 1583 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1584 | if (!p) |
| 1585 | return NULL; |
| 1586 | p->kind = Assert_kind; |
| 1587 | p->v.Assert.test = test; |
| 1588 | p->v.Assert.msg = msg; |
| 1589 | p->lineno = lineno; |
| 1590 | p->col_offset = col_offset; |
| 1591 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1592 | } |
| 1593 | |
| 1594 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1595 | Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1596 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1597 | stmt_ty p; |
| 1598 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1599 | if (!p) |
| 1600 | return NULL; |
| 1601 | p->kind = Import_kind; |
| 1602 | p->v.Import.names = names; |
| 1603 | p->lineno = lineno; |
| 1604 | p->col_offset = col_offset; |
| 1605 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1606 | } |
| 1607 | |
| 1608 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1609 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
| 1610 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1611 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1612 | stmt_ty p; |
| 1613 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1614 | if (!p) |
| 1615 | return NULL; |
| 1616 | p->kind = ImportFrom_kind; |
| 1617 | p->v.ImportFrom.module = module; |
| 1618 | p->v.ImportFrom.names = names; |
| 1619 | p->v.ImportFrom.level = level; |
| 1620 | p->lineno = lineno; |
| 1621 | p->col_offset = col_offset; |
| 1622 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1623 | } |
| 1624 | |
| 1625 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1626 | Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1627 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1628 | stmt_ty p; |
| 1629 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1630 | if (!p) |
| 1631 | return NULL; |
| 1632 | p->kind = Global_kind; |
| 1633 | p->v.Global.names = names; |
| 1634 | p->lineno = lineno; |
| 1635 | p->col_offset = col_offset; |
| 1636 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1637 | } |
| 1638 | |
| 1639 | stmt_ty |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 1640 | Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
| 1641 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1642 | stmt_ty p; |
| 1643 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1644 | if (!p) |
| 1645 | return NULL; |
| 1646 | p->kind = Nonlocal_kind; |
| 1647 | p->v.Nonlocal.names = names; |
| 1648 | p->lineno = lineno; |
| 1649 | p->col_offset = col_offset; |
| 1650 | return p; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 1651 | } |
| 1652 | |
| 1653 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1654 | Expr(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1655 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1656 | stmt_ty p; |
| 1657 | if (!value) { |
| 1658 | PyErr_SetString(PyExc_ValueError, |
| 1659 | "field value is required for Expr"); |
| 1660 | return NULL; |
| 1661 | } |
| 1662 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1663 | if (!p) |
| 1664 | return NULL; |
| 1665 | p->kind = Expr_kind; |
| 1666 | p->v.Expr.value = value; |
| 1667 | p->lineno = lineno; |
| 1668 | p->col_offset = col_offset; |
| 1669 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1670 | } |
| 1671 | |
| 1672 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1673 | Pass(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1674 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1675 | stmt_ty p; |
| 1676 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1677 | if (!p) |
| 1678 | return NULL; |
| 1679 | p->kind = Pass_kind; |
| 1680 | p->lineno = lineno; |
| 1681 | p->col_offset = col_offset; |
| 1682 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1683 | } |
| 1684 | |
| 1685 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1686 | Break(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1687 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1688 | stmt_ty p; |
| 1689 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1690 | if (!p) |
| 1691 | return NULL; |
| 1692 | p->kind = Break_kind; |
| 1693 | p->lineno = lineno; |
| 1694 | p->col_offset = col_offset; |
| 1695 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1696 | } |
| 1697 | |
| 1698 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1699 | Continue(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1700 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1701 | stmt_ty p; |
| 1702 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1703 | if (!p) |
| 1704 | return NULL; |
| 1705 | p->kind = Continue_kind; |
| 1706 | p->lineno = lineno; |
| 1707 | p->col_offset = col_offset; |
| 1708 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1709 | } |
| 1710 | |
| 1711 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1712 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1713 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1714 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1715 | expr_ty p; |
| 1716 | if (!op) { |
| 1717 | PyErr_SetString(PyExc_ValueError, |
| 1718 | "field op is required for BoolOp"); |
| 1719 | return NULL; |
| 1720 | } |
| 1721 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1722 | if (!p) |
| 1723 | return NULL; |
| 1724 | p->kind = BoolOp_kind; |
| 1725 | p->v.BoolOp.op = op; |
| 1726 | p->v.BoolOp.values = values; |
| 1727 | p->lineno = lineno; |
| 1728 | p->col_offset = col_offset; |
| 1729 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1730 | } |
| 1731 | |
| 1732 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1733 | BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset, |
| 1734 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1735 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1736 | expr_ty p; |
| 1737 | if (!left) { |
| 1738 | PyErr_SetString(PyExc_ValueError, |
| 1739 | "field left is required for BinOp"); |
| 1740 | return NULL; |
| 1741 | } |
| 1742 | if (!op) { |
| 1743 | PyErr_SetString(PyExc_ValueError, |
| 1744 | "field op is required for BinOp"); |
| 1745 | return NULL; |
| 1746 | } |
| 1747 | if (!right) { |
| 1748 | PyErr_SetString(PyExc_ValueError, |
| 1749 | "field right is required for BinOp"); |
| 1750 | return NULL; |
| 1751 | } |
| 1752 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1753 | if (!p) |
| 1754 | return NULL; |
| 1755 | p->kind = BinOp_kind; |
| 1756 | p->v.BinOp.left = left; |
| 1757 | p->v.BinOp.op = op; |
| 1758 | p->v.BinOp.right = right; |
| 1759 | p->lineno = lineno; |
| 1760 | p->col_offset = col_offset; |
| 1761 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1762 | } |
| 1763 | |
| 1764 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1765 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena |
| 1766 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1767 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1768 | expr_ty p; |
| 1769 | if (!op) { |
| 1770 | PyErr_SetString(PyExc_ValueError, |
| 1771 | "field op is required for UnaryOp"); |
| 1772 | return NULL; |
| 1773 | } |
| 1774 | if (!operand) { |
| 1775 | PyErr_SetString(PyExc_ValueError, |
| 1776 | "field operand is required for UnaryOp"); |
| 1777 | return NULL; |
| 1778 | } |
| 1779 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1780 | if (!p) |
| 1781 | return NULL; |
| 1782 | p->kind = UnaryOp_kind; |
| 1783 | p->v.UnaryOp.op = op; |
| 1784 | p->v.UnaryOp.operand = operand; |
| 1785 | p->lineno = lineno; |
| 1786 | p->col_offset = col_offset; |
| 1787 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1788 | } |
| 1789 | |
| 1790 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1791 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena |
| 1792 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1793 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1794 | expr_ty p; |
| 1795 | if (!args) { |
| 1796 | PyErr_SetString(PyExc_ValueError, |
| 1797 | "field args is required for Lambda"); |
| 1798 | return NULL; |
| 1799 | } |
| 1800 | if (!body) { |
| 1801 | PyErr_SetString(PyExc_ValueError, |
| 1802 | "field body is required for Lambda"); |
| 1803 | return NULL; |
| 1804 | } |
| 1805 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1806 | if (!p) |
| 1807 | return NULL; |
| 1808 | p->kind = Lambda_kind; |
| 1809 | p->v.Lambda.args = args; |
| 1810 | p->v.Lambda.body = body; |
| 1811 | p->lineno = lineno; |
| 1812 | p->col_offset = col_offset; |
| 1813 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1814 | } |
| 1815 | |
| 1816 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1817 | IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset, |
| 1818 | PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1819 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1820 | expr_ty p; |
| 1821 | if (!test) { |
| 1822 | PyErr_SetString(PyExc_ValueError, |
| 1823 | "field test is required for IfExp"); |
| 1824 | return NULL; |
| 1825 | } |
| 1826 | if (!body) { |
| 1827 | PyErr_SetString(PyExc_ValueError, |
| 1828 | "field body is required for IfExp"); |
| 1829 | return NULL; |
| 1830 | } |
| 1831 | if (!orelse) { |
| 1832 | PyErr_SetString(PyExc_ValueError, |
| 1833 | "field orelse is required for IfExp"); |
| 1834 | return NULL; |
| 1835 | } |
| 1836 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1837 | if (!p) |
| 1838 | return NULL; |
| 1839 | p->kind = IfExp_kind; |
| 1840 | p->v.IfExp.test = test; |
| 1841 | p->v.IfExp.body = body; |
| 1842 | p->v.IfExp.orelse = orelse; |
| 1843 | p->lineno = lineno; |
| 1844 | p->col_offset = col_offset; |
| 1845 | return p; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1846 | } |
| 1847 | |
| 1848 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1849 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1850 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1851 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1852 | expr_ty p; |
| 1853 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1854 | if (!p) |
| 1855 | return NULL; |
| 1856 | p->kind = Dict_kind; |
| 1857 | p->v.Dict.keys = keys; |
| 1858 | p->v.Dict.values = values; |
| 1859 | p->lineno = lineno; |
| 1860 | p->col_offset = col_offset; |
| 1861 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1862 | } |
| 1863 | |
| 1864 | expr_ty |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1865 | Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena) |
| 1866 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1867 | expr_ty p; |
| 1868 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1869 | if (!p) |
| 1870 | return NULL; |
| 1871 | p->kind = Set_kind; |
| 1872 | p->v.Set.elts = elts; |
| 1873 | p->lineno = lineno; |
| 1874 | p->col_offset = col_offset; |
| 1875 | return p; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1876 | } |
| 1877 | |
| 1878 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1879 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1880 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1881 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1882 | expr_ty p; |
| 1883 | if (!elt) { |
| 1884 | PyErr_SetString(PyExc_ValueError, |
| 1885 | "field elt is required for ListComp"); |
| 1886 | return NULL; |
| 1887 | } |
| 1888 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1889 | if (!p) |
| 1890 | return NULL; |
| 1891 | p->kind = ListComp_kind; |
| 1892 | p->v.ListComp.elt = elt; |
| 1893 | p->v.ListComp.generators = generators; |
| 1894 | p->lineno = lineno; |
| 1895 | p->col_offset = col_offset; |
| 1896 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1897 | } |
| 1898 | |
| 1899 | expr_ty |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 1900 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena |
| 1901 | *arena) |
| 1902 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1903 | expr_ty p; |
| 1904 | if (!elt) { |
| 1905 | PyErr_SetString(PyExc_ValueError, |
| 1906 | "field elt is required for SetComp"); |
| 1907 | return NULL; |
| 1908 | } |
| 1909 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1910 | if (!p) |
| 1911 | return NULL; |
| 1912 | p->kind = SetComp_kind; |
| 1913 | p->v.SetComp.elt = elt; |
| 1914 | p->v.SetComp.generators = generators; |
| 1915 | p->lineno = lineno; |
| 1916 | p->col_offset = col_offset; |
| 1917 | return p; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 1918 | } |
| 1919 | |
| 1920 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 1921 | DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int |
| 1922 | col_offset, PyArena *arena) |
| 1923 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1924 | expr_ty p; |
| 1925 | if (!key) { |
| 1926 | PyErr_SetString(PyExc_ValueError, |
| 1927 | "field key is required for DictComp"); |
| 1928 | return NULL; |
| 1929 | } |
| 1930 | if (!value) { |
| 1931 | PyErr_SetString(PyExc_ValueError, |
| 1932 | "field value is required for DictComp"); |
| 1933 | return NULL; |
| 1934 | } |
| 1935 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1936 | if (!p) |
| 1937 | return NULL; |
| 1938 | p->kind = DictComp_kind; |
| 1939 | p->v.DictComp.key = key; |
| 1940 | p->v.DictComp.value = value; |
| 1941 | p->v.DictComp.generators = generators; |
| 1942 | p->lineno = lineno; |
| 1943 | p->col_offset = col_offset; |
| 1944 | return p; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 1945 | } |
| 1946 | |
| 1947 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1948 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1949 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1950 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1951 | expr_ty p; |
| 1952 | if (!elt) { |
| 1953 | PyErr_SetString(PyExc_ValueError, |
| 1954 | "field elt is required for GeneratorExp"); |
| 1955 | return NULL; |
| 1956 | } |
| 1957 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1958 | if (!p) |
| 1959 | return NULL; |
| 1960 | p->kind = GeneratorExp_kind; |
| 1961 | p->v.GeneratorExp.elt = elt; |
| 1962 | p->v.GeneratorExp.generators = generators; |
| 1963 | p->lineno = lineno; |
| 1964 | p->col_offset = col_offset; |
| 1965 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1966 | } |
| 1967 | |
| 1968 | expr_ty |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1969 | Await(expr_ty value, int lineno, int col_offset, PyArena *arena) |
| 1970 | { |
| 1971 | expr_ty p; |
| 1972 | if (!value) { |
| 1973 | PyErr_SetString(PyExc_ValueError, |
| 1974 | "field value is required for Await"); |
| 1975 | return NULL; |
| 1976 | } |
| 1977 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1978 | if (!p) |
| 1979 | return NULL; |
| 1980 | p->kind = Await_kind; |
| 1981 | p->v.Await.value = value; |
| 1982 | p->lineno = lineno; |
| 1983 | p->col_offset = col_offset; |
| 1984 | return p; |
| 1985 | } |
| 1986 | |
| 1987 | expr_ty |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 1988 | Yield(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 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 = Yield_kind; |
| 1995 | p->v.Yield.value = value; |
| 1996 | p->lineno = lineno; |
| 1997 | p->col_offset = col_offset; |
| 1998 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | expr_ty |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2002 | YieldFrom(expr_ty value, int lineno, int col_offset, PyArena *arena) |
| 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 YieldFrom"); |
| 2008 | return NULL; |
| 2009 | } |
| 2010 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2011 | if (!p) |
| 2012 | return NULL; |
| 2013 | p->kind = YieldFrom_kind; |
| 2014 | p->v.YieldFrom.value = value; |
| 2015 | p->lineno = lineno; |
| 2016 | p->col_offset = col_offset; |
| 2017 | return p; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2018 | } |
| 2019 | |
| 2020 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2021 | Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno, |
| 2022 | int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2023 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2024 | expr_ty p; |
| 2025 | if (!left) { |
| 2026 | PyErr_SetString(PyExc_ValueError, |
| 2027 | "field left is required for Compare"); |
| 2028 | return NULL; |
| 2029 | } |
| 2030 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2031 | if (!p) |
| 2032 | return NULL; |
| 2033 | p->kind = Compare_kind; |
| 2034 | p->v.Compare.left = left; |
| 2035 | p->v.Compare.ops = ops; |
| 2036 | p->v.Compare.comparators = comparators; |
| 2037 | p->lineno = lineno; |
| 2038 | p->col_offset = col_offset; |
| 2039 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2040 | } |
| 2041 | |
| 2042 | expr_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 2043 | Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int lineno, int |
| 2044 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2045 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2046 | expr_ty p; |
| 2047 | if (!func) { |
| 2048 | PyErr_SetString(PyExc_ValueError, |
| 2049 | "field func is required for Call"); |
| 2050 | return NULL; |
| 2051 | } |
| 2052 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2053 | if (!p) |
| 2054 | return NULL; |
| 2055 | p->kind = Call_kind; |
| 2056 | p->v.Call.func = func; |
| 2057 | p->v.Call.args = args; |
| 2058 | p->v.Call.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 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 |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2065 | Num(object n, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2066 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2067 | expr_ty p; |
| 2068 | if (!n) { |
| 2069 | PyErr_SetString(PyExc_ValueError, |
| 2070 | "field n is required for Num"); |
| 2071 | return NULL; |
| 2072 | } |
| 2073 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2074 | if (!p) |
| 2075 | return NULL; |
| 2076 | p->kind = Num_kind; |
| 2077 | p->v.Num.n = n; |
| 2078 | p->lineno = lineno; |
| 2079 | p->col_offset = col_offset; |
| 2080 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2081 | } |
| 2082 | |
| 2083 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2084 | Str(string s, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2085 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2086 | expr_ty p; |
| 2087 | if (!s) { |
| 2088 | PyErr_SetString(PyExc_ValueError, |
| 2089 | "field s is required for Str"); |
| 2090 | return NULL; |
| 2091 | } |
| 2092 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2093 | if (!p) |
| 2094 | return NULL; |
| 2095 | p->kind = Str_kind; |
| 2096 | p->v.Str.s = s; |
| 2097 | p->lineno = lineno; |
| 2098 | p->col_offset = col_offset; |
| 2099 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2100 | } |
| 2101 | |
| 2102 | expr_ty |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2103 | FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno, |
| 2104 | int col_offset, PyArena *arena) |
| 2105 | { |
| 2106 | expr_ty p; |
| 2107 | if (!value) { |
| 2108 | PyErr_SetString(PyExc_ValueError, |
| 2109 | "field value is required for FormattedValue"); |
| 2110 | return NULL; |
| 2111 | } |
| 2112 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2113 | if (!p) |
| 2114 | return NULL; |
| 2115 | p->kind = FormattedValue_kind; |
| 2116 | p->v.FormattedValue.value = value; |
| 2117 | p->v.FormattedValue.conversion = conversion; |
| 2118 | p->v.FormattedValue.format_spec = format_spec; |
| 2119 | p->lineno = lineno; |
| 2120 | p->col_offset = col_offset; |
| 2121 | return p; |
| 2122 | } |
| 2123 | |
| 2124 | expr_ty |
| 2125 | JoinedStr(asdl_seq * values, int lineno, int col_offset, PyArena *arena) |
| 2126 | { |
| 2127 | expr_ty p; |
| 2128 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2129 | if (!p) |
| 2130 | return NULL; |
| 2131 | p->kind = JoinedStr_kind; |
| 2132 | p->v.JoinedStr.values = values; |
| 2133 | p->lineno = lineno; |
| 2134 | p->col_offset = col_offset; |
| 2135 | return p; |
| 2136 | } |
| 2137 | |
| 2138 | expr_ty |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 2139 | Bytes(bytes s, int lineno, int col_offset, PyArena *arena) |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 2140 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2141 | expr_ty p; |
| 2142 | if (!s) { |
| 2143 | PyErr_SetString(PyExc_ValueError, |
| 2144 | "field s is required for Bytes"); |
| 2145 | return NULL; |
| 2146 | } |
| 2147 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2148 | if (!p) |
| 2149 | return NULL; |
| 2150 | p->kind = Bytes_kind; |
| 2151 | p->v.Bytes.s = s; |
| 2152 | p->lineno = lineno; |
| 2153 | p->col_offset = col_offset; |
| 2154 | return p; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 2155 | } |
| 2156 | |
| 2157 | expr_ty |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 2158 | NameConstant(singleton value, int lineno, int col_offset, PyArena *arena) |
| 2159 | { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 2160 | expr_ty p; |
| 2161 | if (!value) { |
| 2162 | PyErr_SetString(PyExc_ValueError, |
| 2163 | "field value is required for NameConstant"); |
| 2164 | return NULL; |
| 2165 | } |
| 2166 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2167 | if (!p) |
| 2168 | return NULL; |
| 2169 | p->kind = NameConstant_kind; |
| 2170 | p->v.NameConstant.value = value; |
| 2171 | p->lineno = lineno; |
| 2172 | p->col_offset = col_offset; |
| 2173 | return p; |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 2174 | } |
| 2175 | |
| 2176 | expr_ty |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 2177 | Ellipsis(int lineno, int col_offset, PyArena *arena) |
| 2178 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2179 | expr_ty p; |
| 2180 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2181 | if (!p) |
| 2182 | return NULL; |
| 2183 | p->kind = Ellipsis_kind; |
| 2184 | p->lineno = lineno; |
| 2185 | p->col_offset = col_offset; |
| 2186 | return p; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 2187 | } |
| 2188 | |
| 2189 | expr_ty |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 2190 | Constant(constant value, int lineno, int col_offset, PyArena *arena) |
| 2191 | { |
| 2192 | expr_ty p; |
| 2193 | if (!value) { |
| 2194 | PyErr_SetString(PyExc_ValueError, |
| 2195 | "field value is required for Constant"); |
| 2196 | return NULL; |
| 2197 | } |
| 2198 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2199 | if (!p) |
| 2200 | return NULL; |
| 2201 | p->kind = Constant_kind; |
| 2202 | p->v.Constant.value = value; |
| 2203 | p->lineno = lineno; |
| 2204 | p->col_offset = col_offset; |
| 2205 | return p; |
| 2206 | } |
| 2207 | |
| 2208 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2209 | Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int |
| 2210 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2211 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2212 | expr_ty p; |
| 2213 | if (!value) { |
| 2214 | PyErr_SetString(PyExc_ValueError, |
| 2215 | "field value is required for Attribute"); |
| 2216 | return NULL; |
| 2217 | } |
| 2218 | if (!attr) { |
| 2219 | PyErr_SetString(PyExc_ValueError, |
| 2220 | "field attr is required for Attribute"); |
| 2221 | return NULL; |
| 2222 | } |
| 2223 | if (!ctx) { |
| 2224 | PyErr_SetString(PyExc_ValueError, |
| 2225 | "field ctx is required for Attribute"); |
| 2226 | return NULL; |
| 2227 | } |
| 2228 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2229 | if (!p) |
| 2230 | return NULL; |
| 2231 | p->kind = Attribute_kind; |
| 2232 | p->v.Attribute.value = value; |
| 2233 | p->v.Attribute.attr = attr; |
| 2234 | p->v.Attribute.ctx = ctx; |
| 2235 | p->lineno = lineno; |
| 2236 | p->col_offset = col_offset; |
| 2237 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2238 | } |
| 2239 | |
| 2240 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2241 | Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int |
| 2242 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2243 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2244 | expr_ty p; |
| 2245 | if (!value) { |
| 2246 | PyErr_SetString(PyExc_ValueError, |
| 2247 | "field value is required for Subscript"); |
| 2248 | return NULL; |
| 2249 | } |
| 2250 | if (!slice) { |
| 2251 | PyErr_SetString(PyExc_ValueError, |
| 2252 | "field slice is required for Subscript"); |
| 2253 | return NULL; |
| 2254 | } |
| 2255 | if (!ctx) { |
| 2256 | PyErr_SetString(PyExc_ValueError, |
| 2257 | "field ctx is required for Subscript"); |
| 2258 | return NULL; |
| 2259 | } |
| 2260 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2261 | if (!p) |
| 2262 | return NULL; |
| 2263 | p->kind = Subscript_kind; |
| 2264 | p->v.Subscript.value = value; |
| 2265 | p->v.Subscript.slice = slice; |
| 2266 | p->v.Subscript.ctx = ctx; |
| 2267 | p->lineno = lineno; |
| 2268 | p->col_offset = col_offset; |
| 2269 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2270 | } |
| 2271 | |
| 2272 | expr_ty |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2273 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 2274 | *arena) |
| 2275 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2276 | expr_ty p; |
| 2277 | if (!value) { |
| 2278 | PyErr_SetString(PyExc_ValueError, |
| 2279 | "field value is required for Starred"); |
| 2280 | return NULL; |
| 2281 | } |
| 2282 | if (!ctx) { |
| 2283 | PyErr_SetString(PyExc_ValueError, |
| 2284 | "field ctx is required for Starred"); |
| 2285 | return NULL; |
| 2286 | } |
| 2287 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2288 | if (!p) |
| 2289 | return NULL; |
| 2290 | p->kind = Starred_kind; |
| 2291 | p->v.Starred.value = value; |
| 2292 | p->v.Starred.ctx = ctx; |
| 2293 | p->lineno = lineno; |
| 2294 | p->col_offset = col_offset; |
| 2295 | return p; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2296 | } |
| 2297 | |
| 2298 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2299 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 2300 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2301 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2302 | expr_ty p; |
| 2303 | if (!id) { |
| 2304 | PyErr_SetString(PyExc_ValueError, |
| 2305 | "field id is required for Name"); |
| 2306 | return NULL; |
| 2307 | } |
| 2308 | if (!ctx) { |
| 2309 | PyErr_SetString(PyExc_ValueError, |
| 2310 | "field ctx is required for Name"); |
| 2311 | return NULL; |
| 2312 | } |
| 2313 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2314 | if (!p) |
| 2315 | return NULL; |
| 2316 | p->kind = Name_kind; |
| 2317 | p->v.Name.id = id; |
| 2318 | p->v.Name.ctx = ctx; |
| 2319 | p->lineno = lineno; |
| 2320 | p->col_offset = col_offset; |
| 2321 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2322 | } |
| 2323 | |
| 2324 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2325 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 2326 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2327 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2328 | expr_ty p; |
| 2329 | if (!ctx) { |
| 2330 | PyErr_SetString(PyExc_ValueError, |
| 2331 | "field ctx is required for List"); |
| 2332 | return NULL; |
| 2333 | } |
| 2334 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2335 | if (!p) |
| 2336 | return NULL; |
| 2337 | p->kind = List_kind; |
| 2338 | p->v.List.elts = elts; |
| 2339 | p->v.List.ctx = ctx; |
| 2340 | p->lineno = lineno; |
| 2341 | p->col_offset = col_offset; |
| 2342 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2343 | } |
| 2344 | |
| 2345 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2346 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 2347 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2348 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2349 | expr_ty p; |
| 2350 | if (!ctx) { |
| 2351 | PyErr_SetString(PyExc_ValueError, |
| 2352 | "field ctx is required for Tuple"); |
| 2353 | return NULL; |
| 2354 | } |
| 2355 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2356 | if (!p) |
| 2357 | return NULL; |
| 2358 | p->kind = Tuple_kind; |
| 2359 | p->v.Tuple.elts = elts; |
| 2360 | p->v.Tuple.ctx = ctx; |
| 2361 | p->lineno = lineno; |
| 2362 | p->col_offset = col_offset; |
| 2363 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2364 | } |
| 2365 | |
| 2366 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2367 | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2368 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2369 | slice_ty p; |
| 2370 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2371 | if (!p) |
| 2372 | return NULL; |
| 2373 | p->kind = Slice_kind; |
| 2374 | p->v.Slice.lower = lower; |
| 2375 | p->v.Slice.upper = upper; |
| 2376 | p->v.Slice.step = step; |
| 2377 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2378 | } |
| 2379 | |
| 2380 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2381 | ExtSlice(asdl_seq * dims, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2382 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2383 | slice_ty p; |
| 2384 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2385 | if (!p) |
| 2386 | return NULL; |
| 2387 | p->kind = ExtSlice_kind; |
| 2388 | p->v.ExtSlice.dims = dims; |
| 2389 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2390 | } |
| 2391 | |
| 2392 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2393 | Index(expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2394 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2395 | slice_ty p; |
| 2396 | if (!value) { |
| 2397 | PyErr_SetString(PyExc_ValueError, |
| 2398 | "field value is required for Index"); |
| 2399 | return NULL; |
| 2400 | } |
| 2401 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2402 | if (!p) |
| 2403 | return NULL; |
| 2404 | p->kind = Index_kind; |
| 2405 | p->v.Index.value = value; |
| 2406 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2407 | } |
| 2408 | |
| 2409 | comprehension_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2410 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2411 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2412 | comprehension_ty p; |
| 2413 | if (!target) { |
| 2414 | PyErr_SetString(PyExc_ValueError, |
| 2415 | "field target is required for comprehension"); |
| 2416 | return NULL; |
| 2417 | } |
| 2418 | if (!iter) { |
| 2419 | PyErr_SetString(PyExc_ValueError, |
| 2420 | "field iter is required for comprehension"); |
| 2421 | return NULL; |
| 2422 | } |
| 2423 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2424 | if (!p) |
| 2425 | return NULL; |
| 2426 | p->target = target; |
| 2427 | p->iter = iter; |
| 2428 | p->ifs = ifs; |
| 2429 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2430 | } |
| 2431 | |
| 2432 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 2433 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2434 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2435 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2436 | excepthandler_ty p; |
| 2437 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2438 | if (!p) |
| 2439 | return NULL; |
| 2440 | p->kind = ExceptHandler_kind; |
| 2441 | p->v.ExceptHandler.type = type; |
| 2442 | p->v.ExceptHandler.name = name; |
| 2443 | p->v.ExceptHandler.body = body; |
| 2444 | p->lineno = lineno; |
| 2445 | p->col_offset = col_offset; |
| 2446 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2447 | } |
| 2448 | |
| 2449 | arguments_ty |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 2450 | arguments(asdl_seq * args, arg_ty vararg, asdl_seq * kwonlyargs, asdl_seq * |
| 2451 | kw_defaults, arg_ty kwarg, asdl_seq * defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2452 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2453 | arguments_ty p; |
| 2454 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2455 | if (!p) |
| 2456 | return NULL; |
| 2457 | p->args = args; |
| 2458 | p->vararg = vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2459 | p->kwonlyargs = kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2460 | p->kw_defaults = kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 2461 | p->kwarg = kwarg; |
| 2462 | p->defaults = defaults; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2463 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2464 | } |
| 2465 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2466 | arg_ty |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 2467 | arg(identifier arg, expr_ty annotation, int lineno, int col_offset, PyArena |
| 2468 | *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2469 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2470 | arg_ty p; |
| 2471 | if (!arg) { |
| 2472 | PyErr_SetString(PyExc_ValueError, |
| 2473 | "field arg is required for arg"); |
| 2474 | return NULL; |
| 2475 | } |
| 2476 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2477 | if (!p) |
| 2478 | return NULL; |
| 2479 | p->arg = arg; |
| 2480 | p->annotation = annotation; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 2481 | p->lineno = lineno; |
| 2482 | p->col_offset = col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2483 | return p; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2484 | } |
| 2485 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2486 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2487 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2488 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2489 | keyword_ty p; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2490 | if (!value) { |
| 2491 | PyErr_SetString(PyExc_ValueError, |
| 2492 | "field value is required for keyword"); |
| 2493 | return NULL; |
| 2494 | } |
| 2495 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2496 | if (!p) |
| 2497 | return NULL; |
| 2498 | p->arg = arg; |
| 2499 | p->value = value; |
| 2500 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2501 | } |
| 2502 | |
| 2503 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2504 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2505 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2506 | alias_ty p; |
| 2507 | if (!name) { |
| 2508 | PyErr_SetString(PyExc_ValueError, |
| 2509 | "field name is required for alias"); |
| 2510 | return NULL; |
| 2511 | } |
| 2512 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2513 | if (!p) |
| 2514 | return NULL; |
| 2515 | p->name = name; |
| 2516 | p->asname = asname; |
| 2517 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2518 | } |
| 2519 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2520 | withitem_ty |
| 2521 | withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) |
| 2522 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2523 | withitem_ty p; |
| 2524 | if (!context_expr) { |
| 2525 | PyErr_SetString(PyExc_ValueError, |
| 2526 | "field context_expr is required for withitem"); |
| 2527 | return NULL; |
| 2528 | } |
| 2529 | p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2530 | if (!p) |
| 2531 | return NULL; |
| 2532 | p->context_expr = context_expr; |
| 2533 | p->optional_vars = optional_vars; |
| 2534 | return p; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2535 | } |
| 2536 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2537 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2538 | PyObject* |
| 2539 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2540 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2541 | mod_ty o = (mod_ty)_o; |
| 2542 | PyObject *result = NULL, *value = NULL; |
| 2543 | if (!o) { |
| 2544 | Py_INCREF(Py_None); |
| 2545 | return Py_None; |
| 2546 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2547 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2548 | switch (o->kind) { |
| 2549 | case Module_kind: |
| 2550 | result = PyType_GenericNew(Module_type, NULL, NULL); |
| 2551 | if (!result) goto failed; |
| 2552 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 2553 | if (!value) goto failed; |
| 2554 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2555 | goto failed; |
| 2556 | Py_DECREF(value); |
| 2557 | break; |
| 2558 | case Interactive_kind: |
| 2559 | result = PyType_GenericNew(Interactive_type, NULL, NULL); |
| 2560 | if (!result) goto failed; |
| 2561 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 2562 | if (!value) goto failed; |
| 2563 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2564 | goto failed; |
| 2565 | Py_DECREF(value); |
| 2566 | break; |
| 2567 | case Expression_kind: |
| 2568 | result = PyType_GenericNew(Expression_type, NULL, NULL); |
| 2569 | if (!result) goto failed; |
| 2570 | value = ast2obj_expr(o->v.Expression.body); |
| 2571 | if (!value) goto failed; |
| 2572 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2573 | goto failed; |
| 2574 | Py_DECREF(value); |
| 2575 | break; |
| 2576 | case Suite_kind: |
| 2577 | result = PyType_GenericNew(Suite_type, NULL, NULL); |
| 2578 | if (!result) goto failed; |
| 2579 | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
| 2580 | if (!value) goto failed; |
| 2581 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2582 | goto failed; |
| 2583 | Py_DECREF(value); |
| 2584 | break; |
| 2585 | } |
| 2586 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2587 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2588 | Py_XDECREF(value); |
| 2589 | Py_XDECREF(result); |
| 2590 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2591 | } |
| 2592 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2593 | PyObject* |
| 2594 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2595 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2596 | stmt_ty o = (stmt_ty)_o; |
| 2597 | PyObject *result = NULL, *value = NULL; |
| 2598 | if (!o) { |
| 2599 | Py_INCREF(Py_None); |
| 2600 | return Py_None; |
| 2601 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2602 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2603 | switch (o->kind) { |
| 2604 | case FunctionDef_kind: |
| 2605 | result = PyType_GenericNew(FunctionDef_type, NULL, NULL); |
| 2606 | if (!result) goto failed; |
| 2607 | value = ast2obj_identifier(o->v.FunctionDef.name); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2608 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2609 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2610 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2611 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2612 | value = ast2obj_arguments(o->v.FunctionDef.args); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2613 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2614 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 2615 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2616 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2617 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 2618 | if (!value) goto failed; |
| 2619 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2620 | goto failed; |
| 2621 | Py_DECREF(value); |
| 2622 | value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr); |
| 2623 | if (!value) goto failed; |
| 2624 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2625 | goto failed; |
| 2626 | Py_DECREF(value); |
| 2627 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 2628 | if (!value) goto failed; |
| 2629 | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
| 2630 | goto failed; |
| 2631 | Py_DECREF(value); |
| 2632 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2633 | case AsyncFunctionDef_kind: |
| 2634 | result = PyType_GenericNew(AsyncFunctionDef_type, NULL, NULL); |
| 2635 | if (!result) goto failed; |
| 2636 | value = ast2obj_identifier(o->v.AsyncFunctionDef.name); |
| 2637 | if (!value) goto failed; |
| 2638 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2639 | goto failed; |
| 2640 | Py_DECREF(value); |
| 2641 | value = ast2obj_arguments(o->v.AsyncFunctionDef.args); |
| 2642 | if (!value) goto failed; |
| 2643 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 2644 | goto failed; |
| 2645 | Py_DECREF(value); |
| 2646 | value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt); |
| 2647 | if (!value) goto failed; |
| 2648 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2649 | goto failed; |
| 2650 | Py_DECREF(value); |
| 2651 | value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list, |
| 2652 | ast2obj_expr); |
| 2653 | if (!value) goto failed; |
| 2654 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2655 | goto failed; |
| 2656 | Py_DECREF(value); |
| 2657 | value = ast2obj_expr(o->v.AsyncFunctionDef.returns); |
| 2658 | if (!value) goto failed; |
| 2659 | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
| 2660 | goto failed; |
| 2661 | Py_DECREF(value); |
| 2662 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2663 | case ClassDef_kind: |
| 2664 | result = PyType_GenericNew(ClassDef_type, NULL, NULL); |
| 2665 | if (!result) goto failed; |
| 2666 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 2667 | if (!value) goto failed; |
| 2668 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2669 | goto failed; |
| 2670 | Py_DECREF(value); |
| 2671 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 2672 | if (!value) goto failed; |
| 2673 | if (_PyObject_SetAttrId(result, &PyId_bases, value) == -1) |
| 2674 | goto failed; |
| 2675 | Py_DECREF(value); |
| 2676 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 2677 | if (!value) goto failed; |
| 2678 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
| 2679 | goto failed; |
| 2680 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2681 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 2682 | if (!value) goto failed; |
| 2683 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2684 | goto failed; |
| 2685 | Py_DECREF(value); |
| 2686 | value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr); |
| 2687 | if (!value) goto failed; |
| 2688 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2689 | goto failed; |
| 2690 | Py_DECREF(value); |
| 2691 | break; |
| 2692 | case Return_kind: |
| 2693 | result = PyType_GenericNew(Return_type, NULL, NULL); |
| 2694 | if (!result) goto failed; |
| 2695 | value = ast2obj_expr(o->v.Return.value); |
| 2696 | if (!value) goto failed; |
| 2697 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2698 | goto failed; |
| 2699 | Py_DECREF(value); |
| 2700 | break; |
| 2701 | case Delete_kind: |
| 2702 | result = PyType_GenericNew(Delete_type, NULL, NULL); |
| 2703 | if (!result) goto failed; |
| 2704 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 2705 | if (!value) goto failed; |
| 2706 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
| 2707 | goto failed; |
| 2708 | Py_DECREF(value); |
| 2709 | break; |
| 2710 | case Assign_kind: |
| 2711 | result = PyType_GenericNew(Assign_type, NULL, NULL); |
| 2712 | if (!result) goto failed; |
| 2713 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 2714 | if (!value) goto failed; |
| 2715 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
| 2716 | goto failed; |
| 2717 | Py_DECREF(value); |
| 2718 | value = ast2obj_expr(o->v.Assign.value); |
| 2719 | if (!value) goto failed; |
| 2720 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2721 | goto failed; |
| 2722 | Py_DECREF(value); |
| 2723 | break; |
| 2724 | case AugAssign_kind: |
| 2725 | result = PyType_GenericNew(AugAssign_type, NULL, NULL); |
| 2726 | if (!result) goto failed; |
| 2727 | value = ast2obj_expr(o->v.AugAssign.target); |
| 2728 | if (!value) goto failed; |
| 2729 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2730 | goto failed; |
| 2731 | Py_DECREF(value); |
| 2732 | value = ast2obj_operator(o->v.AugAssign.op); |
| 2733 | if (!value) goto failed; |
| 2734 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 2735 | goto failed; |
| 2736 | Py_DECREF(value); |
| 2737 | value = ast2obj_expr(o->v.AugAssign.value); |
| 2738 | if (!value) goto failed; |
| 2739 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2740 | goto failed; |
| 2741 | Py_DECREF(value); |
| 2742 | break; |
| 2743 | case For_kind: |
| 2744 | result = PyType_GenericNew(For_type, NULL, NULL); |
| 2745 | if (!result) goto failed; |
| 2746 | value = ast2obj_expr(o->v.For.target); |
| 2747 | if (!value) goto failed; |
| 2748 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2749 | goto failed; |
| 2750 | Py_DECREF(value); |
| 2751 | value = ast2obj_expr(o->v.For.iter); |
| 2752 | if (!value) goto failed; |
| 2753 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 2754 | goto failed; |
| 2755 | Py_DECREF(value); |
| 2756 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 2757 | if (!value) goto failed; |
| 2758 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2759 | goto failed; |
| 2760 | Py_DECREF(value); |
| 2761 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 2762 | if (!value) goto failed; |
| 2763 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2764 | goto failed; |
| 2765 | Py_DECREF(value); |
| 2766 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2767 | case AsyncFor_kind: |
| 2768 | result = PyType_GenericNew(AsyncFor_type, NULL, NULL); |
| 2769 | if (!result) goto failed; |
| 2770 | value = ast2obj_expr(o->v.AsyncFor.target); |
| 2771 | if (!value) goto failed; |
| 2772 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2773 | goto failed; |
| 2774 | Py_DECREF(value); |
| 2775 | value = ast2obj_expr(o->v.AsyncFor.iter); |
| 2776 | if (!value) goto failed; |
| 2777 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 2778 | goto failed; |
| 2779 | Py_DECREF(value); |
| 2780 | value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt); |
| 2781 | if (!value) goto failed; |
| 2782 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2783 | goto failed; |
| 2784 | Py_DECREF(value); |
| 2785 | value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt); |
| 2786 | if (!value) goto failed; |
| 2787 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2788 | goto failed; |
| 2789 | Py_DECREF(value); |
| 2790 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2791 | case While_kind: |
| 2792 | result = PyType_GenericNew(While_type, NULL, NULL); |
| 2793 | if (!result) goto failed; |
| 2794 | value = ast2obj_expr(o->v.While.test); |
| 2795 | if (!value) goto failed; |
| 2796 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 2797 | goto failed; |
| 2798 | Py_DECREF(value); |
| 2799 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 2800 | if (!value) goto failed; |
| 2801 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2802 | goto failed; |
| 2803 | Py_DECREF(value); |
| 2804 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 2805 | if (!value) goto failed; |
| 2806 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2807 | goto failed; |
| 2808 | Py_DECREF(value); |
| 2809 | break; |
| 2810 | case If_kind: |
| 2811 | result = PyType_GenericNew(If_type, NULL, NULL); |
| 2812 | if (!result) goto failed; |
| 2813 | value = ast2obj_expr(o->v.If.test); |
| 2814 | if (!value) goto failed; |
| 2815 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 2816 | goto failed; |
| 2817 | Py_DECREF(value); |
| 2818 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 2819 | if (!value) goto failed; |
| 2820 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2821 | goto failed; |
| 2822 | Py_DECREF(value); |
| 2823 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 2824 | if (!value) goto failed; |
| 2825 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2826 | goto failed; |
| 2827 | Py_DECREF(value); |
| 2828 | break; |
| 2829 | case With_kind: |
| 2830 | result = PyType_GenericNew(With_type, NULL, NULL); |
| 2831 | if (!result) goto failed; |
| 2832 | value = ast2obj_list(o->v.With.items, ast2obj_withitem); |
| 2833 | if (!value) goto failed; |
| 2834 | if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) |
| 2835 | goto failed; |
| 2836 | Py_DECREF(value); |
| 2837 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 2838 | if (!value) goto failed; |
| 2839 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2840 | goto failed; |
| 2841 | Py_DECREF(value); |
| 2842 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2843 | case AsyncWith_kind: |
| 2844 | result = PyType_GenericNew(AsyncWith_type, NULL, NULL); |
| 2845 | if (!result) goto failed; |
| 2846 | value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem); |
| 2847 | if (!value) goto failed; |
| 2848 | if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) |
| 2849 | goto failed; |
| 2850 | Py_DECREF(value); |
| 2851 | value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt); |
| 2852 | if (!value) goto failed; |
| 2853 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2854 | goto failed; |
| 2855 | Py_DECREF(value); |
| 2856 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2857 | case Raise_kind: |
| 2858 | result = PyType_GenericNew(Raise_type, NULL, NULL); |
| 2859 | if (!result) goto failed; |
| 2860 | value = ast2obj_expr(o->v.Raise.exc); |
| 2861 | if (!value) goto failed; |
| 2862 | if (_PyObject_SetAttrId(result, &PyId_exc, value) == -1) |
| 2863 | goto failed; |
| 2864 | Py_DECREF(value); |
| 2865 | value = ast2obj_expr(o->v.Raise.cause); |
| 2866 | if (!value) goto failed; |
| 2867 | if (_PyObject_SetAttrId(result, &PyId_cause, value) == -1) |
| 2868 | goto failed; |
| 2869 | Py_DECREF(value); |
| 2870 | break; |
| 2871 | case Try_kind: |
| 2872 | result = PyType_GenericNew(Try_type, NULL, NULL); |
| 2873 | if (!result) goto failed; |
| 2874 | value = ast2obj_list(o->v.Try.body, ast2obj_stmt); |
| 2875 | if (!value) goto failed; |
| 2876 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2877 | goto failed; |
| 2878 | Py_DECREF(value); |
| 2879 | value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); |
| 2880 | if (!value) goto failed; |
| 2881 | if (_PyObject_SetAttrId(result, &PyId_handlers, value) == -1) |
| 2882 | goto failed; |
| 2883 | Py_DECREF(value); |
| 2884 | value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); |
| 2885 | if (!value) goto failed; |
| 2886 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2887 | goto failed; |
| 2888 | Py_DECREF(value); |
| 2889 | value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); |
| 2890 | if (!value) goto failed; |
| 2891 | if (_PyObject_SetAttrId(result, &PyId_finalbody, value) == -1) |
| 2892 | goto failed; |
| 2893 | Py_DECREF(value); |
| 2894 | break; |
| 2895 | case Assert_kind: |
| 2896 | result = PyType_GenericNew(Assert_type, NULL, NULL); |
| 2897 | if (!result) goto failed; |
| 2898 | value = ast2obj_expr(o->v.Assert.test); |
| 2899 | if (!value) goto failed; |
| 2900 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 2901 | goto failed; |
| 2902 | Py_DECREF(value); |
| 2903 | value = ast2obj_expr(o->v.Assert.msg); |
| 2904 | if (!value) goto failed; |
| 2905 | if (_PyObject_SetAttrId(result, &PyId_msg, value) == -1) |
| 2906 | goto failed; |
| 2907 | Py_DECREF(value); |
| 2908 | break; |
| 2909 | case Import_kind: |
| 2910 | result = PyType_GenericNew(Import_type, NULL, NULL); |
| 2911 | if (!result) goto failed; |
| 2912 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 2913 | if (!value) goto failed; |
| 2914 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 2915 | goto failed; |
| 2916 | Py_DECREF(value); |
| 2917 | break; |
| 2918 | case ImportFrom_kind: |
| 2919 | result = PyType_GenericNew(ImportFrom_type, NULL, NULL); |
| 2920 | if (!result) goto failed; |
| 2921 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 2922 | if (!value) goto failed; |
| 2923 | if (_PyObject_SetAttrId(result, &PyId_module, value) == -1) |
| 2924 | goto failed; |
| 2925 | Py_DECREF(value); |
| 2926 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 2927 | if (!value) goto failed; |
| 2928 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 2929 | goto failed; |
| 2930 | Py_DECREF(value); |
| 2931 | value = ast2obj_int(o->v.ImportFrom.level); |
| 2932 | if (!value) goto failed; |
| 2933 | if (_PyObject_SetAttrId(result, &PyId_level, value) == -1) |
| 2934 | goto failed; |
| 2935 | Py_DECREF(value); |
| 2936 | break; |
| 2937 | case Global_kind: |
| 2938 | result = PyType_GenericNew(Global_type, NULL, NULL); |
| 2939 | if (!result) goto failed; |
| 2940 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 2941 | if (!value) goto failed; |
| 2942 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 2943 | goto failed; |
| 2944 | Py_DECREF(value); |
| 2945 | break; |
| 2946 | case Nonlocal_kind: |
| 2947 | result = PyType_GenericNew(Nonlocal_type, NULL, NULL); |
| 2948 | if (!result) goto failed; |
| 2949 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 2950 | if (!value) goto failed; |
| 2951 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 2952 | goto failed; |
| 2953 | Py_DECREF(value); |
| 2954 | break; |
| 2955 | case Expr_kind: |
| 2956 | result = PyType_GenericNew(Expr_type, NULL, NULL); |
| 2957 | if (!result) goto failed; |
| 2958 | value = ast2obj_expr(o->v.Expr.value); |
| 2959 | if (!value) goto failed; |
| 2960 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2961 | goto failed; |
| 2962 | Py_DECREF(value); |
| 2963 | break; |
| 2964 | case Pass_kind: |
| 2965 | result = PyType_GenericNew(Pass_type, NULL, NULL); |
| 2966 | if (!result) goto failed; |
| 2967 | break; |
| 2968 | case Break_kind: |
| 2969 | result = PyType_GenericNew(Break_type, NULL, NULL); |
| 2970 | if (!result) goto failed; |
| 2971 | break; |
| 2972 | case Continue_kind: |
| 2973 | result = PyType_GenericNew(Continue_type, NULL, NULL); |
| 2974 | if (!result) goto failed; |
| 2975 | break; |
| 2976 | } |
| 2977 | value = ast2obj_int(o->lineno); |
| 2978 | if (!value) goto failed; |
| 2979 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 2980 | goto failed; |
| 2981 | Py_DECREF(value); |
| 2982 | value = ast2obj_int(o->col_offset); |
| 2983 | if (!value) goto failed; |
| 2984 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 2985 | goto failed; |
| 2986 | Py_DECREF(value); |
| 2987 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2988 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2989 | Py_XDECREF(value); |
| 2990 | Py_XDECREF(result); |
| 2991 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2992 | } |
| 2993 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2994 | PyObject* |
| 2995 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2996 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2997 | expr_ty o = (expr_ty)_o; |
| 2998 | PyObject *result = NULL, *value = NULL; |
| 2999 | if (!o) { |
| 3000 | Py_INCREF(Py_None); |
| 3001 | return Py_None; |
| 3002 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3003 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3004 | switch (o->kind) { |
| 3005 | case BoolOp_kind: |
| 3006 | result = PyType_GenericNew(BoolOp_type, NULL, NULL); |
| 3007 | if (!result) goto failed; |
| 3008 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 3009 | if (!value) goto failed; |
| 3010 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 3011 | goto failed; |
| 3012 | Py_DECREF(value); |
| 3013 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 3014 | if (!value) goto failed; |
| 3015 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 3016 | goto failed; |
| 3017 | Py_DECREF(value); |
| 3018 | break; |
| 3019 | case BinOp_kind: |
| 3020 | result = PyType_GenericNew(BinOp_type, NULL, NULL); |
| 3021 | if (!result) goto failed; |
| 3022 | value = ast2obj_expr(o->v.BinOp.left); |
| 3023 | if (!value) goto failed; |
| 3024 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
| 3025 | goto failed; |
| 3026 | Py_DECREF(value); |
| 3027 | value = ast2obj_operator(o->v.BinOp.op); |
| 3028 | if (!value) goto failed; |
| 3029 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 3030 | goto failed; |
| 3031 | Py_DECREF(value); |
| 3032 | value = ast2obj_expr(o->v.BinOp.right); |
| 3033 | if (!value) goto failed; |
| 3034 | if (_PyObject_SetAttrId(result, &PyId_right, value) == -1) |
| 3035 | goto failed; |
| 3036 | Py_DECREF(value); |
| 3037 | break; |
| 3038 | case UnaryOp_kind: |
| 3039 | result = PyType_GenericNew(UnaryOp_type, NULL, NULL); |
| 3040 | if (!result) goto failed; |
| 3041 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 3042 | if (!value) goto failed; |
| 3043 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 3044 | goto failed; |
| 3045 | Py_DECREF(value); |
| 3046 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 3047 | if (!value) goto failed; |
| 3048 | if (_PyObject_SetAttrId(result, &PyId_operand, value) == -1) |
| 3049 | goto failed; |
| 3050 | Py_DECREF(value); |
| 3051 | break; |
| 3052 | case Lambda_kind: |
| 3053 | result = PyType_GenericNew(Lambda_type, NULL, NULL); |
| 3054 | if (!result) goto failed; |
| 3055 | value = ast2obj_arguments(o->v.Lambda.args); |
| 3056 | if (!value) goto failed; |
| 3057 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3058 | goto failed; |
| 3059 | Py_DECREF(value); |
| 3060 | value = ast2obj_expr(o->v.Lambda.body); |
| 3061 | if (!value) goto failed; |
| 3062 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3063 | goto failed; |
| 3064 | Py_DECREF(value); |
| 3065 | break; |
| 3066 | case IfExp_kind: |
| 3067 | result = PyType_GenericNew(IfExp_type, NULL, NULL); |
| 3068 | if (!result) goto failed; |
| 3069 | value = ast2obj_expr(o->v.IfExp.test); |
| 3070 | if (!value) goto failed; |
| 3071 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 3072 | goto failed; |
| 3073 | Py_DECREF(value); |
| 3074 | value = ast2obj_expr(o->v.IfExp.body); |
| 3075 | if (!value) goto failed; |
| 3076 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3077 | goto failed; |
| 3078 | Py_DECREF(value); |
| 3079 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 3080 | if (!value) goto failed; |
| 3081 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 3082 | goto failed; |
| 3083 | Py_DECREF(value); |
| 3084 | break; |
| 3085 | case Dict_kind: |
| 3086 | result = PyType_GenericNew(Dict_type, NULL, NULL); |
| 3087 | if (!result) goto failed; |
| 3088 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 3089 | if (!value) goto failed; |
| 3090 | if (_PyObject_SetAttrId(result, &PyId_keys, value) == -1) |
| 3091 | goto failed; |
| 3092 | Py_DECREF(value); |
| 3093 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 3094 | if (!value) goto failed; |
| 3095 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 3096 | goto failed; |
| 3097 | Py_DECREF(value); |
| 3098 | break; |
| 3099 | case Set_kind: |
| 3100 | result = PyType_GenericNew(Set_type, NULL, NULL); |
| 3101 | if (!result) goto failed; |
| 3102 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 3103 | if (!value) goto failed; |
| 3104 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3105 | goto failed; |
| 3106 | Py_DECREF(value); |
| 3107 | break; |
| 3108 | case ListComp_kind: |
| 3109 | result = PyType_GenericNew(ListComp_type, NULL, NULL); |
| 3110 | if (!result) goto failed; |
| 3111 | value = ast2obj_expr(o->v.ListComp.elt); |
| 3112 | if (!value) goto failed; |
| 3113 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 3114 | goto failed; |
| 3115 | Py_DECREF(value); |
| 3116 | value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension); |
| 3117 | if (!value) goto failed; |
| 3118 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3119 | goto failed; |
| 3120 | Py_DECREF(value); |
| 3121 | break; |
| 3122 | case SetComp_kind: |
| 3123 | result = PyType_GenericNew(SetComp_type, NULL, NULL); |
| 3124 | if (!result) goto failed; |
| 3125 | value = ast2obj_expr(o->v.SetComp.elt); |
| 3126 | if (!value) goto failed; |
| 3127 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 3128 | goto failed; |
| 3129 | Py_DECREF(value); |
| 3130 | value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension); |
| 3131 | if (!value) goto failed; |
| 3132 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3133 | goto failed; |
| 3134 | Py_DECREF(value); |
| 3135 | break; |
| 3136 | case DictComp_kind: |
| 3137 | result = PyType_GenericNew(DictComp_type, NULL, NULL); |
| 3138 | if (!result) goto failed; |
| 3139 | value = ast2obj_expr(o->v.DictComp.key); |
| 3140 | if (!value) goto failed; |
| 3141 | if (_PyObject_SetAttrId(result, &PyId_key, value) == -1) |
| 3142 | goto failed; |
| 3143 | Py_DECREF(value); |
| 3144 | value = ast2obj_expr(o->v.DictComp.value); |
| 3145 | if (!value) goto failed; |
| 3146 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3147 | goto failed; |
| 3148 | Py_DECREF(value); |
| 3149 | value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension); |
| 3150 | if (!value) goto failed; |
| 3151 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3152 | goto failed; |
| 3153 | Py_DECREF(value); |
| 3154 | break; |
| 3155 | case GeneratorExp_kind: |
| 3156 | result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); |
| 3157 | if (!result) goto failed; |
| 3158 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 3159 | if (!value) goto failed; |
| 3160 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 3161 | goto failed; |
| 3162 | Py_DECREF(value); |
| 3163 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 3164 | ast2obj_comprehension); |
| 3165 | if (!value) goto failed; |
| 3166 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3167 | goto failed; |
| 3168 | Py_DECREF(value); |
| 3169 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3170 | case Await_kind: |
| 3171 | result = PyType_GenericNew(Await_type, NULL, NULL); |
| 3172 | if (!result) goto failed; |
| 3173 | value = ast2obj_expr(o->v.Await.value); |
| 3174 | if (!value) goto failed; |
| 3175 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3176 | goto failed; |
| 3177 | Py_DECREF(value); |
| 3178 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3179 | case Yield_kind: |
| 3180 | result = PyType_GenericNew(Yield_type, NULL, NULL); |
| 3181 | if (!result) goto failed; |
| 3182 | value = ast2obj_expr(o->v.Yield.value); |
| 3183 | if (!value) goto failed; |
| 3184 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3185 | goto failed; |
| 3186 | Py_DECREF(value); |
| 3187 | break; |
| 3188 | case YieldFrom_kind: |
| 3189 | result = PyType_GenericNew(YieldFrom_type, NULL, NULL); |
| 3190 | if (!result) goto failed; |
| 3191 | value = ast2obj_expr(o->v.YieldFrom.value); |
| 3192 | if (!value) goto failed; |
| 3193 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3194 | goto failed; |
| 3195 | Py_DECREF(value); |
| 3196 | break; |
| 3197 | case Compare_kind: |
| 3198 | result = PyType_GenericNew(Compare_type, NULL, NULL); |
| 3199 | if (!result) goto failed; |
| 3200 | value = ast2obj_expr(o->v.Compare.left); |
| 3201 | if (!value) goto failed; |
| 3202 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
| 3203 | goto failed; |
| 3204 | Py_DECREF(value); |
| 3205 | { |
| 3206 | Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 3207 | value = PyList_New(n); |
| 3208 | if (!value) goto failed; |
| 3209 | for(i = 0; i < n; i++) |
| 3210 | 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] | 3211 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 3212 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3213 | if (_PyObject_SetAttrId(result, &PyId_ops, value) == -1) |
| 3214 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3215 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3216 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3217 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3218 | if (_PyObject_SetAttrId(result, &PyId_comparators, value) == -1) |
| 3219 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3220 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3221 | break; |
| 3222 | case Call_kind: |
| 3223 | result = PyType_GenericNew(Call_type, NULL, NULL); |
| 3224 | if (!result) goto failed; |
| 3225 | value = ast2obj_expr(o->v.Call.func); |
| 3226 | if (!value) goto failed; |
| 3227 | if (_PyObject_SetAttrId(result, &PyId_func, value) == -1) |
| 3228 | goto failed; |
| 3229 | Py_DECREF(value); |
| 3230 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 3231 | if (!value) goto failed; |
| 3232 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3233 | goto failed; |
| 3234 | Py_DECREF(value); |
| 3235 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 3236 | if (!value) goto failed; |
| 3237 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
| 3238 | goto failed; |
| 3239 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3240 | break; |
| 3241 | case Num_kind: |
| 3242 | result = PyType_GenericNew(Num_type, NULL, NULL); |
| 3243 | if (!result) goto failed; |
| 3244 | value = ast2obj_object(o->v.Num.n); |
| 3245 | if (!value) goto failed; |
| 3246 | if (_PyObject_SetAttrId(result, &PyId_n, value) == -1) |
| 3247 | goto failed; |
| 3248 | Py_DECREF(value); |
| 3249 | break; |
| 3250 | case Str_kind: |
| 3251 | result = PyType_GenericNew(Str_type, NULL, NULL); |
| 3252 | if (!result) goto failed; |
| 3253 | value = ast2obj_string(o->v.Str.s); |
| 3254 | if (!value) goto failed; |
| 3255 | if (_PyObject_SetAttrId(result, &PyId_s, value) == -1) |
| 3256 | goto failed; |
| 3257 | Py_DECREF(value); |
| 3258 | break; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3259 | case FormattedValue_kind: |
| 3260 | result = PyType_GenericNew(FormattedValue_type, NULL, NULL); |
| 3261 | if (!result) goto failed; |
| 3262 | value = ast2obj_expr(o->v.FormattedValue.value); |
| 3263 | if (!value) goto failed; |
| 3264 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3265 | goto failed; |
| 3266 | Py_DECREF(value); |
| 3267 | value = ast2obj_int(o->v.FormattedValue.conversion); |
| 3268 | if (!value) goto failed; |
| 3269 | if (_PyObject_SetAttrId(result, &PyId_conversion, value) == -1) |
| 3270 | goto failed; |
| 3271 | Py_DECREF(value); |
| 3272 | value = ast2obj_expr(o->v.FormattedValue.format_spec); |
| 3273 | if (!value) goto failed; |
| 3274 | if (_PyObject_SetAttrId(result, &PyId_format_spec, value) == -1) |
| 3275 | goto failed; |
| 3276 | Py_DECREF(value); |
| 3277 | break; |
| 3278 | case JoinedStr_kind: |
| 3279 | result = PyType_GenericNew(JoinedStr_type, NULL, NULL); |
| 3280 | if (!result) goto failed; |
| 3281 | value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr); |
| 3282 | if (!value) goto failed; |
| 3283 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 3284 | goto failed; |
| 3285 | Py_DECREF(value); |
| 3286 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3287 | case Bytes_kind: |
| 3288 | result = PyType_GenericNew(Bytes_type, NULL, NULL); |
| 3289 | if (!result) goto failed; |
| 3290 | value = ast2obj_bytes(o->v.Bytes.s); |
| 3291 | if (!value) goto failed; |
| 3292 | if (_PyObject_SetAttrId(result, &PyId_s, value) == -1) |
| 3293 | goto failed; |
| 3294 | Py_DECREF(value); |
| 3295 | break; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3296 | case NameConstant_kind: |
| 3297 | result = PyType_GenericNew(NameConstant_type, NULL, NULL); |
| 3298 | if (!result) goto failed; |
| 3299 | value = ast2obj_singleton(o->v.NameConstant.value); |
| 3300 | if (!value) goto failed; |
| 3301 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3302 | goto failed; |
| 3303 | Py_DECREF(value); |
| 3304 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3305 | case Ellipsis_kind: |
| 3306 | result = PyType_GenericNew(Ellipsis_type, NULL, NULL); |
| 3307 | if (!result) goto failed; |
| 3308 | break; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3309 | case Constant_kind: |
| 3310 | result = PyType_GenericNew(Constant_type, NULL, NULL); |
| 3311 | if (!result) goto failed; |
| 3312 | value = ast2obj_constant(o->v.Constant.value); |
| 3313 | if (!value) goto failed; |
| 3314 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3315 | goto failed; |
| 3316 | Py_DECREF(value); |
| 3317 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3318 | case Attribute_kind: |
| 3319 | result = PyType_GenericNew(Attribute_type, NULL, NULL); |
| 3320 | if (!result) goto failed; |
| 3321 | value = ast2obj_expr(o->v.Attribute.value); |
| 3322 | if (!value) goto failed; |
| 3323 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3324 | goto failed; |
| 3325 | Py_DECREF(value); |
| 3326 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 3327 | if (!value) goto failed; |
| 3328 | if (_PyObject_SetAttrId(result, &PyId_attr, value) == -1) |
| 3329 | goto failed; |
| 3330 | Py_DECREF(value); |
| 3331 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 3332 | if (!value) goto failed; |
| 3333 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3334 | goto failed; |
| 3335 | Py_DECREF(value); |
| 3336 | break; |
| 3337 | case Subscript_kind: |
| 3338 | result = PyType_GenericNew(Subscript_type, NULL, NULL); |
| 3339 | if (!result) goto failed; |
| 3340 | value = ast2obj_expr(o->v.Subscript.value); |
| 3341 | if (!value) goto failed; |
| 3342 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3343 | goto failed; |
| 3344 | Py_DECREF(value); |
| 3345 | value = ast2obj_slice(o->v.Subscript.slice); |
| 3346 | if (!value) goto failed; |
| 3347 | if (_PyObject_SetAttrId(result, &PyId_slice, value) == -1) |
| 3348 | goto failed; |
| 3349 | Py_DECREF(value); |
| 3350 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 3351 | if (!value) goto failed; |
| 3352 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3353 | goto failed; |
| 3354 | Py_DECREF(value); |
| 3355 | break; |
| 3356 | case Starred_kind: |
| 3357 | result = PyType_GenericNew(Starred_type, NULL, NULL); |
| 3358 | if (!result) goto failed; |
| 3359 | value = ast2obj_expr(o->v.Starred.value); |
| 3360 | if (!value) goto failed; |
| 3361 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3362 | goto failed; |
| 3363 | Py_DECREF(value); |
| 3364 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 3365 | if (!value) goto failed; |
| 3366 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3367 | goto failed; |
| 3368 | Py_DECREF(value); |
| 3369 | break; |
| 3370 | case Name_kind: |
| 3371 | result = PyType_GenericNew(Name_type, NULL, NULL); |
| 3372 | if (!result) goto failed; |
| 3373 | value = ast2obj_identifier(o->v.Name.id); |
| 3374 | if (!value) goto failed; |
| 3375 | if (_PyObject_SetAttrId(result, &PyId_id, value) == -1) |
| 3376 | goto failed; |
| 3377 | Py_DECREF(value); |
| 3378 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 3379 | if (!value) goto failed; |
| 3380 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3381 | goto failed; |
| 3382 | Py_DECREF(value); |
| 3383 | break; |
| 3384 | case List_kind: |
| 3385 | result = PyType_GenericNew(List_type, NULL, NULL); |
| 3386 | if (!result) goto failed; |
| 3387 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 3388 | if (!value) goto failed; |
| 3389 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3390 | goto failed; |
| 3391 | Py_DECREF(value); |
| 3392 | value = ast2obj_expr_context(o->v.List.ctx); |
| 3393 | if (!value) goto failed; |
| 3394 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3395 | goto failed; |
| 3396 | Py_DECREF(value); |
| 3397 | break; |
| 3398 | case Tuple_kind: |
| 3399 | result = PyType_GenericNew(Tuple_type, NULL, NULL); |
| 3400 | if (!result) goto failed; |
| 3401 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 3402 | if (!value) goto failed; |
| 3403 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3404 | goto failed; |
| 3405 | Py_DECREF(value); |
| 3406 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 3407 | if (!value) goto failed; |
| 3408 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3409 | goto failed; |
| 3410 | Py_DECREF(value); |
| 3411 | break; |
| 3412 | } |
| 3413 | value = ast2obj_int(o->lineno); |
| 3414 | if (!value) goto failed; |
| 3415 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3416 | goto failed; |
| 3417 | Py_DECREF(value); |
| 3418 | value = ast2obj_int(o->col_offset); |
| 3419 | if (!value) goto failed; |
| 3420 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3421 | goto failed; |
| 3422 | Py_DECREF(value); |
| 3423 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3424 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3425 | Py_XDECREF(value); |
| 3426 | Py_XDECREF(result); |
| 3427 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3428 | } |
| 3429 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3430 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3431 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3432 | switch(o) { |
| 3433 | case Load: |
| 3434 | Py_INCREF(Load_singleton); |
| 3435 | return Load_singleton; |
| 3436 | case Store: |
| 3437 | Py_INCREF(Store_singleton); |
| 3438 | return Store_singleton; |
| 3439 | case Del: |
| 3440 | Py_INCREF(Del_singleton); |
| 3441 | return Del_singleton; |
| 3442 | case AugLoad: |
| 3443 | Py_INCREF(AugLoad_singleton); |
| 3444 | return AugLoad_singleton; |
| 3445 | case AugStore: |
| 3446 | Py_INCREF(AugStore_singleton); |
| 3447 | return AugStore_singleton; |
| 3448 | case Param: |
| 3449 | Py_INCREF(Param_singleton); |
| 3450 | return Param_singleton; |
| 3451 | default: |
| 3452 | /* should never happen, but just in case ... */ |
| 3453 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 3454 | return NULL; |
| 3455 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3456 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3457 | PyObject* |
| 3458 | ast2obj_slice(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3459 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3460 | slice_ty o = (slice_ty)_o; |
| 3461 | PyObject *result = NULL, *value = NULL; |
| 3462 | if (!o) { |
| 3463 | Py_INCREF(Py_None); |
| 3464 | return Py_None; |
| 3465 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3466 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3467 | switch (o->kind) { |
| 3468 | case Slice_kind: |
| 3469 | result = PyType_GenericNew(Slice_type, NULL, NULL); |
| 3470 | if (!result) goto failed; |
| 3471 | value = ast2obj_expr(o->v.Slice.lower); |
| 3472 | if (!value) goto failed; |
| 3473 | if (_PyObject_SetAttrId(result, &PyId_lower, value) == -1) |
| 3474 | goto failed; |
| 3475 | Py_DECREF(value); |
| 3476 | value = ast2obj_expr(o->v.Slice.upper); |
| 3477 | if (!value) goto failed; |
| 3478 | if (_PyObject_SetAttrId(result, &PyId_upper, value) == -1) |
| 3479 | goto failed; |
| 3480 | Py_DECREF(value); |
| 3481 | value = ast2obj_expr(o->v.Slice.step); |
| 3482 | if (!value) goto failed; |
| 3483 | if (_PyObject_SetAttrId(result, &PyId_step, value) == -1) |
| 3484 | goto failed; |
| 3485 | Py_DECREF(value); |
| 3486 | break; |
| 3487 | case ExtSlice_kind: |
| 3488 | result = PyType_GenericNew(ExtSlice_type, NULL, NULL); |
| 3489 | if (!result) goto failed; |
| 3490 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 3491 | if (!value) goto failed; |
| 3492 | if (_PyObject_SetAttrId(result, &PyId_dims, value) == -1) |
| 3493 | goto failed; |
| 3494 | Py_DECREF(value); |
| 3495 | break; |
| 3496 | case Index_kind: |
| 3497 | result = PyType_GenericNew(Index_type, NULL, NULL); |
| 3498 | if (!result) goto failed; |
| 3499 | value = ast2obj_expr(o->v.Index.value); |
| 3500 | if (!value) goto failed; |
| 3501 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3502 | goto failed; |
| 3503 | Py_DECREF(value); |
| 3504 | break; |
| 3505 | } |
| 3506 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3507 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3508 | Py_XDECREF(value); |
| 3509 | Py_XDECREF(result); |
| 3510 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3511 | } |
| 3512 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3513 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3514 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3515 | switch(o) { |
| 3516 | case And: |
| 3517 | Py_INCREF(And_singleton); |
| 3518 | return And_singleton; |
| 3519 | case Or: |
| 3520 | Py_INCREF(Or_singleton); |
| 3521 | return Or_singleton; |
| 3522 | default: |
| 3523 | /* should never happen, but just in case ... */ |
| 3524 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 3525 | return NULL; |
| 3526 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3527 | } |
| 3528 | PyObject* ast2obj_operator(operator_ty o) |
| 3529 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3530 | switch(o) { |
| 3531 | case Add: |
| 3532 | Py_INCREF(Add_singleton); |
| 3533 | return Add_singleton; |
| 3534 | case Sub: |
| 3535 | Py_INCREF(Sub_singleton); |
| 3536 | return Sub_singleton; |
| 3537 | case Mult: |
| 3538 | Py_INCREF(Mult_singleton); |
| 3539 | return Mult_singleton; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 3540 | case MatMult: |
| 3541 | Py_INCREF(MatMult_singleton); |
| 3542 | return MatMult_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3543 | case Div: |
| 3544 | Py_INCREF(Div_singleton); |
| 3545 | return Div_singleton; |
| 3546 | case Mod: |
| 3547 | Py_INCREF(Mod_singleton); |
| 3548 | return Mod_singleton; |
| 3549 | case Pow: |
| 3550 | Py_INCREF(Pow_singleton); |
| 3551 | return Pow_singleton; |
| 3552 | case LShift: |
| 3553 | Py_INCREF(LShift_singleton); |
| 3554 | return LShift_singleton; |
| 3555 | case RShift: |
| 3556 | Py_INCREF(RShift_singleton); |
| 3557 | return RShift_singleton; |
| 3558 | case BitOr: |
| 3559 | Py_INCREF(BitOr_singleton); |
| 3560 | return BitOr_singleton; |
| 3561 | case BitXor: |
| 3562 | Py_INCREF(BitXor_singleton); |
| 3563 | return BitXor_singleton; |
| 3564 | case BitAnd: |
| 3565 | Py_INCREF(BitAnd_singleton); |
| 3566 | return BitAnd_singleton; |
| 3567 | case FloorDiv: |
| 3568 | Py_INCREF(FloorDiv_singleton); |
| 3569 | return FloorDiv_singleton; |
| 3570 | default: |
| 3571 | /* should never happen, but just in case ... */ |
| 3572 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 3573 | return NULL; |
| 3574 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3575 | } |
| 3576 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 3577 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3578 | switch(o) { |
| 3579 | case Invert: |
| 3580 | Py_INCREF(Invert_singleton); |
| 3581 | return Invert_singleton; |
| 3582 | case Not: |
| 3583 | Py_INCREF(Not_singleton); |
| 3584 | return Not_singleton; |
| 3585 | case UAdd: |
| 3586 | Py_INCREF(UAdd_singleton); |
| 3587 | return UAdd_singleton; |
| 3588 | case USub: |
| 3589 | Py_INCREF(USub_singleton); |
| 3590 | return USub_singleton; |
| 3591 | default: |
| 3592 | /* should never happen, but just in case ... */ |
| 3593 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 3594 | return NULL; |
| 3595 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3596 | } |
| 3597 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 3598 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3599 | switch(o) { |
| 3600 | case Eq: |
| 3601 | Py_INCREF(Eq_singleton); |
| 3602 | return Eq_singleton; |
| 3603 | case NotEq: |
| 3604 | Py_INCREF(NotEq_singleton); |
| 3605 | return NotEq_singleton; |
| 3606 | case Lt: |
| 3607 | Py_INCREF(Lt_singleton); |
| 3608 | return Lt_singleton; |
| 3609 | case LtE: |
| 3610 | Py_INCREF(LtE_singleton); |
| 3611 | return LtE_singleton; |
| 3612 | case Gt: |
| 3613 | Py_INCREF(Gt_singleton); |
| 3614 | return Gt_singleton; |
| 3615 | case GtE: |
| 3616 | Py_INCREF(GtE_singleton); |
| 3617 | return GtE_singleton; |
| 3618 | case Is: |
| 3619 | Py_INCREF(Is_singleton); |
| 3620 | return Is_singleton; |
| 3621 | case IsNot: |
| 3622 | Py_INCREF(IsNot_singleton); |
| 3623 | return IsNot_singleton; |
| 3624 | case In: |
| 3625 | Py_INCREF(In_singleton); |
| 3626 | return In_singleton; |
| 3627 | case NotIn: |
| 3628 | Py_INCREF(NotIn_singleton); |
| 3629 | return NotIn_singleton; |
| 3630 | default: |
| 3631 | /* should never happen, but just in case ... */ |
| 3632 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 3633 | return NULL; |
| 3634 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3635 | } |
| 3636 | PyObject* |
| 3637 | ast2obj_comprehension(void* _o) |
| 3638 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3639 | comprehension_ty o = (comprehension_ty)_o; |
| 3640 | PyObject *result = NULL, *value = NULL; |
| 3641 | if (!o) { |
| 3642 | Py_INCREF(Py_None); |
| 3643 | return Py_None; |
| 3644 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3645 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3646 | result = PyType_GenericNew(comprehension_type, NULL, NULL); |
| 3647 | if (!result) return NULL; |
| 3648 | value = ast2obj_expr(o->target); |
| 3649 | if (!value) goto failed; |
| 3650 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 3651 | goto failed; |
| 3652 | Py_DECREF(value); |
| 3653 | value = ast2obj_expr(o->iter); |
| 3654 | if (!value) goto failed; |
| 3655 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 3656 | goto failed; |
| 3657 | Py_DECREF(value); |
| 3658 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 3659 | if (!value) goto failed; |
| 3660 | if (_PyObject_SetAttrId(result, &PyId_ifs, value) == -1) |
| 3661 | goto failed; |
| 3662 | Py_DECREF(value); |
| 3663 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3664 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3665 | Py_XDECREF(value); |
| 3666 | Py_XDECREF(result); |
| 3667 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3668 | } |
| 3669 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3670 | PyObject* |
| 3671 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3672 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3673 | excepthandler_ty o = (excepthandler_ty)_o; |
| 3674 | PyObject *result = NULL, *value = NULL; |
| 3675 | if (!o) { |
| 3676 | Py_INCREF(Py_None); |
| 3677 | return Py_None; |
| 3678 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3679 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3680 | switch (o->kind) { |
| 3681 | case ExceptHandler_kind: |
| 3682 | result = PyType_GenericNew(ExceptHandler_type, NULL, NULL); |
| 3683 | if (!result) goto failed; |
| 3684 | value = ast2obj_expr(o->v.ExceptHandler.type); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3685 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3686 | if (_PyObject_SetAttrId(result, &PyId_type, value) == -1) |
| 3687 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3688 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3689 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3690 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3691 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 3692 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3693 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3694 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 3695 | if (!value) goto failed; |
| 3696 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3697 | goto failed; |
| 3698 | Py_DECREF(value); |
| 3699 | break; |
| 3700 | } |
| 3701 | value = ast2obj_int(o->lineno); |
| 3702 | if (!value) goto failed; |
| 3703 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3704 | goto failed; |
| 3705 | Py_DECREF(value); |
| 3706 | value = ast2obj_int(o->col_offset); |
| 3707 | if (!value) goto failed; |
| 3708 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3709 | goto failed; |
| 3710 | Py_DECREF(value); |
| 3711 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3712 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3713 | Py_XDECREF(value); |
| 3714 | Py_XDECREF(result); |
| 3715 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3716 | } |
| 3717 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3718 | PyObject* |
| 3719 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3720 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3721 | arguments_ty o = (arguments_ty)_o; |
| 3722 | PyObject *result = NULL, *value = NULL; |
| 3723 | if (!o) { |
| 3724 | Py_INCREF(Py_None); |
| 3725 | return Py_None; |
| 3726 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3727 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3728 | result = PyType_GenericNew(arguments_type, NULL, NULL); |
| 3729 | if (!result) return NULL; |
| 3730 | value = ast2obj_list(o->args, ast2obj_arg); |
| 3731 | if (!value) goto failed; |
| 3732 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3733 | goto failed; |
| 3734 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3735 | value = ast2obj_arg(o->vararg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3736 | if (!value) goto failed; |
| 3737 | if (_PyObject_SetAttrId(result, &PyId_vararg, value) == -1) |
| 3738 | goto failed; |
| 3739 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3740 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
| 3741 | if (!value) goto failed; |
| 3742 | if (_PyObject_SetAttrId(result, &PyId_kwonlyargs, value) == -1) |
| 3743 | goto failed; |
| 3744 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3745 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3746 | if (!value) goto failed; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3747 | if (_PyObject_SetAttrId(result, &PyId_kw_defaults, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3748 | goto failed; |
| 3749 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3750 | value = ast2obj_arg(o->kwarg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3751 | if (!value) goto failed; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3752 | if (_PyObject_SetAttrId(result, &PyId_kwarg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3753 | goto failed; |
| 3754 | Py_DECREF(value); |
| 3755 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 3756 | if (!value) goto failed; |
| 3757 | if (_PyObject_SetAttrId(result, &PyId_defaults, value) == -1) |
| 3758 | goto failed; |
| 3759 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3760 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3761 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3762 | Py_XDECREF(value); |
| 3763 | Py_XDECREF(result); |
| 3764 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3765 | } |
| 3766 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3767 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3768 | ast2obj_arg(void* _o) |
| 3769 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3770 | arg_ty o = (arg_ty)_o; |
| 3771 | PyObject *result = NULL, *value = NULL; |
| 3772 | if (!o) { |
| 3773 | Py_INCREF(Py_None); |
| 3774 | return Py_None; |
| 3775 | } |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3776 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3777 | result = PyType_GenericNew(arg_type, NULL, NULL); |
| 3778 | if (!result) return NULL; |
| 3779 | value = ast2obj_identifier(o->arg); |
| 3780 | if (!value) goto failed; |
| 3781 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
| 3782 | goto failed; |
| 3783 | Py_DECREF(value); |
| 3784 | value = ast2obj_expr(o->annotation); |
| 3785 | if (!value) goto failed; |
| 3786 | if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) |
| 3787 | goto failed; |
| 3788 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3789 | value = ast2obj_int(o->lineno); |
| 3790 | if (!value) goto failed; |
| 3791 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3792 | goto failed; |
| 3793 | Py_DECREF(value); |
| 3794 | value = ast2obj_int(o->col_offset); |
| 3795 | if (!value) goto failed; |
| 3796 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3797 | goto failed; |
| 3798 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3799 | return result; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3800 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3801 | Py_XDECREF(value); |
| 3802 | Py_XDECREF(result); |
| 3803 | return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3804 | } |
| 3805 | |
| 3806 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3807 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3808 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3809 | keyword_ty o = (keyword_ty)_o; |
| 3810 | PyObject *result = NULL, *value = NULL; |
| 3811 | if (!o) { |
| 3812 | Py_INCREF(Py_None); |
| 3813 | return Py_None; |
| 3814 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3815 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3816 | result = PyType_GenericNew(keyword_type, NULL, NULL); |
| 3817 | if (!result) return NULL; |
| 3818 | value = ast2obj_identifier(o->arg); |
| 3819 | if (!value) goto failed; |
| 3820 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
| 3821 | goto failed; |
| 3822 | Py_DECREF(value); |
| 3823 | value = ast2obj_expr(o->value); |
| 3824 | if (!value) goto failed; |
| 3825 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3826 | goto failed; |
| 3827 | Py_DECREF(value); |
| 3828 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3829 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3830 | Py_XDECREF(value); |
| 3831 | Py_XDECREF(result); |
| 3832 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3833 | } |
| 3834 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3835 | PyObject* |
| 3836 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3837 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3838 | alias_ty o = (alias_ty)_o; |
| 3839 | PyObject *result = NULL, *value = NULL; |
| 3840 | if (!o) { |
| 3841 | Py_INCREF(Py_None); |
| 3842 | return Py_None; |
| 3843 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3844 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3845 | result = PyType_GenericNew(alias_type, NULL, NULL); |
| 3846 | if (!result) return NULL; |
| 3847 | value = ast2obj_identifier(o->name); |
| 3848 | if (!value) goto failed; |
| 3849 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 3850 | goto failed; |
| 3851 | Py_DECREF(value); |
| 3852 | value = ast2obj_identifier(o->asname); |
| 3853 | if (!value) goto failed; |
| 3854 | if (_PyObject_SetAttrId(result, &PyId_asname, value) == -1) |
| 3855 | goto failed; |
| 3856 | Py_DECREF(value); |
| 3857 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3858 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3859 | Py_XDECREF(value); |
| 3860 | Py_XDECREF(result); |
| 3861 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3862 | } |
| 3863 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3864 | PyObject* |
| 3865 | ast2obj_withitem(void* _o) |
| 3866 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3867 | withitem_ty o = (withitem_ty)_o; |
| 3868 | PyObject *result = NULL, *value = NULL; |
| 3869 | if (!o) { |
| 3870 | Py_INCREF(Py_None); |
| 3871 | return Py_None; |
| 3872 | } |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3873 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3874 | result = PyType_GenericNew(withitem_type, NULL, NULL); |
| 3875 | if (!result) return NULL; |
| 3876 | value = ast2obj_expr(o->context_expr); |
| 3877 | if (!value) goto failed; |
| 3878 | if (_PyObject_SetAttrId(result, &PyId_context_expr, value) == -1) |
| 3879 | goto failed; |
| 3880 | Py_DECREF(value); |
| 3881 | value = ast2obj_expr(o->optional_vars); |
| 3882 | if (!value) goto failed; |
| 3883 | if (_PyObject_SetAttrId(result, &PyId_optional_vars, value) == -1) |
| 3884 | goto failed; |
| 3885 | Py_DECREF(value); |
| 3886 | return result; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3887 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3888 | Py_XDECREF(value); |
| 3889 | Py_XDECREF(result); |
| 3890 | return NULL; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3891 | } |
| 3892 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3893 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3894 | int |
| 3895 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 3896 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3897 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3898 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3899 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3900 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3901 | if (obj == Py_None) { |
| 3902 | *out = NULL; |
| 3903 | return 0; |
| 3904 | } |
| 3905 | isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type); |
| 3906 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3907 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3908 | } |
| 3909 | if (isinstance) { |
| 3910 | asdl_seq* body; |
| 3911 | |
| 3912 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 3913 | int res; |
| 3914 | Py_ssize_t len; |
| 3915 | Py_ssize_t i; |
| 3916 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 3917 | if (tmp == NULL) goto failed; |
| 3918 | if (!PyList_Check(tmp)) { |
| 3919 | PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3920 | goto failed; |
| 3921 | } |
| 3922 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 3923 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3924 | if (body == NULL) goto failed; |
| 3925 | for (i = 0; i < len; i++) { |
| 3926 | stmt_ty value; |
| 3927 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3928 | if (res != 0) goto failed; |
| 3929 | asdl_seq_SET(body, i, value); |
| 3930 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 3931 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3932 | } else { |
| 3933 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 3934 | return 1; |
| 3935 | } |
| 3936 | *out = Module(body, arena); |
| 3937 | if (*out == NULL) goto failed; |
| 3938 | return 0; |
| 3939 | } |
| 3940 | isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type); |
| 3941 | if (isinstance == -1) { |
| 3942 | return 1; |
| 3943 | } |
| 3944 | if (isinstance) { |
| 3945 | asdl_seq* body; |
| 3946 | |
| 3947 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 3948 | int res; |
| 3949 | Py_ssize_t len; |
| 3950 | Py_ssize_t i; |
| 3951 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 3952 | if (tmp == NULL) goto failed; |
| 3953 | if (!PyList_Check(tmp)) { |
| 3954 | PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3955 | goto failed; |
| 3956 | } |
| 3957 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 3958 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3959 | if (body == NULL) goto failed; |
| 3960 | for (i = 0; i < len; i++) { |
| 3961 | stmt_ty value; |
| 3962 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3963 | if (res != 0) goto failed; |
| 3964 | asdl_seq_SET(body, i, value); |
| 3965 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 3966 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3967 | } else { |
| 3968 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 3969 | return 1; |
| 3970 | } |
| 3971 | *out = Interactive(body, arena); |
| 3972 | if (*out == NULL) goto failed; |
| 3973 | return 0; |
| 3974 | } |
| 3975 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type); |
| 3976 | if (isinstance == -1) { |
| 3977 | return 1; |
| 3978 | } |
| 3979 | if (isinstance) { |
| 3980 | expr_ty body; |
| 3981 | |
| 3982 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 3983 | int res; |
| 3984 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 3985 | if (tmp == NULL) goto failed; |
| 3986 | res = obj2ast_expr(tmp, &body, arena); |
| 3987 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 3988 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3989 | } else { |
| 3990 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 3991 | return 1; |
| 3992 | } |
| 3993 | *out = Expression(body, arena); |
| 3994 | if (*out == NULL) goto failed; |
| 3995 | return 0; |
| 3996 | } |
| 3997 | isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type); |
| 3998 | if (isinstance == -1) { |
| 3999 | return 1; |
| 4000 | } |
| 4001 | if (isinstance) { |
| 4002 | asdl_seq* body; |
| 4003 | |
| 4004 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4005 | int res; |
| 4006 | Py_ssize_t len; |
| 4007 | Py_ssize_t i; |
| 4008 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4009 | if (tmp == NULL) goto failed; |
| 4010 | if (!PyList_Check(tmp)) { |
| 4011 | PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4012 | goto failed; |
| 4013 | } |
| 4014 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4015 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4016 | if (body == NULL) goto failed; |
| 4017 | for (i = 0; i < len; i++) { |
| 4018 | stmt_ty value; |
| 4019 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4020 | if (res != 0) goto failed; |
| 4021 | asdl_seq_SET(body, i, value); |
| 4022 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4023 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4024 | } else { |
| 4025 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite"); |
| 4026 | return 1; |
| 4027 | } |
| 4028 | *out = Suite(body, arena); |
| 4029 | if (*out == NULL) goto failed; |
| 4030 | return 0; |
| 4031 | } |
| 4032 | |
| 4033 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
| 4034 | failed: |
| 4035 | Py_XDECREF(tmp); |
| 4036 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4037 | } |
| 4038 | |
| 4039 | int |
| 4040 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 4041 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4042 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4043 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4044 | PyObject *tmp = NULL; |
| 4045 | int lineno; |
| 4046 | int col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4047 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4048 | if (obj == Py_None) { |
| 4049 | *out = NULL; |
| 4050 | return 0; |
| 4051 | } |
| 4052 | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
| 4053 | int res; |
| 4054 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
| 4055 | if (tmp == NULL) goto failed; |
| 4056 | res = obj2ast_int(tmp, &lineno, arena); |
| 4057 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4058 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4059 | } else { |
| 4060 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4061 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4062 | } |
| 4063 | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
| 4064 | int res; |
| 4065 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
| 4066 | if (tmp == NULL) goto failed; |
| 4067 | res = obj2ast_int(tmp, &col_offset, arena); |
| 4068 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4069 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4070 | } else { |
| 4071 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 4072 | return 1; |
| 4073 | } |
| 4074 | isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type); |
| 4075 | if (isinstance == -1) { |
| 4076 | return 1; |
| 4077 | } |
| 4078 | if (isinstance) { |
| 4079 | identifier name; |
| 4080 | arguments_ty args; |
| 4081 | asdl_seq* body; |
| 4082 | asdl_seq* decorator_list; |
| 4083 | expr_ty returns; |
| 4084 | |
| 4085 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
| 4086 | int res; |
| 4087 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
| 4088 | if (tmp == NULL) goto failed; |
| 4089 | res = obj2ast_identifier(tmp, &name, arena); |
| 4090 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4091 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4092 | } else { |
| 4093 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 4094 | return 1; |
| 4095 | } |
| 4096 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
| 4097 | int res; |
| 4098 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
| 4099 | if (tmp == NULL) goto failed; |
| 4100 | res = obj2ast_arguments(tmp, &args, arena); |
| 4101 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4102 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4103 | } else { |
| 4104 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 4105 | return 1; |
| 4106 | } |
| 4107 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4108 | int res; |
| 4109 | Py_ssize_t len; |
| 4110 | Py_ssize_t i; |
| 4111 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4112 | if (tmp == NULL) goto failed; |
| 4113 | if (!PyList_Check(tmp)) { |
| 4114 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4115 | goto failed; |
| 4116 | } |
| 4117 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4118 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4119 | if (body == NULL) goto failed; |
| 4120 | for (i = 0; i < len; i++) { |
| 4121 | stmt_ty value; |
| 4122 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4123 | if (res != 0) goto failed; |
| 4124 | asdl_seq_SET(body, i, value); |
| 4125 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4126 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4127 | } else { |
| 4128 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 4129 | return 1; |
| 4130 | } |
| 4131 | if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) { |
| 4132 | int res; |
| 4133 | Py_ssize_t len; |
| 4134 | Py_ssize_t i; |
| 4135 | tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); |
| 4136 | if (tmp == NULL) goto failed; |
| 4137 | if (!PyList_Check(tmp)) { |
| 4138 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4139 | goto failed; |
| 4140 | } |
| 4141 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4142 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4143 | if (decorator_list == NULL) goto failed; |
| 4144 | for (i = 0; i < len; i++) { |
| 4145 | expr_ty value; |
| 4146 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4147 | if (res != 0) goto failed; |
| 4148 | asdl_seq_SET(decorator_list, i, value); |
| 4149 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4150 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4151 | } else { |
| 4152 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 4153 | return 1; |
| 4154 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4155 | if (exists_not_none(obj, &PyId_returns)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4156 | int res; |
| 4157 | tmp = _PyObject_GetAttrId(obj, &PyId_returns); |
| 4158 | if (tmp == NULL) goto failed; |
| 4159 | res = obj2ast_expr(tmp, &returns, arena); |
| 4160 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4161 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4162 | } else { |
| 4163 | returns = NULL; |
| 4164 | } |
| 4165 | *out = FunctionDef(name, args, body, decorator_list, returns, lineno, |
| 4166 | col_offset, arena); |
| 4167 | if (*out == NULL) goto failed; |
| 4168 | return 0; |
| 4169 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4170 | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncFunctionDef_type); |
| 4171 | if (isinstance == -1) { |
| 4172 | return 1; |
| 4173 | } |
| 4174 | if (isinstance) { |
| 4175 | identifier name; |
| 4176 | arguments_ty args; |
| 4177 | asdl_seq* body; |
| 4178 | asdl_seq* decorator_list; |
| 4179 | expr_ty returns; |
| 4180 | |
| 4181 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
| 4182 | int res; |
| 4183 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
| 4184 | if (tmp == NULL) goto failed; |
| 4185 | res = obj2ast_identifier(tmp, &name, arena); |
| 4186 | if (res != 0) goto failed; |
| 4187 | Py_CLEAR(tmp); |
| 4188 | } else { |
| 4189 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef"); |
| 4190 | return 1; |
| 4191 | } |
| 4192 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
| 4193 | int res; |
| 4194 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
| 4195 | if (tmp == NULL) goto failed; |
| 4196 | res = obj2ast_arguments(tmp, &args, arena); |
| 4197 | if (res != 0) goto failed; |
| 4198 | Py_CLEAR(tmp); |
| 4199 | } else { |
| 4200 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef"); |
| 4201 | return 1; |
| 4202 | } |
| 4203 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4204 | int res; |
| 4205 | Py_ssize_t len; |
| 4206 | Py_ssize_t i; |
| 4207 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4208 | if (tmp == NULL) goto failed; |
| 4209 | if (!PyList_Check(tmp)) { |
| 4210 | PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4211 | goto failed; |
| 4212 | } |
| 4213 | len = PyList_GET_SIZE(tmp); |
| 4214 | body = _Py_asdl_seq_new(len, arena); |
| 4215 | if (body == NULL) goto failed; |
| 4216 | for (i = 0; i < len; i++) { |
| 4217 | stmt_ty value; |
| 4218 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4219 | if (res != 0) goto failed; |
| 4220 | asdl_seq_SET(body, i, value); |
| 4221 | } |
| 4222 | Py_CLEAR(tmp); |
| 4223 | } else { |
| 4224 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef"); |
| 4225 | return 1; |
| 4226 | } |
| 4227 | if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) { |
| 4228 | int res; |
| 4229 | Py_ssize_t len; |
| 4230 | Py_ssize_t i; |
| 4231 | tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); |
| 4232 | if (tmp == NULL) goto failed; |
| 4233 | if (!PyList_Check(tmp)) { |
| 4234 | PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4235 | goto failed; |
| 4236 | } |
| 4237 | len = PyList_GET_SIZE(tmp); |
| 4238 | decorator_list = _Py_asdl_seq_new(len, arena); |
| 4239 | if (decorator_list == NULL) goto failed; |
| 4240 | for (i = 0; i < len; i++) { |
| 4241 | expr_ty value; |
| 4242 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4243 | if (res != 0) goto failed; |
| 4244 | asdl_seq_SET(decorator_list, i, value); |
| 4245 | } |
| 4246 | Py_CLEAR(tmp); |
| 4247 | } else { |
| 4248 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef"); |
| 4249 | return 1; |
| 4250 | } |
| 4251 | if (exists_not_none(obj, &PyId_returns)) { |
| 4252 | int res; |
| 4253 | tmp = _PyObject_GetAttrId(obj, &PyId_returns); |
| 4254 | if (tmp == NULL) goto failed; |
| 4255 | res = obj2ast_expr(tmp, &returns, arena); |
| 4256 | if (res != 0) goto failed; |
| 4257 | Py_CLEAR(tmp); |
| 4258 | } else { |
| 4259 | returns = NULL; |
| 4260 | } |
| 4261 | *out = AsyncFunctionDef(name, args, body, decorator_list, returns, |
| 4262 | lineno, col_offset, arena); |
| 4263 | if (*out == NULL) goto failed; |
| 4264 | return 0; |
| 4265 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4266 | isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type); |
| 4267 | if (isinstance == -1) { |
| 4268 | return 1; |
| 4269 | } |
| 4270 | if (isinstance) { |
| 4271 | identifier name; |
| 4272 | asdl_seq* bases; |
| 4273 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4274 | asdl_seq* body; |
| 4275 | asdl_seq* decorator_list; |
| 4276 | |
| 4277 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
| 4278 | int res; |
| 4279 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
| 4280 | if (tmp == NULL) goto failed; |
| 4281 | res = obj2ast_identifier(tmp, &name, arena); |
| 4282 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4283 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4284 | } else { |
| 4285 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 4286 | return 1; |
| 4287 | } |
| 4288 | if (_PyObject_HasAttrId(obj, &PyId_bases)) { |
| 4289 | int res; |
| 4290 | Py_ssize_t len; |
| 4291 | Py_ssize_t i; |
| 4292 | tmp = _PyObject_GetAttrId(obj, &PyId_bases); |
| 4293 | if (tmp == NULL) goto failed; |
| 4294 | if (!PyList_Check(tmp)) { |
| 4295 | PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4296 | goto failed; |
| 4297 | } |
| 4298 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4299 | bases = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4300 | if (bases == NULL) goto failed; |
| 4301 | for (i = 0; i < len; i++) { |
| 4302 | expr_ty value; |
| 4303 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4304 | if (res != 0) goto failed; |
| 4305 | asdl_seq_SET(bases, i, value); |
| 4306 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4307 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4308 | } else { |
| 4309 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 4310 | return 1; |
| 4311 | } |
| 4312 | if (_PyObject_HasAttrId(obj, &PyId_keywords)) { |
| 4313 | int res; |
| 4314 | Py_ssize_t len; |
| 4315 | Py_ssize_t i; |
| 4316 | tmp = _PyObject_GetAttrId(obj, &PyId_keywords); |
| 4317 | if (tmp == NULL) goto failed; |
| 4318 | if (!PyList_Check(tmp)) { |
| 4319 | PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4320 | goto failed; |
| 4321 | } |
| 4322 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4323 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4324 | if (keywords == NULL) goto failed; |
| 4325 | for (i = 0; i < len; i++) { |
| 4326 | keyword_ty value; |
| 4327 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4328 | if (res != 0) goto failed; |
| 4329 | asdl_seq_SET(keywords, i, value); |
| 4330 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4331 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4332 | } else { |
| 4333 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 4334 | return 1; |
| 4335 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4336 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4337 | int res; |
| 4338 | Py_ssize_t len; |
| 4339 | Py_ssize_t i; |
| 4340 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4341 | if (tmp == NULL) goto failed; |
| 4342 | if (!PyList_Check(tmp)) { |
| 4343 | PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4344 | goto failed; |
| 4345 | } |
| 4346 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4347 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4348 | if (body == NULL) goto failed; |
| 4349 | for (i = 0; i < len; i++) { |
| 4350 | stmt_ty value; |
| 4351 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4352 | if (res != 0) goto failed; |
| 4353 | asdl_seq_SET(body, i, value); |
| 4354 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4355 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4356 | } else { |
| 4357 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 4358 | return 1; |
| 4359 | } |
| 4360 | if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) { |
| 4361 | int res; |
| 4362 | Py_ssize_t len; |
| 4363 | Py_ssize_t i; |
| 4364 | tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); |
| 4365 | if (tmp == NULL) goto failed; |
| 4366 | if (!PyList_Check(tmp)) { |
| 4367 | PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4368 | goto failed; |
| 4369 | } |
| 4370 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4371 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4372 | if (decorator_list == NULL) goto failed; |
| 4373 | for (i = 0; i < len; i++) { |
| 4374 | expr_ty value; |
| 4375 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4376 | if (res != 0) goto failed; |
| 4377 | asdl_seq_SET(decorator_list, i, value); |
| 4378 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4379 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4380 | } else { |
| 4381 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 4382 | return 1; |
| 4383 | } |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 4384 | *out = ClassDef(name, bases, keywords, body, decorator_list, lineno, |
| 4385 | col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4386 | if (*out == NULL) goto failed; |
| 4387 | return 0; |
| 4388 | } |
| 4389 | isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type); |
| 4390 | if (isinstance == -1) { |
| 4391 | return 1; |
| 4392 | } |
| 4393 | if (isinstance) { |
| 4394 | expr_ty value; |
| 4395 | |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4396 | if (exists_not_none(obj, &PyId_value)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4397 | int res; |
| 4398 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 4399 | if (tmp == NULL) goto failed; |
| 4400 | res = obj2ast_expr(tmp, &value, arena); |
| 4401 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4402 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4403 | } else { |
| 4404 | value = NULL; |
| 4405 | } |
| 4406 | *out = Return(value, lineno, col_offset, arena); |
| 4407 | if (*out == NULL) goto failed; |
| 4408 | return 0; |
| 4409 | } |
| 4410 | isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type); |
| 4411 | if (isinstance == -1) { |
| 4412 | return 1; |
| 4413 | } |
| 4414 | if (isinstance) { |
| 4415 | asdl_seq* targets; |
| 4416 | |
| 4417 | if (_PyObject_HasAttrId(obj, &PyId_targets)) { |
| 4418 | int res; |
| 4419 | Py_ssize_t len; |
| 4420 | Py_ssize_t i; |
| 4421 | tmp = _PyObject_GetAttrId(obj, &PyId_targets); |
| 4422 | if (tmp == NULL) goto failed; |
| 4423 | if (!PyList_Check(tmp)) { |
| 4424 | PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4425 | goto failed; |
| 4426 | } |
| 4427 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4428 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4429 | if (targets == NULL) goto failed; |
| 4430 | for (i = 0; i < len; i++) { |
| 4431 | expr_ty value; |
| 4432 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4433 | if (res != 0) goto failed; |
| 4434 | asdl_seq_SET(targets, i, value); |
| 4435 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4436 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4437 | } else { |
| 4438 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 4439 | return 1; |
| 4440 | } |
| 4441 | *out = Delete(targets, lineno, col_offset, arena); |
| 4442 | if (*out == NULL) goto failed; |
| 4443 | return 0; |
| 4444 | } |
| 4445 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type); |
| 4446 | if (isinstance == -1) { |
| 4447 | return 1; |
| 4448 | } |
| 4449 | if (isinstance) { |
| 4450 | asdl_seq* targets; |
| 4451 | expr_ty value; |
| 4452 | |
| 4453 | if (_PyObject_HasAttrId(obj, &PyId_targets)) { |
| 4454 | int res; |
| 4455 | Py_ssize_t len; |
| 4456 | Py_ssize_t i; |
| 4457 | tmp = _PyObject_GetAttrId(obj, &PyId_targets); |
| 4458 | if (tmp == NULL) goto failed; |
| 4459 | if (!PyList_Check(tmp)) { |
| 4460 | PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4461 | goto failed; |
| 4462 | } |
| 4463 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4464 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4465 | if (targets == NULL) goto failed; |
| 4466 | for (i = 0; i < len; i++) { |
| 4467 | expr_ty value; |
| 4468 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4469 | if (res != 0) goto failed; |
| 4470 | asdl_seq_SET(targets, i, value); |
| 4471 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4472 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4473 | } else { |
| 4474 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 4475 | return 1; |
| 4476 | } |
| 4477 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 4478 | int res; |
| 4479 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 4480 | if (tmp == NULL) goto failed; |
| 4481 | res = obj2ast_expr(tmp, &value, arena); |
| 4482 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4483 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4484 | } else { |
| 4485 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 4486 | return 1; |
| 4487 | } |
| 4488 | *out = Assign(targets, value, lineno, col_offset, arena); |
| 4489 | if (*out == NULL) goto failed; |
| 4490 | return 0; |
| 4491 | } |
| 4492 | isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type); |
| 4493 | if (isinstance == -1) { |
| 4494 | return 1; |
| 4495 | } |
| 4496 | if (isinstance) { |
| 4497 | expr_ty target; |
| 4498 | operator_ty op; |
| 4499 | expr_ty value; |
| 4500 | |
| 4501 | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
| 4502 | int res; |
| 4503 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
| 4504 | if (tmp == NULL) goto failed; |
| 4505 | res = obj2ast_expr(tmp, &target, arena); |
| 4506 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4507 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4508 | } else { |
| 4509 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 4510 | return 1; |
| 4511 | } |
| 4512 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
| 4513 | int res; |
| 4514 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
| 4515 | if (tmp == NULL) goto failed; |
| 4516 | res = obj2ast_operator(tmp, &op, arena); |
| 4517 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4518 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4519 | } else { |
| 4520 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 4521 | return 1; |
| 4522 | } |
| 4523 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 4524 | int res; |
| 4525 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 4526 | if (tmp == NULL) goto failed; |
| 4527 | res = obj2ast_expr(tmp, &value, arena); |
| 4528 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4529 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4530 | } else { |
| 4531 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 4532 | return 1; |
| 4533 | } |
| 4534 | *out = AugAssign(target, op, value, lineno, col_offset, arena); |
| 4535 | if (*out == NULL) goto failed; |
| 4536 | return 0; |
| 4537 | } |
| 4538 | isinstance = PyObject_IsInstance(obj, (PyObject*)For_type); |
| 4539 | if (isinstance == -1) { |
| 4540 | return 1; |
| 4541 | } |
| 4542 | if (isinstance) { |
| 4543 | expr_ty target; |
| 4544 | expr_ty iter; |
| 4545 | asdl_seq* body; |
| 4546 | asdl_seq* orelse; |
| 4547 | |
| 4548 | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
| 4549 | int res; |
| 4550 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
| 4551 | if (tmp == NULL) goto failed; |
| 4552 | res = obj2ast_expr(tmp, &target, arena); |
| 4553 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4554 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4555 | } else { |
| 4556 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 4557 | return 1; |
| 4558 | } |
| 4559 | if (_PyObject_HasAttrId(obj, &PyId_iter)) { |
| 4560 | int res; |
| 4561 | tmp = _PyObject_GetAttrId(obj, &PyId_iter); |
| 4562 | if (tmp == NULL) goto failed; |
| 4563 | res = obj2ast_expr(tmp, &iter, arena); |
| 4564 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4565 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4566 | } else { |
| 4567 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 4568 | return 1; |
| 4569 | } |
| 4570 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4571 | int res; |
| 4572 | Py_ssize_t len; |
| 4573 | Py_ssize_t i; |
| 4574 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4575 | if (tmp == NULL) goto failed; |
| 4576 | if (!PyList_Check(tmp)) { |
| 4577 | PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4578 | goto failed; |
| 4579 | } |
| 4580 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4581 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4582 | if (body == NULL) goto failed; |
| 4583 | for (i = 0; i < len; i++) { |
| 4584 | stmt_ty value; |
| 4585 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4586 | if (res != 0) goto failed; |
| 4587 | asdl_seq_SET(body, i, value); |
| 4588 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4589 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4590 | } else { |
| 4591 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 4592 | return 1; |
| 4593 | } |
| 4594 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
| 4595 | int res; |
| 4596 | Py_ssize_t len; |
| 4597 | Py_ssize_t i; |
| 4598 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
| 4599 | if (tmp == NULL) goto failed; |
| 4600 | if (!PyList_Check(tmp)) { |
| 4601 | PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4602 | goto failed; |
| 4603 | } |
| 4604 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4605 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4606 | if (orelse == NULL) goto failed; |
| 4607 | for (i = 0; i < len; i++) { |
| 4608 | stmt_ty value; |
| 4609 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4610 | if (res != 0) goto failed; |
| 4611 | asdl_seq_SET(orelse, i, value); |
| 4612 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4613 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4614 | } else { |
| 4615 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 4616 | return 1; |
| 4617 | } |
| 4618 | *out = For(target, iter, body, orelse, lineno, col_offset, arena); |
| 4619 | if (*out == NULL) goto failed; |
| 4620 | return 0; |
| 4621 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4622 | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncFor_type); |
| 4623 | if (isinstance == -1) { |
| 4624 | return 1; |
| 4625 | } |
| 4626 | if (isinstance) { |
| 4627 | expr_ty target; |
| 4628 | expr_ty iter; |
| 4629 | asdl_seq* body; |
| 4630 | asdl_seq* orelse; |
| 4631 | |
| 4632 | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
| 4633 | int res; |
| 4634 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
| 4635 | if (tmp == NULL) goto failed; |
| 4636 | res = obj2ast_expr(tmp, &target, arena); |
| 4637 | if (res != 0) goto failed; |
| 4638 | Py_CLEAR(tmp); |
| 4639 | } else { |
| 4640 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor"); |
| 4641 | return 1; |
| 4642 | } |
| 4643 | if (_PyObject_HasAttrId(obj, &PyId_iter)) { |
| 4644 | int res; |
| 4645 | tmp = _PyObject_GetAttrId(obj, &PyId_iter); |
| 4646 | if (tmp == NULL) goto failed; |
| 4647 | res = obj2ast_expr(tmp, &iter, arena); |
| 4648 | if (res != 0) goto failed; |
| 4649 | Py_CLEAR(tmp); |
| 4650 | } else { |
| 4651 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor"); |
| 4652 | return 1; |
| 4653 | } |
| 4654 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4655 | int res; |
| 4656 | Py_ssize_t len; |
| 4657 | Py_ssize_t i; |
| 4658 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4659 | if (tmp == NULL) goto failed; |
| 4660 | if (!PyList_Check(tmp)) { |
| 4661 | PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4662 | goto failed; |
| 4663 | } |
| 4664 | len = PyList_GET_SIZE(tmp); |
| 4665 | body = _Py_asdl_seq_new(len, arena); |
| 4666 | if (body == NULL) goto failed; |
| 4667 | for (i = 0; i < len; i++) { |
| 4668 | stmt_ty value; |
| 4669 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4670 | if (res != 0) goto failed; |
| 4671 | asdl_seq_SET(body, i, value); |
| 4672 | } |
| 4673 | Py_CLEAR(tmp); |
| 4674 | } else { |
| 4675 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor"); |
| 4676 | return 1; |
| 4677 | } |
| 4678 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
| 4679 | int res; |
| 4680 | Py_ssize_t len; |
| 4681 | Py_ssize_t i; |
| 4682 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
| 4683 | if (tmp == NULL) goto failed; |
| 4684 | if (!PyList_Check(tmp)) { |
| 4685 | PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4686 | goto failed; |
| 4687 | } |
| 4688 | len = PyList_GET_SIZE(tmp); |
| 4689 | orelse = _Py_asdl_seq_new(len, arena); |
| 4690 | if (orelse == NULL) goto failed; |
| 4691 | for (i = 0; i < len; i++) { |
| 4692 | stmt_ty value; |
| 4693 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4694 | if (res != 0) goto failed; |
| 4695 | asdl_seq_SET(orelse, i, value); |
| 4696 | } |
| 4697 | Py_CLEAR(tmp); |
| 4698 | } else { |
| 4699 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor"); |
| 4700 | return 1; |
| 4701 | } |
| 4702 | *out = AsyncFor(target, iter, body, orelse, lineno, col_offset, arena); |
| 4703 | if (*out == NULL) goto failed; |
| 4704 | return 0; |
| 4705 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4706 | isinstance = PyObject_IsInstance(obj, (PyObject*)While_type); |
| 4707 | if (isinstance == -1) { |
| 4708 | return 1; |
| 4709 | } |
| 4710 | if (isinstance) { |
| 4711 | expr_ty test; |
| 4712 | asdl_seq* body; |
| 4713 | asdl_seq* orelse; |
| 4714 | |
| 4715 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
| 4716 | int res; |
| 4717 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
| 4718 | if (tmp == NULL) goto failed; |
| 4719 | res = obj2ast_expr(tmp, &test, arena); |
| 4720 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4721 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4722 | } else { |
| 4723 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 4724 | return 1; |
| 4725 | } |
| 4726 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4727 | int res; |
| 4728 | Py_ssize_t len; |
| 4729 | Py_ssize_t i; |
| 4730 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4731 | if (tmp == NULL) goto failed; |
| 4732 | if (!PyList_Check(tmp)) { |
| 4733 | PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4734 | goto failed; |
| 4735 | } |
| 4736 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4737 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4738 | if (body == NULL) goto failed; |
| 4739 | for (i = 0; i < len; i++) { |
| 4740 | stmt_ty value; |
| 4741 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4742 | if (res != 0) goto failed; |
| 4743 | asdl_seq_SET(body, i, value); |
| 4744 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4745 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4746 | } else { |
| 4747 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 4748 | return 1; |
| 4749 | } |
| 4750 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
| 4751 | int res; |
| 4752 | Py_ssize_t len; |
| 4753 | Py_ssize_t i; |
| 4754 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
| 4755 | if (tmp == NULL) goto failed; |
| 4756 | if (!PyList_Check(tmp)) { |
| 4757 | PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4758 | goto failed; |
| 4759 | } |
| 4760 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4761 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4762 | if (orelse == NULL) goto failed; |
| 4763 | for (i = 0; i < len; i++) { |
| 4764 | stmt_ty value; |
| 4765 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4766 | if (res != 0) goto failed; |
| 4767 | asdl_seq_SET(orelse, i, value); |
| 4768 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4769 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4770 | } else { |
| 4771 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 4772 | return 1; |
| 4773 | } |
| 4774 | *out = While(test, body, orelse, lineno, col_offset, arena); |
| 4775 | if (*out == NULL) goto failed; |
| 4776 | return 0; |
| 4777 | } |
| 4778 | isinstance = PyObject_IsInstance(obj, (PyObject*)If_type); |
| 4779 | if (isinstance == -1) { |
| 4780 | return 1; |
| 4781 | } |
| 4782 | if (isinstance) { |
| 4783 | expr_ty test; |
| 4784 | asdl_seq* body; |
| 4785 | asdl_seq* orelse; |
| 4786 | |
| 4787 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
| 4788 | int res; |
| 4789 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
| 4790 | if (tmp == NULL) goto failed; |
| 4791 | res = obj2ast_expr(tmp, &test, arena); |
| 4792 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4793 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4794 | } else { |
| 4795 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 4796 | return 1; |
| 4797 | } |
| 4798 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4799 | int res; |
| 4800 | Py_ssize_t len; |
| 4801 | Py_ssize_t i; |
| 4802 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4803 | if (tmp == NULL) goto failed; |
| 4804 | if (!PyList_Check(tmp)) { |
| 4805 | PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4806 | goto failed; |
| 4807 | } |
| 4808 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4809 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4810 | if (body == NULL) goto failed; |
| 4811 | for (i = 0; i < len; i++) { |
| 4812 | stmt_ty value; |
| 4813 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4814 | if (res != 0) goto failed; |
| 4815 | asdl_seq_SET(body, i, value); |
| 4816 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4817 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4818 | } else { |
| 4819 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 4820 | return 1; |
| 4821 | } |
| 4822 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
| 4823 | int res; |
| 4824 | Py_ssize_t len; |
| 4825 | Py_ssize_t i; |
| 4826 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
| 4827 | if (tmp == NULL) goto failed; |
| 4828 | if (!PyList_Check(tmp)) { |
| 4829 | PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4830 | goto failed; |
| 4831 | } |
| 4832 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4833 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4834 | if (orelse == NULL) goto failed; |
| 4835 | for (i = 0; i < len; i++) { |
| 4836 | stmt_ty value; |
| 4837 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4838 | if (res != 0) goto failed; |
| 4839 | asdl_seq_SET(orelse, i, value); |
| 4840 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4841 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4842 | } else { |
| 4843 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 4844 | return 1; |
| 4845 | } |
| 4846 | *out = If(test, body, orelse, lineno, col_offset, arena); |
| 4847 | if (*out == NULL) goto failed; |
| 4848 | return 0; |
| 4849 | } |
| 4850 | isinstance = PyObject_IsInstance(obj, (PyObject*)With_type); |
| 4851 | if (isinstance == -1) { |
| 4852 | return 1; |
| 4853 | } |
| 4854 | if (isinstance) { |
| 4855 | asdl_seq* items; |
| 4856 | asdl_seq* body; |
| 4857 | |
| 4858 | if (_PyObject_HasAttrId(obj, &PyId_items)) { |
| 4859 | int res; |
| 4860 | Py_ssize_t len; |
| 4861 | Py_ssize_t i; |
| 4862 | tmp = _PyObject_GetAttrId(obj, &PyId_items); |
| 4863 | if (tmp == NULL) goto failed; |
| 4864 | if (!PyList_Check(tmp)) { |
| 4865 | PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4866 | goto failed; |
| 4867 | } |
| 4868 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4869 | items = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4870 | if (items == NULL) goto failed; |
| 4871 | for (i = 0; i < len; i++) { |
| 4872 | withitem_ty value; |
| 4873 | res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4874 | if (res != 0) goto failed; |
| 4875 | asdl_seq_SET(items, i, value); |
| 4876 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4877 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4878 | } else { |
| 4879 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); |
| 4880 | return 1; |
| 4881 | } |
| 4882 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4883 | int res; |
| 4884 | Py_ssize_t len; |
| 4885 | Py_ssize_t i; |
| 4886 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4887 | if (tmp == NULL) goto failed; |
| 4888 | if (!PyList_Check(tmp)) { |
| 4889 | PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4890 | goto failed; |
| 4891 | } |
| 4892 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4893 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4894 | if (body == NULL) goto failed; |
| 4895 | for (i = 0; i < len; i++) { |
| 4896 | stmt_ty value; |
| 4897 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4898 | if (res != 0) goto failed; |
| 4899 | asdl_seq_SET(body, i, value); |
| 4900 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4901 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4902 | } else { |
| 4903 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 4904 | return 1; |
| 4905 | } |
| 4906 | *out = With(items, body, lineno, col_offset, arena); |
| 4907 | if (*out == NULL) goto failed; |
| 4908 | return 0; |
| 4909 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4910 | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncWith_type); |
| 4911 | if (isinstance == -1) { |
| 4912 | return 1; |
| 4913 | } |
| 4914 | if (isinstance) { |
| 4915 | asdl_seq* items; |
| 4916 | asdl_seq* body; |
| 4917 | |
| 4918 | if (_PyObject_HasAttrId(obj, &PyId_items)) { |
| 4919 | int res; |
| 4920 | Py_ssize_t len; |
| 4921 | Py_ssize_t i; |
| 4922 | tmp = _PyObject_GetAttrId(obj, &PyId_items); |
| 4923 | if (tmp == NULL) goto failed; |
| 4924 | if (!PyList_Check(tmp)) { |
| 4925 | PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4926 | goto failed; |
| 4927 | } |
| 4928 | len = PyList_GET_SIZE(tmp); |
| 4929 | items = _Py_asdl_seq_new(len, arena); |
| 4930 | if (items == NULL) goto failed; |
| 4931 | for (i = 0; i < len; i++) { |
| 4932 | withitem_ty value; |
| 4933 | res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4934 | if (res != 0) goto failed; |
| 4935 | asdl_seq_SET(items, i, value); |
| 4936 | } |
| 4937 | Py_CLEAR(tmp); |
| 4938 | } else { |
| 4939 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith"); |
| 4940 | return 1; |
| 4941 | } |
| 4942 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4943 | int res; |
| 4944 | Py_ssize_t len; |
| 4945 | Py_ssize_t i; |
| 4946 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4947 | if (tmp == NULL) goto failed; |
| 4948 | if (!PyList_Check(tmp)) { |
| 4949 | PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4950 | goto failed; |
| 4951 | } |
| 4952 | len = PyList_GET_SIZE(tmp); |
| 4953 | body = _Py_asdl_seq_new(len, arena); |
| 4954 | if (body == NULL) goto failed; |
| 4955 | for (i = 0; i < len; i++) { |
| 4956 | stmt_ty value; |
| 4957 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4958 | if (res != 0) goto failed; |
| 4959 | asdl_seq_SET(body, i, value); |
| 4960 | } |
| 4961 | Py_CLEAR(tmp); |
| 4962 | } else { |
| 4963 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith"); |
| 4964 | return 1; |
| 4965 | } |
| 4966 | *out = AsyncWith(items, body, lineno, col_offset, arena); |
| 4967 | if (*out == NULL) goto failed; |
| 4968 | return 0; |
| 4969 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4970 | isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type); |
| 4971 | if (isinstance == -1) { |
| 4972 | return 1; |
| 4973 | } |
| 4974 | if (isinstance) { |
| 4975 | expr_ty exc; |
| 4976 | expr_ty cause; |
| 4977 | |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4978 | if (exists_not_none(obj, &PyId_exc)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4979 | int res; |
| 4980 | tmp = _PyObject_GetAttrId(obj, &PyId_exc); |
| 4981 | if (tmp == NULL) goto failed; |
| 4982 | res = obj2ast_expr(tmp, &exc, arena); |
| 4983 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4984 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4985 | } else { |
| 4986 | exc = NULL; |
| 4987 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4988 | if (exists_not_none(obj, &PyId_cause)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4989 | int res; |
| 4990 | tmp = _PyObject_GetAttrId(obj, &PyId_cause); |
| 4991 | if (tmp == NULL) goto failed; |
| 4992 | res = obj2ast_expr(tmp, &cause, arena); |
| 4993 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4994 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4995 | } else { |
| 4996 | cause = NULL; |
| 4997 | } |
| 4998 | *out = Raise(exc, cause, lineno, col_offset, arena); |
| 4999 | if (*out == NULL) goto failed; |
| 5000 | return 0; |
| 5001 | } |
| 5002 | isinstance = PyObject_IsInstance(obj, (PyObject*)Try_type); |
| 5003 | if (isinstance == -1) { |
| 5004 | return 1; |
| 5005 | } |
| 5006 | if (isinstance) { |
| 5007 | asdl_seq* body; |
| 5008 | asdl_seq* handlers; |
| 5009 | asdl_seq* orelse; |
| 5010 | asdl_seq* finalbody; |
| 5011 | |
| 5012 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 5013 | int res; |
| 5014 | Py_ssize_t len; |
| 5015 | Py_ssize_t i; |
| 5016 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 5017 | if (tmp == NULL) goto failed; |
| 5018 | if (!PyList_Check(tmp)) { |
| 5019 | PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5020 | goto failed; |
| 5021 | } |
| 5022 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5023 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5024 | if (body == NULL) goto failed; |
| 5025 | for (i = 0; i < len; i++) { |
| 5026 | stmt_ty value; |
| 5027 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5028 | if (res != 0) goto failed; |
| 5029 | asdl_seq_SET(body, i, value); |
| 5030 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5031 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5032 | } else { |
| 5033 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); |
| 5034 | return 1; |
| 5035 | } |
| 5036 | if (_PyObject_HasAttrId(obj, &PyId_handlers)) { |
| 5037 | int res; |
| 5038 | Py_ssize_t len; |
| 5039 | Py_ssize_t i; |
| 5040 | tmp = _PyObject_GetAttrId(obj, &PyId_handlers); |
| 5041 | if (tmp == NULL) goto failed; |
| 5042 | if (!PyList_Check(tmp)) { |
| 5043 | PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5044 | goto failed; |
| 5045 | } |
| 5046 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5047 | handlers = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5048 | if (handlers == NULL) goto failed; |
| 5049 | for (i = 0; i < len; i++) { |
| 5050 | excepthandler_ty value; |
| 5051 | res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5052 | if (res != 0) goto failed; |
| 5053 | asdl_seq_SET(handlers, i, value); |
| 5054 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5055 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5056 | } else { |
| 5057 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); |
| 5058 | return 1; |
| 5059 | } |
| 5060 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
| 5061 | int res; |
| 5062 | Py_ssize_t len; |
| 5063 | Py_ssize_t i; |
| 5064 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
| 5065 | if (tmp == NULL) goto failed; |
| 5066 | if (!PyList_Check(tmp)) { |
| 5067 | PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5068 | goto failed; |
| 5069 | } |
| 5070 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5071 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5072 | if (orelse == NULL) goto failed; |
| 5073 | for (i = 0; i < len; i++) { |
| 5074 | stmt_ty value; |
| 5075 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5076 | if (res != 0) goto failed; |
| 5077 | asdl_seq_SET(orelse, i, value); |
| 5078 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5079 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5080 | } else { |
| 5081 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); |
| 5082 | return 1; |
| 5083 | } |
| 5084 | if (_PyObject_HasAttrId(obj, &PyId_finalbody)) { |
| 5085 | int res; |
| 5086 | Py_ssize_t len; |
| 5087 | Py_ssize_t i; |
| 5088 | tmp = _PyObject_GetAttrId(obj, &PyId_finalbody); |
| 5089 | if (tmp == NULL) goto failed; |
| 5090 | if (!PyList_Check(tmp)) { |
| 5091 | PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5092 | goto failed; |
| 5093 | } |
| 5094 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5095 | finalbody = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5096 | if (finalbody == NULL) goto failed; |
| 5097 | for (i = 0; i < len; i++) { |
| 5098 | stmt_ty value; |
| 5099 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5100 | if (res != 0) goto failed; |
| 5101 | asdl_seq_SET(finalbody, i, value); |
| 5102 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5103 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5104 | } else { |
| 5105 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); |
| 5106 | return 1; |
| 5107 | } |
| 5108 | *out = Try(body, handlers, orelse, finalbody, lineno, col_offset, |
| 5109 | arena); |
| 5110 | if (*out == NULL) goto failed; |
| 5111 | return 0; |
| 5112 | } |
| 5113 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type); |
| 5114 | if (isinstance == -1) { |
| 5115 | return 1; |
| 5116 | } |
| 5117 | if (isinstance) { |
| 5118 | expr_ty test; |
| 5119 | expr_ty msg; |
| 5120 | |
| 5121 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
| 5122 | int res; |
| 5123 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
| 5124 | if (tmp == NULL) goto failed; |
| 5125 | res = obj2ast_expr(tmp, &test, arena); |
| 5126 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5127 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5128 | } else { |
| 5129 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 5130 | return 1; |
| 5131 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 5132 | if (exists_not_none(obj, &PyId_msg)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5133 | int res; |
| 5134 | tmp = _PyObject_GetAttrId(obj, &PyId_msg); |
| 5135 | if (tmp == NULL) goto failed; |
| 5136 | res = obj2ast_expr(tmp, &msg, arena); |
| 5137 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5138 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5139 | } else { |
| 5140 | msg = NULL; |
| 5141 | } |
| 5142 | *out = Assert(test, msg, lineno, col_offset, arena); |
| 5143 | if (*out == NULL) goto failed; |
| 5144 | return 0; |
| 5145 | } |
| 5146 | isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type); |
| 5147 | if (isinstance == -1) { |
| 5148 | return 1; |
| 5149 | } |
| 5150 | if (isinstance) { |
| 5151 | asdl_seq* names; |
| 5152 | |
| 5153 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
| 5154 | int res; |
| 5155 | Py_ssize_t len; |
| 5156 | Py_ssize_t i; |
| 5157 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
| 5158 | if (tmp == NULL) goto failed; |
| 5159 | if (!PyList_Check(tmp)) { |
| 5160 | PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5161 | goto failed; |
| 5162 | } |
| 5163 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5164 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5165 | if (names == NULL) goto failed; |
| 5166 | for (i = 0; i < len; i++) { |
| 5167 | alias_ty value; |
| 5168 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5169 | if (res != 0) goto failed; |
| 5170 | asdl_seq_SET(names, i, value); |
| 5171 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5172 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5173 | } else { |
| 5174 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 5175 | return 1; |
| 5176 | } |
| 5177 | *out = Import(names, lineno, col_offset, arena); |
| 5178 | if (*out == NULL) goto failed; |
| 5179 | return 0; |
| 5180 | } |
| 5181 | isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type); |
| 5182 | if (isinstance == -1) { |
| 5183 | return 1; |
| 5184 | } |
| 5185 | if (isinstance) { |
| 5186 | identifier module; |
| 5187 | asdl_seq* names; |
| 5188 | int level; |
| 5189 | |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 5190 | if (exists_not_none(obj, &PyId_module)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5191 | int res; |
| 5192 | tmp = _PyObject_GetAttrId(obj, &PyId_module); |
| 5193 | if (tmp == NULL) goto failed; |
| 5194 | res = obj2ast_identifier(tmp, &module, arena); |
| 5195 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5196 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5197 | } else { |
| 5198 | module = NULL; |
| 5199 | } |
| 5200 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
| 5201 | int res; |
| 5202 | Py_ssize_t len; |
| 5203 | Py_ssize_t i; |
| 5204 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
| 5205 | if (tmp == NULL) goto failed; |
| 5206 | if (!PyList_Check(tmp)) { |
| 5207 | PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5208 | goto failed; |
| 5209 | } |
| 5210 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5211 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5212 | if (names == NULL) goto failed; |
| 5213 | for (i = 0; i < len; i++) { |
| 5214 | alias_ty value; |
| 5215 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5216 | if (res != 0) goto failed; |
| 5217 | asdl_seq_SET(names, i, value); |
| 5218 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5219 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5220 | } else { |
| 5221 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 5222 | return 1; |
| 5223 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 5224 | if (exists_not_none(obj, &PyId_level)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5225 | int res; |
| 5226 | tmp = _PyObject_GetAttrId(obj, &PyId_level); |
| 5227 | if (tmp == NULL) goto failed; |
| 5228 | res = obj2ast_int(tmp, &level, arena); |
| 5229 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5230 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5231 | } else { |
| 5232 | level = 0; |
| 5233 | } |
| 5234 | *out = ImportFrom(module, names, level, lineno, col_offset, arena); |
| 5235 | if (*out == NULL) goto failed; |
| 5236 | return 0; |
| 5237 | } |
| 5238 | isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type); |
| 5239 | if (isinstance == -1) { |
| 5240 | return 1; |
| 5241 | } |
| 5242 | if (isinstance) { |
| 5243 | asdl_seq* names; |
| 5244 | |
| 5245 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
| 5246 | int res; |
| 5247 | Py_ssize_t len; |
| 5248 | Py_ssize_t i; |
| 5249 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
| 5250 | if (tmp == NULL) goto failed; |
| 5251 | if (!PyList_Check(tmp)) { |
| 5252 | PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5253 | goto failed; |
| 5254 | } |
| 5255 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5256 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5257 | if (names == NULL) goto failed; |
| 5258 | for (i = 0; i < len; i++) { |
| 5259 | identifier value; |
| 5260 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5261 | if (res != 0) goto failed; |
| 5262 | asdl_seq_SET(names, i, value); |
| 5263 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5264 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5265 | } else { |
| 5266 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 5267 | return 1; |
| 5268 | } |
| 5269 | *out = Global(names, lineno, col_offset, arena); |
| 5270 | if (*out == NULL) goto failed; |
| 5271 | return 0; |
| 5272 | } |
| 5273 | isinstance = PyObject_IsInstance(obj, (PyObject*)Nonlocal_type); |
| 5274 | if (isinstance == -1) { |
| 5275 | return 1; |
| 5276 | } |
| 5277 | if (isinstance) { |
| 5278 | asdl_seq* names; |
| 5279 | |
| 5280 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
| 5281 | int res; |
| 5282 | Py_ssize_t len; |
| 5283 | Py_ssize_t i; |
| 5284 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
| 5285 | if (tmp == NULL) goto failed; |
| 5286 | if (!PyList_Check(tmp)) { |
| 5287 | PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5288 | goto failed; |
| 5289 | } |
| 5290 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5291 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5292 | if (names == NULL) goto failed; |
| 5293 | for (i = 0; i < len; i++) { |
| 5294 | identifier value; |
| 5295 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5296 | if (res != 0) goto failed; |
| 5297 | asdl_seq_SET(names, i, value); |
| 5298 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5299 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5300 | } else { |
| 5301 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 5302 | return 1; |
| 5303 | } |
| 5304 | *out = Nonlocal(names, lineno, col_offset, arena); |
| 5305 | if (*out == NULL) goto failed; |
| 5306 | return 0; |
| 5307 | } |
| 5308 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type); |
| 5309 | if (isinstance == -1) { |
| 5310 | return 1; |
| 5311 | } |
| 5312 | if (isinstance) { |
| 5313 | expr_ty value; |
| 5314 | |
| 5315 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 5316 | int res; |
| 5317 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 5318 | if (tmp == NULL) goto failed; |
| 5319 | res = obj2ast_expr(tmp, &value, arena); |
| 5320 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5321 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5322 | } else { |
| 5323 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 5324 | return 1; |
| 5325 | } |
| 5326 | *out = Expr(value, lineno, col_offset, arena); |
| 5327 | if (*out == NULL) goto failed; |
| 5328 | return 0; |
| 5329 | } |
| 5330 | isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type); |
| 5331 | if (isinstance == -1) { |
| 5332 | return 1; |
| 5333 | } |
| 5334 | if (isinstance) { |
| 5335 | |
| 5336 | *out = Pass(lineno, col_offset, arena); |
| 5337 | if (*out == NULL) goto failed; |
| 5338 | return 0; |
| 5339 | } |
| 5340 | isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type); |
| 5341 | if (isinstance == -1) { |
| 5342 | return 1; |
| 5343 | } |
| 5344 | if (isinstance) { |
| 5345 | |
| 5346 | *out = Break(lineno, col_offset, arena); |
| 5347 | if (*out == NULL) goto failed; |
| 5348 | return 0; |
| 5349 | } |
| 5350 | isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type); |
| 5351 | if (isinstance == -1) { |
| 5352 | return 1; |
| 5353 | } |
| 5354 | if (isinstance) { |
| 5355 | |
| 5356 | *out = Continue(lineno, col_offset, arena); |
| 5357 | if (*out == NULL) goto failed; |
| 5358 | return 0; |
| 5359 | } |
| 5360 | |
| 5361 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
| 5362 | failed: |
| 5363 | Py_XDECREF(tmp); |
| 5364 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5365 | } |
| 5366 | |
| 5367 | int |
| 5368 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 5369 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5370 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5371 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5372 | PyObject *tmp = NULL; |
| 5373 | int lineno; |
| 5374 | int col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5375 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5376 | if (obj == Py_None) { |
| 5377 | *out = NULL; |
| 5378 | return 0; |
| 5379 | } |
| 5380 | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
| 5381 | int res; |
| 5382 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
| 5383 | if (tmp == NULL) goto failed; |
| 5384 | res = obj2ast_int(tmp, &lineno, arena); |
| 5385 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5386 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5387 | } else { |
| 5388 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5389 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5390 | } |
| 5391 | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
| 5392 | int res; |
| 5393 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
| 5394 | if (tmp == NULL) goto failed; |
| 5395 | res = obj2ast_int(tmp, &col_offset, arena); |
| 5396 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5397 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5398 | } else { |
| 5399 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 5400 | return 1; |
| 5401 | } |
| 5402 | isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type); |
| 5403 | if (isinstance == -1) { |
| 5404 | return 1; |
| 5405 | } |
| 5406 | if (isinstance) { |
| 5407 | boolop_ty op; |
| 5408 | asdl_seq* values; |
| 5409 | |
| 5410 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
| 5411 | int res; |
| 5412 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
| 5413 | if (tmp == NULL) goto failed; |
| 5414 | res = obj2ast_boolop(tmp, &op, arena); |
| 5415 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5416 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5417 | } else { |
| 5418 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 5419 | return 1; |
| 5420 | } |
| 5421 | if (_PyObject_HasAttrId(obj, &PyId_values)) { |
| 5422 | int res; |
| 5423 | Py_ssize_t len; |
| 5424 | Py_ssize_t i; |
| 5425 | tmp = _PyObject_GetAttrId(obj, &PyId_values); |
| 5426 | if (tmp == NULL) goto failed; |
| 5427 | if (!PyList_Check(tmp)) { |
| 5428 | PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5429 | goto failed; |
| 5430 | } |
| 5431 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5432 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5433 | if (values == NULL) goto failed; |
| 5434 | for (i = 0; i < len; i++) { |
| 5435 | expr_ty value; |
| 5436 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5437 | if (res != 0) goto failed; |
| 5438 | asdl_seq_SET(values, i, value); |
| 5439 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5440 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5441 | } else { |
| 5442 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 5443 | return 1; |
| 5444 | } |
| 5445 | *out = BoolOp(op, values, lineno, col_offset, arena); |
| 5446 | if (*out == NULL) goto failed; |
| 5447 | return 0; |
| 5448 | } |
| 5449 | isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type); |
| 5450 | if (isinstance == -1) { |
| 5451 | return 1; |
| 5452 | } |
| 5453 | if (isinstance) { |
| 5454 | expr_ty left; |
| 5455 | operator_ty op; |
| 5456 | expr_ty right; |
| 5457 | |
| 5458 | if (_PyObject_HasAttrId(obj, &PyId_left)) { |
| 5459 | int res; |
| 5460 | tmp = _PyObject_GetAttrId(obj, &PyId_left); |
| 5461 | if (tmp == NULL) goto failed; |
| 5462 | res = obj2ast_expr(tmp, &left, arena); |
| 5463 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5464 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5465 | } else { |
| 5466 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 5467 | return 1; |
| 5468 | } |
| 5469 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
| 5470 | int res; |
| 5471 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
| 5472 | if (tmp == NULL) goto failed; |
| 5473 | res = obj2ast_operator(tmp, &op, arena); |
| 5474 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5475 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5476 | } else { |
| 5477 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 5478 | return 1; |
| 5479 | } |
| 5480 | if (_PyObject_HasAttrId(obj, &PyId_right)) { |
| 5481 | int res; |
| 5482 | tmp = _PyObject_GetAttrId(obj, &PyId_right); |
| 5483 | if (tmp == NULL) goto failed; |
| 5484 | res = obj2ast_expr(tmp, &right, arena); |
| 5485 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5486 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5487 | } else { |
| 5488 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 5489 | return 1; |
| 5490 | } |
| 5491 | *out = BinOp(left, op, right, lineno, col_offset, arena); |
| 5492 | if (*out == NULL) goto failed; |
| 5493 | return 0; |
| 5494 | } |
| 5495 | isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type); |
| 5496 | if (isinstance == -1) { |
| 5497 | return 1; |
| 5498 | } |
| 5499 | if (isinstance) { |
| 5500 | unaryop_ty op; |
| 5501 | expr_ty operand; |
| 5502 | |
| 5503 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
| 5504 | int res; |
| 5505 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
| 5506 | if (tmp == NULL) goto failed; |
| 5507 | res = obj2ast_unaryop(tmp, &op, arena); |
| 5508 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5509 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5510 | } else { |
| 5511 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 5512 | return 1; |
| 5513 | } |
| 5514 | if (_PyObject_HasAttrId(obj, &PyId_operand)) { |
| 5515 | int res; |
| 5516 | tmp = _PyObject_GetAttrId(obj, &PyId_operand); |
| 5517 | if (tmp == NULL) goto failed; |
| 5518 | res = obj2ast_expr(tmp, &operand, arena); |
| 5519 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5520 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5521 | } else { |
| 5522 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 5523 | return 1; |
| 5524 | } |
| 5525 | *out = UnaryOp(op, operand, lineno, col_offset, arena); |
| 5526 | if (*out == NULL) goto failed; |
| 5527 | return 0; |
| 5528 | } |
| 5529 | isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type); |
| 5530 | if (isinstance == -1) { |
| 5531 | return 1; |
| 5532 | } |
| 5533 | if (isinstance) { |
| 5534 | arguments_ty args; |
| 5535 | expr_ty body; |
| 5536 | |
| 5537 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
| 5538 | int res; |
| 5539 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
| 5540 | if (tmp == NULL) goto failed; |
| 5541 | res = obj2ast_arguments(tmp, &args, arena); |
| 5542 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5543 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5544 | } else { |
| 5545 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 5546 | return 1; |
| 5547 | } |
| 5548 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 5549 | int res; |
| 5550 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 5551 | if (tmp == NULL) goto failed; |
| 5552 | res = obj2ast_expr(tmp, &body, arena); |
| 5553 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5554 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5555 | } else { |
| 5556 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 5557 | return 1; |
| 5558 | } |
| 5559 | *out = Lambda(args, body, lineno, col_offset, arena); |
| 5560 | if (*out == NULL) goto failed; |
| 5561 | return 0; |
| 5562 | } |
| 5563 | isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type); |
| 5564 | if (isinstance == -1) { |
| 5565 | return 1; |
| 5566 | } |
| 5567 | if (isinstance) { |
| 5568 | expr_ty test; |
| 5569 | expr_ty body; |
| 5570 | expr_ty orelse; |
| 5571 | |
| 5572 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
| 5573 | int res; |
| 5574 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
| 5575 | if (tmp == NULL) goto failed; |
| 5576 | res = obj2ast_expr(tmp, &test, arena); |
| 5577 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5578 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5579 | } else { |
| 5580 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 5581 | return 1; |
| 5582 | } |
| 5583 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 5584 | int res; |
| 5585 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 5586 | if (tmp == NULL) goto failed; |
| 5587 | res = obj2ast_expr(tmp, &body, arena); |
| 5588 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5589 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5590 | } else { |
| 5591 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 5592 | return 1; |
| 5593 | } |
| 5594 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
| 5595 | int res; |
| 5596 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
| 5597 | if (tmp == NULL) goto failed; |
| 5598 | res = obj2ast_expr(tmp, &orelse, arena); |
| 5599 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5600 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5601 | } else { |
| 5602 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 5603 | return 1; |
| 5604 | } |
| 5605 | *out = IfExp(test, body, orelse, lineno, col_offset, arena); |
| 5606 | if (*out == NULL) goto failed; |
| 5607 | return 0; |
| 5608 | } |
| 5609 | isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type); |
| 5610 | if (isinstance == -1) { |
| 5611 | return 1; |
| 5612 | } |
| 5613 | if (isinstance) { |
| 5614 | asdl_seq* keys; |
| 5615 | asdl_seq* values; |
| 5616 | |
| 5617 | if (_PyObject_HasAttrId(obj, &PyId_keys)) { |
| 5618 | int res; |
| 5619 | Py_ssize_t len; |
| 5620 | Py_ssize_t i; |
| 5621 | tmp = _PyObject_GetAttrId(obj, &PyId_keys); |
| 5622 | if (tmp == NULL) goto failed; |
| 5623 | if (!PyList_Check(tmp)) { |
| 5624 | PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5625 | goto failed; |
| 5626 | } |
| 5627 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5628 | keys = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5629 | if (keys == NULL) goto failed; |
| 5630 | for (i = 0; i < len; i++) { |
| 5631 | expr_ty value; |
| 5632 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5633 | if (res != 0) goto failed; |
| 5634 | asdl_seq_SET(keys, i, value); |
| 5635 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5636 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5637 | } else { |
| 5638 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 5639 | return 1; |
| 5640 | } |
| 5641 | if (_PyObject_HasAttrId(obj, &PyId_values)) { |
| 5642 | int res; |
| 5643 | Py_ssize_t len; |
| 5644 | Py_ssize_t i; |
| 5645 | tmp = _PyObject_GetAttrId(obj, &PyId_values); |
| 5646 | if (tmp == NULL) goto failed; |
| 5647 | if (!PyList_Check(tmp)) { |
| 5648 | PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5649 | goto failed; |
| 5650 | } |
| 5651 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5652 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5653 | if (values == NULL) goto failed; |
| 5654 | for (i = 0; i < len; i++) { |
| 5655 | expr_ty value; |
| 5656 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5657 | if (res != 0) goto failed; |
| 5658 | asdl_seq_SET(values, i, value); |
| 5659 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5660 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5661 | } else { |
| 5662 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 5663 | return 1; |
| 5664 | } |
| 5665 | *out = Dict(keys, values, lineno, col_offset, arena); |
| 5666 | if (*out == NULL) goto failed; |
| 5667 | return 0; |
| 5668 | } |
| 5669 | isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type); |
| 5670 | if (isinstance == -1) { |
| 5671 | return 1; |
| 5672 | } |
| 5673 | if (isinstance) { |
| 5674 | asdl_seq* elts; |
| 5675 | |
| 5676 | if (_PyObject_HasAttrId(obj, &PyId_elts)) { |
| 5677 | int res; |
| 5678 | Py_ssize_t len; |
| 5679 | Py_ssize_t i; |
| 5680 | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
| 5681 | if (tmp == NULL) goto failed; |
| 5682 | if (!PyList_Check(tmp)) { |
| 5683 | PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5684 | goto failed; |
| 5685 | } |
| 5686 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5687 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5688 | if (elts == NULL) goto failed; |
| 5689 | for (i = 0; i < len; i++) { |
| 5690 | expr_ty value; |
| 5691 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5692 | if (res != 0) goto failed; |
| 5693 | asdl_seq_SET(elts, i, value); |
| 5694 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5695 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5696 | } else { |
| 5697 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 5698 | return 1; |
| 5699 | } |
| 5700 | *out = Set(elts, lineno, col_offset, arena); |
| 5701 | if (*out == NULL) goto failed; |
| 5702 | return 0; |
| 5703 | } |
| 5704 | isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type); |
| 5705 | if (isinstance == -1) { |
| 5706 | return 1; |
| 5707 | } |
| 5708 | if (isinstance) { |
| 5709 | expr_ty elt; |
| 5710 | asdl_seq* generators; |
| 5711 | |
| 5712 | if (_PyObject_HasAttrId(obj, &PyId_elt)) { |
| 5713 | int res; |
| 5714 | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
| 5715 | if (tmp == NULL) goto failed; |
| 5716 | res = obj2ast_expr(tmp, &elt, arena); |
| 5717 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5718 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5719 | } else { |
| 5720 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 5721 | return 1; |
| 5722 | } |
| 5723 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
| 5724 | int res; |
| 5725 | Py_ssize_t len; |
| 5726 | Py_ssize_t i; |
| 5727 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
| 5728 | if (tmp == NULL) goto failed; |
| 5729 | if (!PyList_Check(tmp)) { |
| 5730 | PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5731 | goto failed; |
| 5732 | } |
| 5733 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5734 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5735 | if (generators == NULL) goto failed; |
| 5736 | for (i = 0; i < len; i++) { |
| 5737 | comprehension_ty value; |
| 5738 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5739 | if (res != 0) goto failed; |
| 5740 | asdl_seq_SET(generators, i, value); |
| 5741 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5742 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5743 | } else { |
| 5744 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 5745 | return 1; |
| 5746 | } |
| 5747 | *out = ListComp(elt, generators, lineno, col_offset, arena); |
| 5748 | if (*out == NULL) goto failed; |
| 5749 | return 0; |
| 5750 | } |
| 5751 | isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type); |
| 5752 | if (isinstance == -1) { |
| 5753 | return 1; |
| 5754 | } |
| 5755 | if (isinstance) { |
| 5756 | expr_ty elt; |
| 5757 | asdl_seq* generators; |
| 5758 | |
| 5759 | if (_PyObject_HasAttrId(obj, &PyId_elt)) { |
| 5760 | int res; |
| 5761 | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
| 5762 | if (tmp == NULL) goto failed; |
| 5763 | res = obj2ast_expr(tmp, &elt, arena); |
| 5764 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5765 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5766 | } else { |
| 5767 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 5768 | return 1; |
| 5769 | } |
| 5770 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
| 5771 | int res; |
| 5772 | Py_ssize_t len; |
| 5773 | Py_ssize_t i; |
| 5774 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
| 5775 | if (tmp == NULL) goto failed; |
| 5776 | if (!PyList_Check(tmp)) { |
| 5777 | PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5778 | goto failed; |
| 5779 | } |
| 5780 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5781 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5782 | if (generators == NULL) goto failed; |
| 5783 | for (i = 0; i < len; i++) { |
| 5784 | comprehension_ty value; |
| 5785 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5786 | if (res != 0) goto failed; |
| 5787 | asdl_seq_SET(generators, i, value); |
| 5788 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5789 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5790 | } else { |
| 5791 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 5792 | return 1; |
| 5793 | } |
| 5794 | *out = SetComp(elt, generators, lineno, col_offset, arena); |
| 5795 | if (*out == NULL) goto failed; |
| 5796 | return 0; |
| 5797 | } |
| 5798 | isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type); |
| 5799 | if (isinstance == -1) { |
| 5800 | return 1; |
| 5801 | } |
| 5802 | if (isinstance) { |
| 5803 | expr_ty key; |
| 5804 | expr_ty value; |
| 5805 | asdl_seq* generators; |
| 5806 | |
| 5807 | if (_PyObject_HasAttrId(obj, &PyId_key)) { |
| 5808 | int res; |
| 5809 | tmp = _PyObject_GetAttrId(obj, &PyId_key); |
| 5810 | if (tmp == NULL) goto failed; |
| 5811 | res = obj2ast_expr(tmp, &key, arena); |
| 5812 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5813 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5814 | } else { |
| 5815 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 5816 | return 1; |
| 5817 | } |
| 5818 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 5819 | int res; |
| 5820 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 5821 | if (tmp == NULL) goto failed; |
| 5822 | res = obj2ast_expr(tmp, &value, arena); |
| 5823 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5824 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5825 | } else { |
| 5826 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 5827 | return 1; |
| 5828 | } |
| 5829 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
| 5830 | int res; |
| 5831 | Py_ssize_t len; |
| 5832 | Py_ssize_t i; |
| 5833 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
| 5834 | if (tmp == NULL) goto failed; |
| 5835 | if (!PyList_Check(tmp)) { |
| 5836 | PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5837 | goto failed; |
| 5838 | } |
| 5839 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5840 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5841 | if (generators == NULL) goto failed; |
| 5842 | for (i = 0; i < len; i++) { |
| 5843 | comprehension_ty value; |
| 5844 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5845 | if (res != 0) goto failed; |
| 5846 | asdl_seq_SET(generators, i, value); |
| 5847 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5848 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5849 | } else { |
| 5850 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 5851 | return 1; |
| 5852 | } |
| 5853 | *out = DictComp(key, value, generators, lineno, col_offset, arena); |
| 5854 | if (*out == NULL) goto failed; |
| 5855 | return 0; |
| 5856 | } |
| 5857 | isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type); |
| 5858 | if (isinstance == -1) { |
| 5859 | return 1; |
| 5860 | } |
| 5861 | if (isinstance) { |
| 5862 | expr_ty elt; |
| 5863 | asdl_seq* generators; |
| 5864 | |
| 5865 | if (_PyObject_HasAttrId(obj, &PyId_elt)) { |
| 5866 | int res; |
| 5867 | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
| 5868 | if (tmp == NULL) goto failed; |
| 5869 | res = obj2ast_expr(tmp, &elt, arena); |
| 5870 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5871 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5872 | } else { |
| 5873 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 5874 | return 1; |
| 5875 | } |
| 5876 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
| 5877 | int res; |
| 5878 | Py_ssize_t len; |
| 5879 | Py_ssize_t i; |
| 5880 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
| 5881 | if (tmp == NULL) goto failed; |
| 5882 | if (!PyList_Check(tmp)) { |
| 5883 | PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5884 | goto failed; |
| 5885 | } |
| 5886 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5887 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5888 | if (generators == NULL) goto failed; |
| 5889 | for (i = 0; i < len; i++) { |
| 5890 | comprehension_ty value; |
| 5891 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5892 | if (res != 0) goto failed; |
| 5893 | asdl_seq_SET(generators, i, value); |
| 5894 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5895 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5896 | } else { |
| 5897 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 5898 | return 1; |
| 5899 | } |
| 5900 | *out = GeneratorExp(elt, generators, lineno, col_offset, arena); |
| 5901 | if (*out == NULL) goto failed; |
| 5902 | return 0; |
| 5903 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5904 | isinstance = PyObject_IsInstance(obj, (PyObject*)Await_type); |
| 5905 | if (isinstance == -1) { |
| 5906 | return 1; |
| 5907 | } |
| 5908 | if (isinstance) { |
| 5909 | expr_ty value; |
| 5910 | |
| 5911 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 5912 | int res; |
| 5913 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 5914 | if (tmp == NULL) goto failed; |
| 5915 | res = obj2ast_expr(tmp, &value, arena); |
| 5916 | if (res != 0) goto failed; |
| 5917 | Py_CLEAR(tmp); |
| 5918 | } else { |
| 5919 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await"); |
| 5920 | return 1; |
| 5921 | } |
| 5922 | *out = Await(value, lineno, col_offset, arena); |
| 5923 | if (*out == NULL) goto failed; |
| 5924 | return 0; |
| 5925 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5926 | isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); |
| 5927 | if (isinstance == -1) { |
| 5928 | return 1; |
| 5929 | } |
| 5930 | if (isinstance) { |
| 5931 | expr_ty value; |
| 5932 | |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 5933 | if (exists_not_none(obj, &PyId_value)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5934 | int res; |
| 5935 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 5936 | if (tmp == NULL) goto failed; |
| 5937 | res = obj2ast_expr(tmp, &value, 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 | value = NULL; |
| 5942 | } |
| 5943 | *out = Yield(value, lineno, col_offset, arena); |
| 5944 | if (*out == NULL) goto failed; |
| 5945 | return 0; |
| 5946 | } |
| 5947 | isinstance = PyObject_IsInstance(obj, (PyObject*)YieldFrom_type); |
| 5948 | if (isinstance == -1) { |
| 5949 | return 1; |
| 5950 | } |
| 5951 | if (isinstance) { |
| 5952 | expr_ty value; |
| 5953 | |
| 5954 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 5955 | int res; |
| 5956 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 5957 | if (tmp == NULL) goto failed; |
| 5958 | res = obj2ast_expr(tmp, &value, arena); |
| 5959 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5960 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5961 | } else { |
| 5962 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom"); |
| 5963 | return 1; |
| 5964 | } |
| 5965 | *out = YieldFrom(value, lineno, col_offset, arena); |
| 5966 | if (*out == NULL) goto failed; |
| 5967 | return 0; |
| 5968 | } |
| 5969 | isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); |
| 5970 | if (isinstance == -1) { |
| 5971 | return 1; |
| 5972 | } |
| 5973 | if (isinstance) { |
| 5974 | expr_ty left; |
| 5975 | asdl_int_seq* ops; |
| 5976 | asdl_seq* comparators; |
| 5977 | |
| 5978 | if (_PyObject_HasAttrId(obj, &PyId_left)) { |
| 5979 | int res; |
| 5980 | tmp = _PyObject_GetAttrId(obj, &PyId_left); |
| 5981 | if (tmp == NULL) goto failed; |
| 5982 | res = obj2ast_expr(tmp, &left, arena); |
| 5983 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5984 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5985 | } else { |
| 5986 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 5987 | return 1; |
| 5988 | } |
| 5989 | if (_PyObject_HasAttrId(obj, &PyId_ops)) { |
| 5990 | int res; |
| 5991 | Py_ssize_t len; |
| 5992 | Py_ssize_t i; |
| 5993 | tmp = _PyObject_GetAttrId(obj, &PyId_ops); |
| 5994 | if (tmp == NULL) goto failed; |
| 5995 | if (!PyList_Check(tmp)) { |
| 5996 | PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5997 | goto failed; |
| 5998 | } |
| 5999 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6000 | ops = _Py_asdl_int_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6001 | if (ops == NULL) goto failed; |
| 6002 | for (i = 0; i < len; i++) { |
| 6003 | cmpop_ty value; |
| 6004 | res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6005 | if (res != 0) goto failed; |
| 6006 | asdl_seq_SET(ops, i, value); |
| 6007 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6008 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6009 | } else { |
| 6010 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 6011 | return 1; |
| 6012 | } |
| 6013 | if (_PyObject_HasAttrId(obj, &PyId_comparators)) { |
| 6014 | int res; |
| 6015 | Py_ssize_t len; |
| 6016 | Py_ssize_t i; |
| 6017 | tmp = _PyObject_GetAttrId(obj, &PyId_comparators); |
| 6018 | if (tmp == NULL) goto failed; |
| 6019 | if (!PyList_Check(tmp)) { |
| 6020 | PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6021 | goto failed; |
| 6022 | } |
| 6023 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6024 | comparators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6025 | if (comparators == NULL) goto failed; |
| 6026 | for (i = 0; i < len; i++) { |
| 6027 | expr_ty value; |
| 6028 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6029 | if (res != 0) goto failed; |
| 6030 | asdl_seq_SET(comparators, i, value); |
| 6031 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6032 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6033 | } else { |
| 6034 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 6035 | return 1; |
| 6036 | } |
| 6037 | *out = Compare(left, ops, comparators, lineno, col_offset, arena); |
| 6038 | if (*out == NULL) goto failed; |
| 6039 | return 0; |
| 6040 | } |
| 6041 | isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type); |
| 6042 | if (isinstance == -1) { |
| 6043 | return 1; |
| 6044 | } |
| 6045 | if (isinstance) { |
| 6046 | expr_ty func; |
| 6047 | asdl_seq* args; |
| 6048 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6049 | |
| 6050 | if (_PyObject_HasAttrId(obj, &PyId_func)) { |
| 6051 | int res; |
| 6052 | tmp = _PyObject_GetAttrId(obj, &PyId_func); |
| 6053 | if (tmp == NULL) goto failed; |
| 6054 | res = obj2ast_expr(tmp, &func, arena); |
| 6055 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6056 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6057 | } else { |
| 6058 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 6059 | return 1; |
| 6060 | } |
| 6061 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
| 6062 | int res; |
| 6063 | Py_ssize_t len; |
| 6064 | Py_ssize_t i; |
| 6065 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
| 6066 | if (tmp == NULL) goto failed; |
| 6067 | if (!PyList_Check(tmp)) { |
| 6068 | PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6069 | goto failed; |
| 6070 | } |
| 6071 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6072 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6073 | if (args == NULL) goto failed; |
| 6074 | for (i = 0; i < len; i++) { |
| 6075 | expr_ty value; |
| 6076 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6077 | if (res != 0) goto failed; |
| 6078 | asdl_seq_SET(args, i, value); |
| 6079 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6080 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6081 | } else { |
| 6082 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 6083 | return 1; |
| 6084 | } |
| 6085 | if (_PyObject_HasAttrId(obj, &PyId_keywords)) { |
| 6086 | int res; |
| 6087 | Py_ssize_t len; |
| 6088 | Py_ssize_t i; |
| 6089 | tmp = _PyObject_GetAttrId(obj, &PyId_keywords); |
| 6090 | if (tmp == NULL) goto failed; |
| 6091 | if (!PyList_Check(tmp)) { |
| 6092 | PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6093 | goto failed; |
| 6094 | } |
| 6095 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6096 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6097 | if (keywords == NULL) goto failed; |
| 6098 | for (i = 0; i < len; i++) { |
| 6099 | keyword_ty value; |
| 6100 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6101 | if (res != 0) goto failed; |
| 6102 | asdl_seq_SET(keywords, i, value); |
| 6103 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6104 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6105 | } else { |
| 6106 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 6107 | return 1; |
| 6108 | } |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 6109 | *out = Call(func, args, keywords, lineno, col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6110 | if (*out == NULL) goto failed; |
| 6111 | return 0; |
| 6112 | } |
| 6113 | isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type); |
| 6114 | if (isinstance == -1) { |
| 6115 | return 1; |
| 6116 | } |
| 6117 | if (isinstance) { |
| 6118 | object n; |
| 6119 | |
| 6120 | if (_PyObject_HasAttrId(obj, &PyId_n)) { |
| 6121 | int res; |
| 6122 | tmp = _PyObject_GetAttrId(obj, &PyId_n); |
| 6123 | if (tmp == NULL) goto failed; |
| 6124 | res = obj2ast_object(tmp, &n, arena); |
| 6125 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6126 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6127 | } else { |
| 6128 | PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num"); |
| 6129 | return 1; |
| 6130 | } |
| 6131 | *out = Num(n, lineno, col_offset, arena); |
| 6132 | if (*out == NULL) goto failed; |
| 6133 | return 0; |
| 6134 | } |
| 6135 | isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type); |
| 6136 | if (isinstance == -1) { |
| 6137 | return 1; |
| 6138 | } |
| 6139 | if (isinstance) { |
| 6140 | string s; |
| 6141 | |
| 6142 | if (_PyObject_HasAttrId(obj, &PyId_s)) { |
| 6143 | int res; |
| 6144 | tmp = _PyObject_GetAttrId(obj, &PyId_s); |
| 6145 | if (tmp == NULL) goto failed; |
| 6146 | res = obj2ast_string(tmp, &s, arena); |
| 6147 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6148 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6149 | } else { |
| 6150 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str"); |
| 6151 | return 1; |
| 6152 | } |
| 6153 | *out = Str(s, lineno, col_offset, arena); |
| 6154 | if (*out == NULL) goto failed; |
| 6155 | return 0; |
| 6156 | } |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6157 | isinstance = PyObject_IsInstance(obj, (PyObject*)FormattedValue_type); |
| 6158 | if (isinstance == -1) { |
| 6159 | return 1; |
| 6160 | } |
| 6161 | if (isinstance) { |
| 6162 | expr_ty value; |
| 6163 | int conversion; |
| 6164 | expr_ty format_spec; |
| 6165 | |
| 6166 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 6167 | int res; |
| 6168 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 6169 | if (tmp == NULL) goto failed; |
| 6170 | res = obj2ast_expr(tmp, &value, arena); |
| 6171 | if (res != 0) goto failed; |
| 6172 | Py_CLEAR(tmp); |
| 6173 | } else { |
| 6174 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue"); |
| 6175 | return 1; |
| 6176 | } |
| 6177 | if (exists_not_none(obj, &PyId_conversion)) { |
| 6178 | int res; |
| 6179 | tmp = _PyObject_GetAttrId(obj, &PyId_conversion); |
| 6180 | if (tmp == NULL) goto failed; |
| 6181 | res = obj2ast_int(tmp, &conversion, arena); |
| 6182 | if (res != 0) goto failed; |
| 6183 | Py_CLEAR(tmp); |
| 6184 | } else { |
| 6185 | conversion = 0; |
| 6186 | } |
| 6187 | if (exists_not_none(obj, &PyId_format_spec)) { |
| 6188 | int res; |
| 6189 | tmp = _PyObject_GetAttrId(obj, &PyId_format_spec); |
| 6190 | if (tmp == NULL) goto failed; |
| 6191 | res = obj2ast_expr(tmp, &format_spec, arena); |
| 6192 | if (res != 0) goto failed; |
| 6193 | Py_CLEAR(tmp); |
| 6194 | } else { |
| 6195 | format_spec = NULL; |
| 6196 | } |
| 6197 | *out = FormattedValue(value, conversion, format_spec, lineno, |
| 6198 | col_offset, arena); |
| 6199 | if (*out == NULL) goto failed; |
| 6200 | return 0; |
| 6201 | } |
| 6202 | isinstance = PyObject_IsInstance(obj, (PyObject*)JoinedStr_type); |
| 6203 | if (isinstance == -1) { |
| 6204 | return 1; |
| 6205 | } |
| 6206 | if (isinstance) { |
| 6207 | asdl_seq* values; |
| 6208 | |
| 6209 | if (_PyObject_HasAttrId(obj, &PyId_values)) { |
| 6210 | int res; |
| 6211 | Py_ssize_t len; |
| 6212 | Py_ssize_t i; |
| 6213 | tmp = _PyObject_GetAttrId(obj, &PyId_values); |
| 6214 | if (tmp == NULL) goto failed; |
| 6215 | if (!PyList_Check(tmp)) { |
| 6216 | PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6217 | goto failed; |
| 6218 | } |
| 6219 | len = PyList_GET_SIZE(tmp); |
| 6220 | values = _Py_asdl_seq_new(len, arena); |
| 6221 | if (values == NULL) goto failed; |
| 6222 | for (i = 0; i < len; i++) { |
| 6223 | expr_ty value; |
| 6224 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6225 | if (res != 0) goto failed; |
| 6226 | asdl_seq_SET(values, i, value); |
| 6227 | } |
| 6228 | Py_CLEAR(tmp); |
| 6229 | } else { |
| 6230 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr"); |
| 6231 | return 1; |
| 6232 | } |
| 6233 | *out = JoinedStr(values, lineno, col_offset, arena); |
| 6234 | if (*out == NULL) goto failed; |
| 6235 | return 0; |
| 6236 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6237 | isinstance = PyObject_IsInstance(obj, (PyObject*)Bytes_type); |
| 6238 | if (isinstance == -1) { |
| 6239 | return 1; |
| 6240 | } |
| 6241 | if (isinstance) { |
| 6242 | bytes s; |
| 6243 | |
| 6244 | if (_PyObject_HasAttrId(obj, &PyId_s)) { |
| 6245 | int res; |
| 6246 | tmp = _PyObject_GetAttrId(obj, &PyId_s); |
| 6247 | if (tmp == NULL) goto failed; |
| 6248 | res = obj2ast_bytes(tmp, &s, arena); |
| 6249 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6250 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6251 | } else { |
| 6252 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Bytes"); |
| 6253 | return 1; |
| 6254 | } |
| 6255 | *out = Bytes(s, lineno, col_offset, arena); |
| 6256 | if (*out == NULL) goto failed; |
| 6257 | return 0; |
| 6258 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6259 | isinstance = PyObject_IsInstance(obj, (PyObject*)NameConstant_type); |
| 6260 | if (isinstance == -1) { |
| 6261 | return 1; |
| 6262 | } |
| 6263 | if (isinstance) { |
| 6264 | singleton value; |
| 6265 | |
| 6266 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 6267 | int res; |
| 6268 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 6269 | if (tmp == NULL) goto failed; |
| 6270 | res = obj2ast_singleton(tmp, &value, arena); |
| 6271 | if (res != 0) goto failed; |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 6272 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6273 | } else { |
| 6274 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NameConstant"); |
| 6275 | return 1; |
| 6276 | } |
| 6277 | *out = NameConstant(value, lineno, col_offset, arena); |
| 6278 | if (*out == NULL) goto failed; |
| 6279 | return 0; |
| 6280 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6281 | isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type); |
| 6282 | if (isinstance == -1) { |
| 6283 | return 1; |
| 6284 | } |
| 6285 | if (isinstance) { |
| 6286 | |
| 6287 | *out = Ellipsis(lineno, col_offset, arena); |
| 6288 | if (*out == NULL) goto failed; |
| 6289 | return 0; |
| 6290 | } |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 6291 | isinstance = PyObject_IsInstance(obj, (PyObject*)Constant_type); |
| 6292 | if (isinstance == -1) { |
| 6293 | return 1; |
| 6294 | } |
| 6295 | if (isinstance) { |
| 6296 | constant value; |
| 6297 | |
| 6298 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 6299 | int res; |
| 6300 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 6301 | if (tmp == NULL) goto failed; |
| 6302 | res = obj2ast_constant(tmp, &value, arena); |
| 6303 | if (res != 0) goto failed; |
| 6304 | Py_CLEAR(tmp); |
| 6305 | } else { |
| 6306 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant"); |
| 6307 | return 1; |
| 6308 | } |
| 6309 | *out = Constant(value, lineno, col_offset, arena); |
| 6310 | if (*out == NULL) goto failed; |
| 6311 | return 0; |
| 6312 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6313 | isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type); |
| 6314 | if (isinstance == -1) { |
| 6315 | return 1; |
| 6316 | } |
| 6317 | if (isinstance) { |
| 6318 | expr_ty value; |
| 6319 | identifier attr; |
| 6320 | expr_context_ty ctx; |
| 6321 | |
| 6322 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 6323 | int res; |
| 6324 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 6325 | if (tmp == NULL) goto failed; |
| 6326 | res = obj2ast_expr(tmp, &value, arena); |
| 6327 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6328 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6329 | } else { |
| 6330 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 6331 | return 1; |
| 6332 | } |
| 6333 | if (_PyObject_HasAttrId(obj, &PyId_attr)) { |
| 6334 | int res; |
| 6335 | tmp = _PyObject_GetAttrId(obj, &PyId_attr); |
| 6336 | if (tmp == NULL) goto failed; |
| 6337 | res = obj2ast_identifier(tmp, &attr, arena); |
| 6338 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6339 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6340 | } else { |
| 6341 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 6342 | return 1; |
| 6343 | } |
| 6344 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
| 6345 | int res; |
| 6346 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
| 6347 | if (tmp == NULL) goto failed; |
| 6348 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 6349 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6350 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6351 | } else { |
| 6352 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 6353 | return 1; |
| 6354 | } |
| 6355 | *out = Attribute(value, attr, ctx, lineno, col_offset, arena); |
| 6356 | if (*out == NULL) goto failed; |
| 6357 | return 0; |
| 6358 | } |
| 6359 | isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type); |
| 6360 | if (isinstance == -1) { |
| 6361 | return 1; |
| 6362 | } |
| 6363 | if (isinstance) { |
| 6364 | expr_ty value; |
| 6365 | slice_ty slice; |
| 6366 | expr_context_ty ctx; |
| 6367 | |
| 6368 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 6369 | int res; |
| 6370 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 6371 | if (tmp == NULL) goto failed; |
| 6372 | res = obj2ast_expr(tmp, &value, arena); |
| 6373 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6374 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6375 | } else { |
| 6376 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 6377 | return 1; |
| 6378 | } |
| 6379 | if (_PyObject_HasAttrId(obj, &PyId_slice)) { |
| 6380 | int res; |
| 6381 | tmp = _PyObject_GetAttrId(obj, &PyId_slice); |
| 6382 | if (tmp == NULL) goto failed; |
| 6383 | res = obj2ast_slice(tmp, &slice, arena); |
| 6384 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6385 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6386 | } else { |
| 6387 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 6388 | return 1; |
| 6389 | } |
| 6390 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
| 6391 | int res; |
| 6392 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
| 6393 | if (tmp == NULL) goto failed; |
| 6394 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 6395 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6396 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6397 | } else { |
| 6398 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 6399 | return 1; |
| 6400 | } |
| 6401 | *out = Subscript(value, slice, ctx, lineno, col_offset, arena); |
| 6402 | if (*out == NULL) goto failed; |
| 6403 | return 0; |
| 6404 | } |
| 6405 | isinstance = PyObject_IsInstance(obj, (PyObject*)Starred_type); |
| 6406 | if (isinstance == -1) { |
| 6407 | return 1; |
| 6408 | } |
| 6409 | if (isinstance) { |
| 6410 | expr_ty value; |
| 6411 | expr_context_ty ctx; |
| 6412 | |
| 6413 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 6414 | int res; |
| 6415 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 6416 | if (tmp == NULL) goto failed; |
| 6417 | res = obj2ast_expr(tmp, &value, arena); |
| 6418 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6419 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6420 | } else { |
| 6421 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 6422 | return 1; |
| 6423 | } |
| 6424 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
| 6425 | int res; |
| 6426 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
| 6427 | if (tmp == NULL) goto failed; |
| 6428 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 6429 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6430 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6431 | } else { |
| 6432 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 6433 | return 1; |
| 6434 | } |
| 6435 | *out = Starred(value, ctx, lineno, col_offset, arena); |
| 6436 | if (*out == NULL) goto failed; |
| 6437 | return 0; |
| 6438 | } |
| 6439 | isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type); |
| 6440 | if (isinstance == -1) { |
| 6441 | return 1; |
| 6442 | } |
| 6443 | if (isinstance) { |
| 6444 | identifier id; |
| 6445 | expr_context_ty ctx; |
| 6446 | |
| 6447 | if (_PyObject_HasAttrId(obj, &PyId_id)) { |
| 6448 | int res; |
| 6449 | tmp = _PyObject_GetAttrId(obj, &PyId_id); |
| 6450 | if (tmp == NULL) goto failed; |
| 6451 | res = obj2ast_identifier(tmp, &id, arena); |
| 6452 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6453 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6454 | } else { |
| 6455 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 6456 | return 1; |
| 6457 | } |
| 6458 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
| 6459 | int res; |
| 6460 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
| 6461 | if (tmp == NULL) goto failed; |
| 6462 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 6463 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6464 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6465 | } else { |
| 6466 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 6467 | return 1; |
| 6468 | } |
| 6469 | *out = Name(id, ctx, lineno, col_offset, arena); |
| 6470 | if (*out == NULL) goto failed; |
| 6471 | return 0; |
| 6472 | } |
| 6473 | isinstance = PyObject_IsInstance(obj, (PyObject*)List_type); |
| 6474 | if (isinstance == -1) { |
| 6475 | return 1; |
| 6476 | } |
| 6477 | if (isinstance) { |
| 6478 | asdl_seq* elts; |
| 6479 | expr_context_ty ctx; |
| 6480 | |
| 6481 | if (_PyObject_HasAttrId(obj, &PyId_elts)) { |
| 6482 | int res; |
| 6483 | Py_ssize_t len; |
| 6484 | Py_ssize_t i; |
| 6485 | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
| 6486 | if (tmp == NULL) goto failed; |
| 6487 | if (!PyList_Check(tmp)) { |
| 6488 | PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6489 | goto failed; |
| 6490 | } |
| 6491 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6492 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6493 | if (elts == NULL) goto failed; |
| 6494 | for (i = 0; i < len; i++) { |
| 6495 | expr_ty value; |
| 6496 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6497 | if (res != 0) goto failed; |
| 6498 | asdl_seq_SET(elts, i, value); |
| 6499 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6500 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6501 | } else { |
| 6502 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 6503 | return 1; |
| 6504 | } |
| 6505 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
| 6506 | int res; |
| 6507 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
| 6508 | if (tmp == NULL) goto failed; |
| 6509 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 6510 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6511 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6512 | } else { |
| 6513 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 6514 | return 1; |
| 6515 | } |
| 6516 | *out = List(elts, ctx, lineno, col_offset, arena); |
| 6517 | if (*out == NULL) goto failed; |
| 6518 | return 0; |
| 6519 | } |
| 6520 | isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type); |
| 6521 | if (isinstance == -1) { |
| 6522 | return 1; |
| 6523 | } |
| 6524 | if (isinstance) { |
| 6525 | asdl_seq* elts; |
| 6526 | expr_context_ty ctx; |
| 6527 | |
| 6528 | if (_PyObject_HasAttrId(obj, &PyId_elts)) { |
| 6529 | int res; |
| 6530 | Py_ssize_t len; |
| 6531 | Py_ssize_t i; |
| 6532 | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
| 6533 | if (tmp == NULL) goto failed; |
| 6534 | if (!PyList_Check(tmp)) { |
| 6535 | PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" 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 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6540 | if (elts == NULL) goto failed; |
| 6541 | for (i = 0; i < len; i++) { |
| 6542 | expr_ty value; |
| 6543 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6544 | if (res != 0) goto failed; |
| 6545 | asdl_seq_SET(elts, 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 \"elts\" missing from Tuple"); |
| 6550 | return 1; |
| 6551 | } |
| 6552 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
| 6553 | int res; |
| 6554 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
| 6555 | if (tmp == NULL) goto failed; |
| 6556 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 6557 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6558 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6559 | } else { |
| 6560 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 6561 | return 1; |
| 6562 | } |
| 6563 | *out = Tuple(elts, ctx, lineno, col_offset, arena); |
| 6564 | if (*out == NULL) goto failed; |
| 6565 | return 0; |
| 6566 | } |
| 6567 | |
| 6568 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
| 6569 | failed: |
| 6570 | Py_XDECREF(tmp); |
| 6571 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6572 | } |
| 6573 | |
| 6574 | int |
| 6575 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 6576 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6577 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6578 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6579 | isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); |
| 6580 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6581 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6582 | } |
| 6583 | if (isinstance) { |
| 6584 | *out = Load; |
| 6585 | return 0; |
| 6586 | } |
| 6587 | isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type); |
| 6588 | if (isinstance == -1) { |
| 6589 | return 1; |
| 6590 | } |
| 6591 | if (isinstance) { |
| 6592 | *out = Store; |
| 6593 | return 0; |
| 6594 | } |
| 6595 | isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type); |
| 6596 | if (isinstance == -1) { |
| 6597 | return 1; |
| 6598 | } |
| 6599 | if (isinstance) { |
| 6600 | *out = Del; |
| 6601 | return 0; |
| 6602 | } |
| 6603 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type); |
| 6604 | if (isinstance == -1) { |
| 6605 | return 1; |
| 6606 | } |
| 6607 | if (isinstance) { |
| 6608 | *out = AugLoad; |
| 6609 | return 0; |
| 6610 | } |
| 6611 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type); |
| 6612 | if (isinstance == -1) { |
| 6613 | return 1; |
| 6614 | } |
| 6615 | if (isinstance) { |
| 6616 | *out = AugStore; |
| 6617 | return 0; |
| 6618 | } |
| 6619 | isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type); |
| 6620 | if (isinstance == -1) { |
| 6621 | return 1; |
| 6622 | } |
| 6623 | if (isinstance) { |
| 6624 | *out = Param; |
| 6625 | return 0; |
| 6626 | } |
| 6627 | |
| 6628 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj); |
| 6629 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6630 | } |
| 6631 | |
| 6632 | int |
| 6633 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
| 6634 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6635 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6636 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6637 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6638 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6639 | if (obj == Py_None) { |
| 6640 | *out = NULL; |
| 6641 | return 0; |
| 6642 | } |
| 6643 | isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type); |
| 6644 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6645 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6646 | } |
| 6647 | if (isinstance) { |
| 6648 | expr_ty lower; |
| 6649 | expr_ty upper; |
| 6650 | expr_ty step; |
| 6651 | |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6652 | if (exists_not_none(obj, &PyId_lower)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6653 | int res; |
| 6654 | tmp = _PyObject_GetAttrId(obj, &PyId_lower); |
| 6655 | if (tmp == NULL) goto failed; |
| 6656 | res = obj2ast_expr(tmp, &lower, arena); |
| 6657 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6658 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6659 | } else { |
| 6660 | lower = NULL; |
| 6661 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6662 | if (exists_not_none(obj, &PyId_upper)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6663 | int res; |
| 6664 | tmp = _PyObject_GetAttrId(obj, &PyId_upper); |
| 6665 | if (tmp == NULL) goto failed; |
| 6666 | res = obj2ast_expr(tmp, &upper, arena); |
| 6667 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6668 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6669 | } else { |
| 6670 | upper = NULL; |
| 6671 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6672 | if (exists_not_none(obj, &PyId_step)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6673 | int res; |
| 6674 | tmp = _PyObject_GetAttrId(obj, &PyId_step); |
| 6675 | if (tmp == NULL) goto failed; |
| 6676 | res = obj2ast_expr(tmp, &step, arena); |
| 6677 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6678 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6679 | } else { |
| 6680 | step = NULL; |
| 6681 | } |
| 6682 | *out = Slice(lower, upper, step, arena); |
| 6683 | if (*out == NULL) goto failed; |
| 6684 | return 0; |
| 6685 | } |
| 6686 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type); |
| 6687 | if (isinstance == -1) { |
| 6688 | return 1; |
| 6689 | } |
| 6690 | if (isinstance) { |
| 6691 | asdl_seq* dims; |
| 6692 | |
| 6693 | if (_PyObject_HasAttrId(obj, &PyId_dims)) { |
| 6694 | int res; |
| 6695 | Py_ssize_t len; |
| 6696 | Py_ssize_t i; |
| 6697 | tmp = _PyObject_GetAttrId(obj, &PyId_dims); |
| 6698 | if (tmp == NULL) goto failed; |
| 6699 | if (!PyList_Check(tmp)) { |
| 6700 | PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6701 | goto failed; |
| 6702 | } |
| 6703 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6704 | dims = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6705 | if (dims == NULL) goto failed; |
| 6706 | for (i = 0; i < len; i++) { |
| 6707 | slice_ty value; |
| 6708 | res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6709 | if (res != 0) goto failed; |
| 6710 | asdl_seq_SET(dims, i, value); |
| 6711 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6712 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6713 | } else { |
| 6714 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
| 6715 | return 1; |
| 6716 | } |
| 6717 | *out = ExtSlice(dims, arena); |
| 6718 | if (*out == NULL) goto failed; |
| 6719 | return 0; |
| 6720 | } |
| 6721 | isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type); |
| 6722 | if (isinstance == -1) { |
| 6723 | return 1; |
| 6724 | } |
| 6725 | if (isinstance) { |
| 6726 | expr_ty value; |
| 6727 | |
| 6728 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 6729 | int res; |
| 6730 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 6731 | if (tmp == NULL) goto failed; |
| 6732 | res = obj2ast_expr(tmp, &value, arena); |
| 6733 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6734 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6735 | } else { |
| 6736 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
| 6737 | return 1; |
| 6738 | } |
| 6739 | *out = Index(value, arena); |
| 6740 | if (*out == NULL) goto failed; |
| 6741 | return 0; |
| 6742 | } |
| 6743 | |
| 6744 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj); |
| 6745 | failed: |
| 6746 | Py_XDECREF(tmp); |
| 6747 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6748 | } |
| 6749 | |
| 6750 | int |
| 6751 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 6752 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6753 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6754 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6755 | isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); |
| 6756 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6757 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6758 | } |
| 6759 | if (isinstance) { |
| 6760 | *out = And; |
| 6761 | return 0; |
| 6762 | } |
| 6763 | isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type); |
| 6764 | if (isinstance == -1) { |
| 6765 | return 1; |
| 6766 | } |
| 6767 | if (isinstance) { |
| 6768 | *out = Or; |
| 6769 | return 0; |
| 6770 | } |
| 6771 | |
| 6772 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj); |
| 6773 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6774 | } |
| 6775 | |
| 6776 | int |
| 6777 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 6778 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6779 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6780 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6781 | isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); |
| 6782 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6783 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6784 | } |
| 6785 | if (isinstance) { |
| 6786 | *out = Add; |
| 6787 | return 0; |
| 6788 | } |
| 6789 | isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type); |
| 6790 | if (isinstance == -1) { |
| 6791 | return 1; |
| 6792 | } |
| 6793 | if (isinstance) { |
| 6794 | *out = Sub; |
| 6795 | return 0; |
| 6796 | } |
| 6797 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type); |
| 6798 | if (isinstance == -1) { |
| 6799 | return 1; |
| 6800 | } |
| 6801 | if (isinstance) { |
| 6802 | *out = Mult; |
| 6803 | return 0; |
| 6804 | } |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 6805 | isinstance = PyObject_IsInstance(obj, (PyObject *)MatMult_type); |
| 6806 | if (isinstance == -1) { |
| 6807 | return 1; |
| 6808 | } |
| 6809 | if (isinstance) { |
| 6810 | *out = MatMult; |
| 6811 | return 0; |
| 6812 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6813 | isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type); |
| 6814 | if (isinstance == -1) { |
| 6815 | return 1; |
| 6816 | } |
| 6817 | if (isinstance) { |
| 6818 | *out = Div; |
| 6819 | return 0; |
| 6820 | } |
| 6821 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type); |
| 6822 | if (isinstance == -1) { |
| 6823 | return 1; |
| 6824 | } |
| 6825 | if (isinstance) { |
| 6826 | *out = Mod; |
| 6827 | return 0; |
| 6828 | } |
| 6829 | isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type); |
| 6830 | if (isinstance == -1) { |
| 6831 | return 1; |
| 6832 | } |
| 6833 | if (isinstance) { |
| 6834 | *out = Pow; |
| 6835 | return 0; |
| 6836 | } |
| 6837 | isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type); |
| 6838 | if (isinstance == -1) { |
| 6839 | return 1; |
| 6840 | } |
| 6841 | if (isinstance) { |
| 6842 | *out = LShift; |
| 6843 | return 0; |
| 6844 | } |
| 6845 | isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type); |
| 6846 | if (isinstance == -1) { |
| 6847 | return 1; |
| 6848 | } |
| 6849 | if (isinstance) { |
| 6850 | *out = RShift; |
| 6851 | return 0; |
| 6852 | } |
| 6853 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type); |
| 6854 | if (isinstance == -1) { |
| 6855 | return 1; |
| 6856 | } |
| 6857 | if (isinstance) { |
| 6858 | *out = BitOr; |
| 6859 | return 0; |
| 6860 | } |
| 6861 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type); |
| 6862 | if (isinstance == -1) { |
| 6863 | return 1; |
| 6864 | } |
| 6865 | if (isinstance) { |
| 6866 | *out = BitXor; |
| 6867 | return 0; |
| 6868 | } |
| 6869 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type); |
| 6870 | if (isinstance == -1) { |
| 6871 | return 1; |
| 6872 | } |
| 6873 | if (isinstance) { |
| 6874 | *out = BitAnd; |
| 6875 | return 0; |
| 6876 | } |
| 6877 | isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type); |
| 6878 | if (isinstance == -1) { |
| 6879 | return 1; |
| 6880 | } |
| 6881 | if (isinstance) { |
| 6882 | *out = FloorDiv; |
| 6883 | return 0; |
| 6884 | } |
| 6885 | |
| 6886 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj); |
| 6887 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6888 | } |
| 6889 | |
| 6890 | int |
| 6891 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 6892 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6893 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6894 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6895 | isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); |
| 6896 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6897 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6898 | } |
| 6899 | if (isinstance) { |
| 6900 | *out = Invert; |
| 6901 | return 0; |
| 6902 | } |
| 6903 | isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type); |
| 6904 | if (isinstance == -1) { |
| 6905 | return 1; |
| 6906 | } |
| 6907 | if (isinstance) { |
| 6908 | *out = Not; |
| 6909 | return 0; |
| 6910 | } |
| 6911 | isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type); |
| 6912 | if (isinstance == -1) { |
| 6913 | return 1; |
| 6914 | } |
| 6915 | if (isinstance) { |
| 6916 | *out = UAdd; |
| 6917 | return 0; |
| 6918 | } |
| 6919 | isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type); |
| 6920 | if (isinstance == -1) { |
| 6921 | return 1; |
| 6922 | } |
| 6923 | if (isinstance) { |
| 6924 | *out = USub; |
| 6925 | return 0; |
| 6926 | } |
| 6927 | |
| 6928 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj); |
| 6929 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6930 | } |
| 6931 | |
| 6932 | int |
| 6933 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 6934 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6935 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6936 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6937 | isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); |
| 6938 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6939 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6940 | } |
| 6941 | if (isinstance) { |
| 6942 | *out = Eq; |
| 6943 | return 0; |
| 6944 | } |
| 6945 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type); |
| 6946 | if (isinstance == -1) { |
| 6947 | return 1; |
| 6948 | } |
| 6949 | if (isinstance) { |
| 6950 | *out = NotEq; |
| 6951 | return 0; |
| 6952 | } |
| 6953 | isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type); |
| 6954 | if (isinstance == -1) { |
| 6955 | return 1; |
| 6956 | } |
| 6957 | if (isinstance) { |
| 6958 | *out = Lt; |
| 6959 | return 0; |
| 6960 | } |
| 6961 | isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type); |
| 6962 | if (isinstance == -1) { |
| 6963 | return 1; |
| 6964 | } |
| 6965 | if (isinstance) { |
| 6966 | *out = LtE; |
| 6967 | return 0; |
| 6968 | } |
| 6969 | isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type); |
| 6970 | if (isinstance == -1) { |
| 6971 | return 1; |
| 6972 | } |
| 6973 | if (isinstance) { |
| 6974 | *out = Gt; |
| 6975 | return 0; |
| 6976 | } |
| 6977 | isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type); |
| 6978 | if (isinstance == -1) { |
| 6979 | return 1; |
| 6980 | } |
| 6981 | if (isinstance) { |
| 6982 | *out = GtE; |
| 6983 | return 0; |
| 6984 | } |
| 6985 | isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type); |
| 6986 | if (isinstance == -1) { |
| 6987 | return 1; |
| 6988 | } |
| 6989 | if (isinstance) { |
| 6990 | *out = Is; |
| 6991 | return 0; |
| 6992 | } |
| 6993 | isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type); |
| 6994 | if (isinstance == -1) { |
| 6995 | return 1; |
| 6996 | } |
| 6997 | if (isinstance) { |
| 6998 | *out = IsNot; |
| 6999 | return 0; |
| 7000 | } |
| 7001 | isinstance = PyObject_IsInstance(obj, (PyObject *)In_type); |
| 7002 | if (isinstance == -1) { |
| 7003 | return 1; |
| 7004 | } |
| 7005 | if (isinstance) { |
| 7006 | *out = In; |
| 7007 | return 0; |
| 7008 | } |
| 7009 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type); |
| 7010 | if (isinstance == -1) { |
| 7011 | return 1; |
| 7012 | } |
| 7013 | if (isinstance) { |
| 7014 | *out = NotIn; |
| 7015 | return 0; |
| 7016 | } |
| 7017 | |
| 7018 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj); |
| 7019 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7020 | } |
| 7021 | |
| 7022 | int |
| 7023 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 7024 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7025 | PyObject* tmp = NULL; |
| 7026 | expr_ty target; |
| 7027 | expr_ty iter; |
| 7028 | asdl_seq* ifs; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7029 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7030 | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
| 7031 | int res; |
| 7032 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
| 7033 | if (tmp == NULL) goto failed; |
| 7034 | res = obj2ast_expr(tmp, &target, arena); |
| 7035 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7036 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7037 | } else { |
| 7038 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7039 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7040 | } |
| 7041 | if (_PyObject_HasAttrId(obj, &PyId_iter)) { |
| 7042 | int res; |
| 7043 | tmp = _PyObject_GetAttrId(obj, &PyId_iter); |
| 7044 | if (tmp == NULL) goto failed; |
| 7045 | res = obj2ast_expr(tmp, &iter, arena); |
| 7046 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7047 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7048 | } else { |
| 7049 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 7050 | return 1; |
| 7051 | } |
| 7052 | if (_PyObject_HasAttrId(obj, &PyId_ifs)) { |
| 7053 | int res; |
| 7054 | Py_ssize_t len; |
| 7055 | Py_ssize_t i; |
| 7056 | tmp = _PyObject_GetAttrId(obj, &PyId_ifs); |
| 7057 | if (tmp == NULL) goto failed; |
| 7058 | if (!PyList_Check(tmp)) { |
| 7059 | PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7060 | goto failed; |
| 7061 | } |
| 7062 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7063 | ifs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7064 | if (ifs == NULL) goto failed; |
| 7065 | for (i = 0; i < len; i++) { |
| 7066 | expr_ty value; |
| 7067 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 7068 | if (res != 0) goto failed; |
| 7069 | asdl_seq_SET(ifs, i, value); |
| 7070 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7071 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7072 | } else { |
| 7073 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 7074 | return 1; |
| 7075 | } |
| 7076 | *out = comprehension(target, iter, ifs, arena); |
| 7077 | return 0; |
| 7078 | failed: |
| 7079 | Py_XDECREF(tmp); |
| 7080 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7081 | } |
| 7082 | |
| 7083 | int |
| 7084 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 7085 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7086 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 7087 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7088 | PyObject *tmp = NULL; |
| 7089 | int lineno; |
| 7090 | int col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7091 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7092 | if (obj == Py_None) { |
| 7093 | *out = NULL; |
| 7094 | return 0; |
| 7095 | } |
| 7096 | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
| 7097 | int res; |
| 7098 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
| 7099 | if (tmp == NULL) goto failed; |
| 7100 | res = obj2ast_int(tmp, &lineno, arena); |
| 7101 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7102 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7103 | } else { |
| 7104 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7105 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7106 | } |
| 7107 | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
| 7108 | int res; |
| 7109 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
| 7110 | if (tmp == NULL) goto failed; |
| 7111 | res = obj2ast_int(tmp, &col_offset, arena); |
| 7112 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7113 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7114 | } else { |
| 7115 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 7116 | return 1; |
| 7117 | } |
| 7118 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type); |
| 7119 | if (isinstance == -1) { |
| 7120 | return 1; |
| 7121 | } |
| 7122 | if (isinstance) { |
| 7123 | expr_ty type; |
| 7124 | identifier name; |
| 7125 | asdl_seq* body; |
| 7126 | |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7127 | if (exists_not_none(obj, &PyId_type)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7128 | int res; |
| 7129 | tmp = _PyObject_GetAttrId(obj, &PyId_type); |
| 7130 | if (tmp == NULL) goto failed; |
| 7131 | res = obj2ast_expr(tmp, &type, arena); |
| 7132 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7133 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7134 | } else { |
| 7135 | type = NULL; |
| 7136 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7137 | if (exists_not_none(obj, &PyId_name)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7138 | int res; |
| 7139 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
| 7140 | if (tmp == NULL) goto failed; |
| 7141 | res = obj2ast_identifier(tmp, &name, arena); |
| 7142 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7143 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7144 | } else { |
| 7145 | name = NULL; |
| 7146 | } |
| 7147 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 7148 | int res; |
| 7149 | Py_ssize_t len; |
| 7150 | Py_ssize_t i; |
| 7151 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 7152 | if (tmp == NULL) goto failed; |
| 7153 | if (!PyList_Check(tmp)) { |
| 7154 | PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7155 | goto failed; |
| 7156 | } |
| 7157 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7158 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7159 | if (body == NULL) goto failed; |
| 7160 | for (i = 0; i < len; i++) { |
| 7161 | stmt_ty value; |
| 7162 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 7163 | if (res != 0) goto failed; |
| 7164 | asdl_seq_SET(body, i, value); |
| 7165 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7166 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7167 | } else { |
| 7168 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 7169 | return 1; |
| 7170 | } |
| 7171 | *out = ExceptHandler(type, name, body, lineno, col_offset, arena); |
| 7172 | if (*out == NULL) goto failed; |
| 7173 | return 0; |
| 7174 | } |
| 7175 | |
| 7176 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
| 7177 | failed: |
| 7178 | Py_XDECREF(tmp); |
| 7179 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7180 | } |
| 7181 | |
| 7182 | int |
| 7183 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 7184 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7185 | PyObject* tmp = NULL; |
| 7186 | asdl_seq* args; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7187 | arg_ty vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7188 | asdl_seq* kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7189 | asdl_seq* kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7190 | arg_ty kwarg; |
| 7191 | asdl_seq* defaults; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7192 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7193 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
| 7194 | int res; |
| 7195 | Py_ssize_t len; |
| 7196 | Py_ssize_t i; |
| 7197 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
| 7198 | if (tmp == NULL) goto failed; |
| 7199 | if (!PyList_Check(tmp)) { |
| 7200 | PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7201 | goto failed; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7202 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7203 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7204 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7205 | if (args == NULL) goto failed; |
| 7206 | for (i = 0; i < len; i++) { |
| 7207 | arg_ty value; |
| 7208 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
| 7209 | if (res != 0) goto failed; |
| 7210 | asdl_seq_SET(args, i, value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7211 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7212 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7213 | } else { |
| 7214 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7215 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7216 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7217 | if (exists_not_none(obj, &PyId_vararg)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7218 | int res; |
| 7219 | tmp = _PyObject_GetAttrId(obj, &PyId_vararg); |
| 7220 | if (tmp == NULL) goto failed; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7221 | res = obj2ast_arg(tmp, &vararg, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7222 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7223 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7224 | } else { |
| 7225 | vararg = NULL; |
| 7226 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7227 | if (_PyObject_HasAttrId(obj, &PyId_kwonlyargs)) { |
| 7228 | int res; |
| 7229 | Py_ssize_t len; |
| 7230 | Py_ssize_t i; |
| 7231 | tmp = _PyObject_GetAttrId(obj, &PyId_kwonlyargs); |
| 7232 | if (tmp == NULL) goto failed; |
| 7233 | if (!PyList_Check(tmp)) { |
| 7234 | PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7235 | goto failed; |
| 7236 | } |
| 7237 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7238 | kwonlyargs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7239 | if (kwonlyargs == NULL) goto failed; |
| 7240 | for (i = 0; i < len; i++) { |
| 7241 | arg_ty value; |
| 7242 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
| 7243 | if (res != 0) goto failed; |
| 7244 | asdl_seq_SET(kwonlyargs, i, value); |
| 7245 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7246 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7247 | } else { |
| 7248 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 7249 | return 1; |
| 7250 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7251 | if (_PyObject_HasAttrId(obj, &PyId_kw_defaults)) { |
| 7252 | int res; |
| 7253 | Py_ssize_t len; |
| 7254 | Py_ssize_t i; |
| 7255 | tmp = _PyObject_GetAttrId(obj, &PyId_kw_defaults); |
| 7256 | if (tmp == NULL) goto failed; |
| 7257 | if (!PyList_Check(tmp)) { |
| 7258 | PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7259 | goto failed; |
| 7260 | } |
| 7261 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7262 | kw_defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7263 | if (kw_defaults == NULL) goto failed; |
| 7264 | for (i = 0; i < len; i++) { |
| 7265 | expr_ty value; |
| 7266 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 7267 | if (res != 0) goto failed; |
| 7268 | asdl_seq_SET(kw_defaults, i, value); |
| 7269 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7270 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7271 | } else { |
| 7272 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 7273 | return 1; |
| 7274 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7275 | if (exists_not_none(obj, &PyId_kwarg)) { |
| 7276 | int res; |
| 7277 | tmp = _PyObject_GetAttrId(obj, &PyId_kwarg); |
| 7278 | if (tmp == NULL) goto failed; |
| 7279 | res = obj2ast_arg(tmp, &kwarg, arena); |
| 7280 | if (res != 0) goto failed; |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 7281 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7282 | } else { |
| 7283 | kwarg = NULL; |
| 7284 | } |
| 7285 | if (_PyObject_HasAttrId(obj, &PyId_defaults)) { |
| 7286 | int res; |
| 7287 | Py_ssize_t len; |
| 7288 | Py_ssize_t i; |
| 7289 | tmp = _PyObject_GetAttrId(obj, &PyId_defaults); |
| 7290 | if (tmp == NULL) goto failed; |
| 7291 | if (!PyList_Check(tmp)) { |
| 7292 | PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7293 | goto failed; |
| 7294 | } |
| 7295 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7296 | defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7297 | if (defaults == NULL) goto failed; |
| 7298 | for (i = 0; i < len; i++) { |
| 7299 | expr_ty value; |
| 7300 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 7301 | if (res != 0) goto failed; |
| 7302 | asdl_seq_SET(defaults, i, value); |
| 7303 | } |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 7304 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7305 | } else { |
| 7306 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 7307 | return 1; |
| 7308 | } |
| 7309 | *out = arguments(args, vararg, kwonlyargs, kw_defaults, kwarg, defaults, |
| 7310 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7311 | return 0; |
| 7312 | failed: |
| 7313 | Py_XDECREF(tmp); |
| 7314 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7315 | } |
| 7316 | |
| 7317 | int |
| 7318 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 7319 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7320 | PyObject* tmp = NULL; |
| 7321 | identifier arg; |
| 7322 | expr_ty annotation; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 7323 | int lineno; |
| 7324 | int col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7325 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7326 | if (_PyObject_HasAttrId(obj, &PyId_arg)) { |
| 7327 | int res; |
| 7328 | tmp = _PyObject_GetAttrId(obj, &PyId_arg); |
| 7329 | if (tmp == NULL) goto failed; |
| 7330 | res = obj2ast_identifier(tmp, &arg, arena); |
| 7331 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7332 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7333 | } else { |
| 7334 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7335 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7336 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7337 | if (exists_not_none(obj, &PyId_annotation)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7338 | int res; |
| 7339 | tmp = _PyObject_GetAttrId(obj, &PyId_annotation); |
| 7340 | if (tmp == NULL) goto failed; |
| 7341 | res = obj2ast_expr(tmp, &annotation, arena); |
| 7342 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7343 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7344 | } else { |
| 7345 | annotation = NULL; |
| 7346 | } |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 7347 | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
| 7348 | int res; |
| 7349 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
| 7350 | if (tmp == NULL) goto failed; |
| 7351 | res = obj2ast_int(tmp, &lineno, arena); |
| 7352 | if (res != 0) goto failed; |
| 7353 | Py_CLEAR(tmp); |
| 7354 | } else { |
| 7355 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg"); |
| 7356 | return 1; |
| 7357 | } |
| 7358 | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
| 7359 | int res; |
| 7360 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
| 7361 | if (tmp == NULL) goto failed; |
| 7362 | res = obj2ast_int(tmp, &col_offset, arena); |
| 7363 | if (res != 0) goto failed; |
| 7364 | Py_CLEAR(tmp); |
| 7365 | } else { |
| 7366 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg"); |
| 7367 | return 1; |
| 7368 | } |
| 7369 | *out = arg(arg, annotation, lineno, col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7370 | return 0; |
| 7371 | failed: |
| 7372 | Py_XDECREF(tmp); |
| 7373 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7374 | } |
| 7375 | |
| 7376 | int |
| 7377 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 7378 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7379 | PyObject* tmp = NULL; |
| 7380 | identifier arg; |
| 7381 | expr_ty value; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7382 | |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 7383 | if (exists_not_none(obj, &PyId_arg)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7384 | int res; |
| 7385 | tmp = _PyObject_GetAttrId(obj, &PyId_arg); |
| 7386 | if (tmp == NULL) goto failed; |
| 7387 | res = obj2ast_identifier(tmp, &arg, arena); |
| 7388 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7389 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7390 | } else { |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 7391 | arg = NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7392 | } |
| 7393 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 7394 | int res; |
| 7395 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 7396 | if (tmp == NULL) goto failed; |
| 7397 | res = obj2ast_expr(tmp, &value, arena); |
| 7398 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7399 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7400 | } else { |
| 7401 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 7402 | return 1; |
| 7403 | } |
| 7404 | *out = keyword(arg, value, arena); |
| 7405 | return 0; |
| 7406 | failed: |
| 7407 | Py_XDECREF(tmp); |
| 7408 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7409 | } |
| 7410 | |
| 7411 | int |
| 7412 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 7413 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7414 | PyObject* tmp = NULL; |
| 7415 | identifier name; |
| 7416 | identifier asname; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7417 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7418 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
| 7419 | int res; |
| 7420 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
| 7421 | if (tmp == NULL) goto failed; |
| 7422 | res = obj2ast_identifier(tmp, &name, arena); |
| 7423 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7424 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7425 | } else { |
| 7426 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7427 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7428 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7429 | if (exists_not_none(obj, &PyId_asname)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7430 | int res; |
| 7431 | tmp = _PyObject_GetAttrId(obj, &PyId_asname); |
| 7432 | if (tmp == NULL) goto failed; |
| 7433 | res = obj2ast_identifier(tmp, &asname, arena); |
| 7434 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7435 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7436 | } else { |
| 7437 | asname = NULL; |
| 7438 | } |
| 7439 | *out = alias(name, asname, arena); |
| 7440 | return 0; |
| 7441 | failed: |
| 7442 | Py_XDECREF(tmp); |
| 7443 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7444 | } |
| 7445 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 7446 | int |
| 7447 | obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) |
| 7448 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7449 | PyObject* tmp = NULL; |
| 7450 | expr_ty context_expr; |
| 7451 | expr_ty optional_vars; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 7452 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7453 | if (_PyObject_HasAttrId(obj, &PyId_context_expr)) { |
| 7454 | int res; |
| 7455 | tmp = _PyObject_GetAttrId(obj, &PyId_context_expr); |
| 7456 | if (tmp == NULL) goto failed; |
| 7457 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 7458 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7459 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7460 | } else { |
| 7461 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 7462 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7463 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7464 | if (exists_not_none(obj, &PyId_optional_vars)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7465 | int res; |
| 7466 | tmp = _PyObject_GetAttrId(obj, &PyId_optional_vars); |
| 7467 | if (tmp == NULL) goto failed; |
| 7468 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 7469 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7470 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7471 | } else { |
| 7472 | optional_vars = NULL; |
| 7473 | } |
| 7474 | *out = withitem(context_expr, optional_vars, arena); |
| 7475 | return 0; |
| 7476 | failed: |
| 7477 | Py_XDECREF(tmp); |
| 7478 | return 1; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 7479 | } |
| 7480 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7481 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7482 | static struct PyModuleDef _astmodule = { |
| 7483 | PyModuleDef_HEAD_INIT, "_ast" |
| 7484 | }; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 7485 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7486 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 7487 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7488 | PyObject *m, *d; |
| 7489 | if (!init_types()) return NULL; |
| 7490 | m = PyModule_Create(&_astmodule); |
| 7491 | if (!m) return NULL; |
| 7492 | d = PyModule_GetDict(m); |
| 7493 | if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return NULL; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7494 | if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7495 | return NULL; |
| 7496 | if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return NULL; |
| 7497 | if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) return |
| 7498 | NULL; |
| 7499 | if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) < |
| 7500 | 0) return NULL; |
| 7501 | if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < 0) |
| 7502 | return NULL; |
| 7503 | if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return |
| 7504 | NULL; |
| 7505 | if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return NULL; |
| 7506 | if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) < |
| 7507 | 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7508 | if (PyDict_SetItemString(d, "AsyncFunctionDef", |
| 7509 | (PyObject*)AsyncFunctionDef_type) < 0) return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7510 | if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) |
| 7511 | return NULL; |
| 7512 | if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) return |
| 7513 | NULL; |
| 7514 | if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) return |
| 7515 | NULL; |
| 7516 | if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) return |
| 7517 | NULL; |
| 7518 | if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < 0) |
| 7519 | return NULL; |
| 7520 | if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7521 | if (PyDict_SetItemString(d, "AsyncFor", (PyObject*)AsyncFor_type) < 0) |
| 7522 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7523 | if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return |
| 7524 | NULL; |
| 7525 | if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return NULL; |
| 7526 | if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7527 | if (PyDict_SetItemString(d, "AsyncWith", (PyObject*)AsyncWith_type) < 0) |
| 7528 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7529 | if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return |
| 7530 | NULL; |
| 7531 | if (PyDict_SetItemString(d, "Try", (PyObject*)Try_type) < 0) return NULL; |
| 7532 | if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) return |
| 7533 | NULL; |
| 7534 | if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) return |
| 7535 | NULL; |
| 7536 | if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < 0) |
| 7537 | return NULL; |
| 7538 | if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) return |
| 7539 | NULL; |
| 7540 | if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0) |
| 7541 | return NULL; |
| 7542 | if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return NULL; |
| 7543 | if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return NULL; |
| 7544 | if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return |
| 7545 | NULL; |
| 7546 | if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) |
| 7547 | return NULL; |
| 7548 | if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return NULL; |
| 7549 | if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) return |
| 7550 | NULL; |
| 7551 | if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return |
| 7552 | NULL; |
| 7553 | if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) return |
| 7554 | NULL; |
| 7555 | if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) return |
| 7556 | NULL; |
| 7557 | if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return |
| 7558 | NULL; |
| 7559 | if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return NULL; |
| 7560 | if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return NULL; |
| 7561 | if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) |
| 7562 | return NULL; |
| 7563 | if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) return |
| 7564 | NULL; |
| 7565 | if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0) |
| 7566 | return NULL; |
| 7567 | if (PyDict_SetItemString(d, "GeneratorExp", (PyObject*)GeneratorExp_type) < |
| 7568 | 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7569 | if (PyDict_SetItemString(d, "Await", (PyObject*)Await_type) < 0) return |
| 7570 | NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7571 | if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return |
| 7572 | NULL; |
| 7573 | if (PyDict_SetItemString(d, "YieldFrom", (PyObject*)YieldFrom_type) < 0) |
| 7574 | return NULL; |
| 7575 | if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) return |
| 7576 | NULL; |
| 7577 | if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return NULL; |
| 7578 | if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return NULL; |
| 7579 | if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return NULL; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7580 | if (PyDict_SetItemString(d, "FormattedValue", |
| 7581 | (PyObject*)FormattedValue_type) < 0) return NULL; |
| 7582 | if (PyDict_SetItemString(d, "JoinedStr", (PyObject*)JoinedStr_type) < 0) |
| 7583 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7584 | if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return |
| 7585 | NULL; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7586 | if (PyDict_SetItemString(d, "NameConstant", (PyObject*)NameConstant_type) < |
| 7587 | 0) return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7588 | if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0) |
| 7589 | return NULL; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 7590 | if (PyDict_SetItemString(d, "Constant", (PyObject*)Constant_type) < 0) |
| 7591 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7592 | if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < 0) |
| 7593 | return NULL; |
| 7594 | if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < 0) |
| 7595 | return NULL; |
| 7596 | if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0) return |
| 7597 | NULL; |
| 7598 | if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return NULL; |
| 7599 | if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return NULL; |
| 7600 | if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return |
| 7601 | NULL; |
| 7602 | if (PyDict_SetItemString(d, "expr_context", (PyObject*)expr_context_type) < |
| 7603 | 0) return NULL; |
| 7604 | if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return NULL; |
| 7605 | if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return |
| 7606 | NULL; |
| 7607 | if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return NULL; |
| 7608 | if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) return |
| 7609 | NULL; |
| 7610 | if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) |
| 7611 | return NULL; |
| 7612 | if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return |
| 7613 | NULL; |
| 7614 | if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return |
| 7615 | NULL; |
| 7616 | if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return |
| 7617 | NULL; |
| 7618 | if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) |
| 7619 | return NULL; |
| 7620 | if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return |
| 7621 | NULL; |
| 7622 | if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) return |
| 7623 | NULL; |
| 7624 | if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return NULL; |
| 7625 | if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return NULL; |
| 7626 | if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) |
| 7627 | return NULL; |
| 7628 | if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return NULL; |
| 7629 | if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return NULL; |
| 7630 | if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return NULL; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 7631 | if (PyDict_SetItemString(d, "MatMult", (PyObject*)MatMult_type) < 0) return |
| 7632 | NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7633 | if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return NULL; |
| 7634 | if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return NULL; |
| 7635 | if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return NULL; |
| 7636 | if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) return |
| 7637 | NULL; |
| 7638 | if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) return |
| 7639 | NULL; |
| 7640 | if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return |
| 7641 | NULL; |
| 7642 | if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) return |
| 7643 | NULL; |
| 7644 | if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) return |
| 7645 | NULL; |
| 7646 | if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) |
| 7647 | return NULL; |
| 7648 | if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) return |
| 7649 | NULL; |
| 7650 | if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) return |
| 7651 | NULL; |
| 7652 | if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return NULL; |
| 7653 | if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return NULL; |
| 7654 | if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return NULL; |
| 7655 | if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return |
| 7656 | NULL; |
| 7657 | if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return NULL; |
| 7658 | if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return |
| 7659 | NULL; |
| 7660 | if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return NULL; |
| 7661 | if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return NULL; |
| 7662 | if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return NULL; |
| 7663 | if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return NULL; |
| 7664 | if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return NULL; |
| 7665 | if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return |
| 7666 | NULL; |
| 7667 | if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return NULL; |
| 7668 | if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return |
| 7669 | NULL; |
| 7670 | if (PyDict_SetItemString(d, "comprehension", (PyObject*)comprehension_type) |
| 7671 | < 0) return NULL; |
| 7672 | if (PyDict_SetItemString(d, "excepthandler", (PyObject*)excepthandler_type) |
| 7673 | < 0) return NULL; |
| 7674 | if (PyDict_SetItemString(d, "ExceptHandler", (PyObject*)ExceptHandler_type) |
| 7675 | < 0) return NULL; |
| 7676 | if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < 0) |
| 7677 | return NULL; |
| 7678 | if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return NULL; |
| 7679 | if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) return |
| 7680 | NULL; |
| 7681 | if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return |
| 7682 | NULL; |
| 7683 | if (PyDict_SetItemString(d, "withitem", (PyObject*)withitem_type) < 0) |
| 7684 | return NULL; |
| 7685 | return m; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 7686 | } |
| 7687 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 7688 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 7689 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 7690 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 7691 | if (!init_types()) |
| 7692 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 7693 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 7694 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 7695 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7696 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 7697 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7698 | { |
| 7699 | mod_ty res; |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 7700 | PyObject *req_type[3]; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7701 | char *req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 7702 | int isinstance; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 7703 | |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 7704 | req_type[0] = (PyObject*)Module_type; |
| 7705 | req_type[1] = (PyObject*)Expression_type; |
| 7706 | req_type[2] = (PyObject*)Interactive_type; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 7707 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7708 | assert(0 <= mode && mode <= 2); |
| 7709 | |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 7710 | if (!init_types()) |
| 7711 | return NULL; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7712 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 7713 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 7714 | if (isinstance == -1) |
| 7715 | return NULL; |
| 7716 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7717 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
| 7718 | req_name[mode], Py_TYPE(ast)->tp_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7719 | return NULL; |
| 7720 | } |
| 7721 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 7722 | return NULL; |
| 7723 | else |
| 7724 | return res; |
| 7725 | } |
| 7726 | |
| 7727 | int PyAST_Check(PyObject* obj) |
| 7728 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 7729 | if (!init_types()) |
| 7730 | return -1; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 7731 | return PyObject_IsInstance(obj, (PyObject*)&AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7732 | } |
| 7733 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 7734 | |