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); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 31 | _Py_IDENTIFIER(end_lineno); |
| 32 | _Py_IDENTIFIER(end_col_offset); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 33 | static char *stmt_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 34 | "lineno", |
| 35 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 36 | "end_lineno", |
| 37 | "end_col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 38 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 39 | static PyObject* ast2obj_stmt(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 40 | static PyTypeObject *FunctionDef_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 41 | _Py_IDENTIFIER(name); |
| 42 | _Py_IDENTIFIER(args); |
| 43 | _Py_IDENTIFIER(decorator_list); |
| 44 | _Py_IDENTIFIER(returns); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 45 | static char *FunctionDef_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 46 | "name", |
| 47 | "args", |
| 48 | "body", |
| 49 | "decorator_list", |
| 50 | "returns", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 51 | }; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 52 | static PyTypeObject *AsyncFunctionDef_type; |
| 53 | static char *AsyncFunctionDef_fields[]={ |
| 54 | "name", |
| 55 | "args", |
| 56 | "body", |
| 57 | "decorator_list", |
| 58 | "returns", |
| 59 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 60 | static PyTypeObject *ClassDef_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 61 | _Py_IDENTIFIER(bases); |
| 62 | _Py_IDENTIFIER(keywords); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 63 | static char *ClassDef_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 64 | "name", |
| 65 | "bases", |
| 66 | "keywords", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 67 | "body", |
| 68 | "decorator_list", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 69 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 70 | static PyTypeObject *Return_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 71 | _Py_IDENTIFIER(value); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 72 | static char *Return_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 73 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 74 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 75 | static PyTypeObject *Delete_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 76 | _Py_IDENTIFIER(targets); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 77 | static char *Delete_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 78 | "targets", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 79 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 80 | static PyTypeObject *Assign_type; |
| 81 | static char *Assign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 82 | "targets", |
| 83 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 84 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 85 | static PyTypeObject *AugAssign_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 86 | _Py_IDENTIFIER(target); |
| 87 | _Py_IDENTIFIER(op); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 88 | static char *AugAssign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 89 | "target", |
| 90 | "op", |
| 91 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 92 | }; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 93 | static PyTypeObject *AnnAssign_type; |
| 94 | _Py_IDENTIFIER(annotation); |
| 95 | _Py_IDENTIFIER(simple); |
| 96 | static char *AnnAssign_fields[]={ |
| 97 | "target", |
| 98 | "annotation", |
| 99 | "value", |
| 100 | "simple", |
| 101 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 102 | static PyTypeObject *For_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 103 | _Py_IDENTIFIER(iter); |
| 104 | _Py_IDENTIFIER(orelse); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 105 | static char *For_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 106 | "target", |
| 107 | "iter", |
| 108 | "body", |
| 109 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 110 | }; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 111 | static PyTypeObject *AsyncFor_type; |
| 112 | static char *AsyncFor_fields[]={ |
| 113 | "target", |
| 114 | "iter", |
| 115 | "body", |
| 116 | "orelse", |
| 117 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 118 | static PyTypeObject *While_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 119 | _Py_IDENTIFIER(test); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 120 | static char *While_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 121 | "test", |
| 122 | "body", |
| 123 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 124 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 125 | static PyTypeObject *If_type; |
| 126 | static char *If_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 127 | "test", |
| 128 | "body", |
| 129 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 130 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 131 | static PyTypeObject *With_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 132 | _Py_IDENTIFIER(items); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 133 | static char *With_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 134 | "items", |
| 135 | "body", |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 136 | }; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 137 | static PyTypeObject *AsyncWith_type; |
| 138 | static char *AsyncWith_fields[]={ |
| 139 | "items", |
| 140 | "body", |
| 141 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 142 | static PyTypeObject *Raise_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 143 | _Py_IDENTIFIER(exc); |
| 144 | _Py_IDENTIFIER(cause); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 145 | static char *Raise_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 146 | "exc", |
| 147 | "cause", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 148 | }; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 149 | static PyTypeObject *Try_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 150 | _Py_IDENTIFIER(handlers); |
| 151 | _Py_IDENTIFIER(finalbody); |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 152 | static char *Try_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 153 | "body", |
| 154 | "handlers", |
| 155 | "orelse", |
| 156 | "finalbody", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 157 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 158 | static PyTypeObject *Assert_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 159 | _Py_IDENTIFIER(msg); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 160 | static char *Assert_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 161 | "test", |
| 162 | "msg", |
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 *Import_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 165 | _Py_IDENTIFIER(names); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 166 | static char *Import_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 167 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 168 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 169 | static PyTypeObject *ImportFrom_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 170 | _Py_IDENTIFIER(module); |
| 171 | _Py_IDENTIFIER(level); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 172 | static char *ImportFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 173 | "module", |
| 174 | "names", |
| 175 | "level", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 176 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 177 | static PyTypeObject *Global_type; |
| 178 | static char *Global_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 179 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 180 | }; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 181 | static PyTypeObject *Nonlocal_type; |
| 182 | static char *Nonlocal_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 183 | "names", |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 184 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 185 | static PyTypeObject *Expr_type; |
| 186 | static char *Expr_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 187 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 188 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 189 | static PyTypeObject *Pass_type; |
| 190 | static PyTypeObject *Break_type; |
| 191 | static PyTypeObject *Continue_type; |
| 192 | static PyTypeObject *expr_type; |
| 193 | static char *expr_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 194 | "lineno", |
| 195 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 196 | "end_lineno", |
| 197 | "end_col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 198 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 199 | static PyObject* ast2obj_expr(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 200 | static PyTypeObject *BoolOp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 201 | _Py_IDENTIFIER(values); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 202 | static char *BoolOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 203 | "op", |
| 204 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 205 | }; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 206 | static PyTypeObject *NamedExpr_type; |
| 207 | static char *NamedExpr_fields[]={ |
| 208 | "target", |
| 209 | "value", |
| 210 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 211 | static PyTypeObject *BinOp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 212 | _Py_IDENTIFIER(left); |
| 213 | _Py_IDENTIFIER(right); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 214 | static char *BinOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 215 | "left", |
| 216 | "op", |
| 217 | "right", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 218 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 219 | static PyTypeObject *UnaryOp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 220 | _Py_IDENTIFIER(operand); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 221 | static char *UnaryOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 222 | "op", |
| 223 | "operand", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 224 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 225 | static PyTypeObject *Lambda_type; |
| 226 | static char *Lambda_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 227 | "args", |
| 228 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 229 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 230 | static PyTypeObject *IfExp_type; |
| 231 | static char *IfExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 232 | "test", |
| 233 | "body", |
| 234 | "orelse", |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 235 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 236 | static PyTypeObject *Dict_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 237 | _Py_IDENTIFIER(keys); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 238 | static char *Dict_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 239 | "keys", |
| 240 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 241 | }; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 242 | static PyTypeObject *Set_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 243 | _Py_IDENTIFIER(elts); |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 244 | static char *Set_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 245 | "elts", |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 246 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 247 | static PyTypeObject *ListComp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 248 | _Py_IDENTIFIER(elt); |
| 249 | _Py_IDENTIFIER(generators); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 250 | static char *ListComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 251 | "elt", |
| 252 | "generators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 253 | }; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 254 | static PyTypeObject *SetComp_type; |
| 255 | static char *SetComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 256 | "elt", |
| 257 | "generators", |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 258 | }; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 259 | static PyTypeObject *DictComp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 260 | _Py_IDENTIFIER(key); |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 261 | static char *DictComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 262 | "key", |
| 263 | "value", |
| 264 | "generators", |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 265 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 266 | static PyTypeObject *GeneratorExp_type; |
| 267 | static char *GeneratorExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 268 | "elt", |
| 269 | "generators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 270 | }; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 271 | static PyTypeObject *Await_type; |
| 272 | static char *Await_fields[]={ |
| 273 | "value", |
| 274 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 275 | static PyTypeObject *Yield_type; |
| 276 | static char *Yield_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 277 | "value", |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 278 | }; |
| 279 | static PyTypeObject *YieldFrom_type; |
| 280 | static char *YieldFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 281 | "value", |
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 *Compare_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 284 | _Py_IDENTIFIER(ops); |
| 285 | _Py_IDENTIFIER(comparators); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 286 | static char *Compare_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 287 | "left", |
| 288 | "ops", |
| 289 | "comparators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 290 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 291 | static PyTypeObject *Call_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 292 | _Py_IDENTIFIER(func); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 293 | static char *Call_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 294 | "func", |
| 295 | "args", |
| 296 | "keywords", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 297 | }; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 298 | static PyTypeObject *FormattedValue_type; |
| 299 | _Py_IDENTIFIER(conversion); |
| 300 | _Py_IDENTIFIER(format_spec); |
| 301 | static char *FormattedValue_fields[]={ |
| 302 | "value", |
| 303 | "conversion", |
| 304 | "format_spec", |
| 305 | }; |
| 306 | static PyTypeObject *JoinedStr_type; |
| 307 | static char *JoinedStr_fields[]={ |
| 308 | "values", |
| 309 | }; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 310 | static PyTypeObject *Constant_type; |
| 311 | static char *Constant_fields[]={ |
| 312 | "value", |
| 313 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 314 | static PyTypeObject *Attribute_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 315 | _Py_IDENTIFIER(attr); |
| 316 | _Py_IDENTIFIER(ctx); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 317 | static char *Attribute_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 318 | "value", |
| 319 | "attr", |
| 320 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 321 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 322 | static PyTypeObject *Subscript_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 323 | _Py_IDENTIFIER(slice); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 324 | static char *Subscript_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 325 | "value", |
| 326 | "slice", |
| 327 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 328 | }; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 329 | static PyTypeObject *Starred_type; |
| 330 | static char *Starred_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 331 | "value", |
| 332 | "ctx", |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 333 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 334 | static PyTypeObject *Name_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 335 | _Py_IDENTIFIER(id); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 336 | static char *Name_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 337 | "id", |
| 338 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 339 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 340 | static PyTypeObject *List_type; |
| 341 | static char *List_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 342 | "elts", |
| 343 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 344 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 345 | static PyTypeObject *Tuple_type; |
| 346 | static char *Tuple_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 347 | "elts", |
| 348 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 349 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 350 | static PyTypeObject *expr_context_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 351 | static PyObject *Load_singleton, *Store_singleton, *Del_singleton, |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 352 | *AugLoad_singleton, *AugStore_singleton, *Param_singleton, |
| 353 | *NamedStore_singleton; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 354 | static PyObject* ast2obj_expr_context(expr_context_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 355 | static PyTypeObject *Load_type; |
| 356 | static PyTypeObject *Store_type; |
| 357 | static PyTypeObject *Del_type; |
| 358 | static PyTypeObject *AugLoad_type; |
| 359 | static PyTypeObject *AugStore_type; |
| 360 | static PyTypeObject *Param_type; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 361 | static PyTypeObject *NamedStore_type; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 362 | static PyTypeObject *slice_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 363 | static PyObject* ast2obj_slice(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 364 | static PyTypeObject *Slice_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 365 | _Py_IDENTIFIER(lower); |
| 366 | _Py_IDENTIFIER(upper); |
| 367 | _Py_IDENTIFIER(step); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 368 | static char *Slice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 369 | "lower", |
| 370 | "upper", |
| 371 | "step", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 372 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 373 | static PyTypeObject *ExtSlice_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 374 | _Py_IDENTIFIER(dims); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 375 | static char *ExtSlice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 376 | "dims", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 377 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 378 | static PyTypeObject *Index_type; |
| 379 | static char *Index_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 380 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 381 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 382 | static PyTypeObject *boolop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 383 | static PyObject *And_singleton, *Or_singleton; |
| 384 | static PyObject* ast2obj_boolop(boolop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 385 | static PyTypeObject *And_type; |
| 386 | static PyTypeObject *Or_type; |
| 387 | static PyTypeObject *operator_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 388 | static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton, |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 389 | *MatMult_singleton, *Div_singleton, *Mod_singleton, *Pow_singleton, |
| 390 | *LShift_singleton, *RShift_singleton, *BitOr_singleton, *BitXor_singleton, |
| 391 | *BitAnd_singleton, *FloorDiv_singleton; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 392 | static PyObject* ast2obj_operator(operator_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 393 | static PyTypeObject *Add_type; |
| 394 | static PyTypeObject *Sub_type; |
| 395 | static PyTypeObject *Mult_type; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 396 | static PyTypeObject *MatMult_type; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 397 | static PyTypeObject *Div_type; |
| 398 | static PyTypeObject *Mod_type; |
| 399 | static PyTypeObject *Pow_type; |
| 400 | static PyTypeObject *LShift_type; |
| 401 | static PyTypeObject *RShift_type; |
| 402 | static PyTypeObject *BitOr_type; |
| 403 | static PyTypeObject *BitXor_type; |
| 404 | static PyTypeObject *BitAnd_type; |
| 405 | static PyTypeObject *FloorDiv_type; |
| 406 | static PyTypeObject *unaryop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 407 | static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton, |
| 408 | *USub_singleton; |
| 409 | static PyObject* ast2obj_unaryop(unaryop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 410 | static PyTypeObject *Invert_type; |
| 411 | static PyTypeObject *Not_type; |
| 412 | static PyTypeObject *UAdd_type; |
| 413 | static PyTypeObject *USub_type; |
| 414 | static PyTypeObject *cmpop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 415 | static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton, |
| 416 | *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton, |
| 417 | *NotIn_singleton; |
| 418 | static PyObject* ast2obj_cmpop(cmpop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 419 | static PyTypeObject *Eq_type; |
| 420 | static PyTypeObject *NotEq_type; |
| 421 | static PyTypeObject *Lt_type; |
| 422 | static PyTypeObject *LtE_type; |
| 423 | static PyTypeObject *Gt_type; |
| 424 | static PyTypeObject *GtE_type; |
| 425 | static PyTypeObject *Is_type; |
| 426 | static PyTypeObject *IsNot_type; |
| 427 | static PyTypeObject *In_type; |
| 428 | static PyTypeObject *NotIn_type; |
| 429 | static PyTypeObject *comprehension_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 430 | static PyObject* ast2obj_comprehension(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 431 | _Py_IDENTIFIER(ifs); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 432 | _Py_IDENTIFIER(is_async); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 433 | static char *comprehension_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 434 | "target", |
| 435 | "iter", |
| 436 | "ifs", |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 437 | "is_async", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 438 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 439 | static PyTypeObject *excepthandler_type; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 440 | static char *excepthandler_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 441 | "lineno", |
| 442 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 443 | "end_lineno", |
| 444 | "end_col_offset", |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 445 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 446 | static PyObject* ast2obj_excepthandler(void*); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 447 | static PyTypeObject *ExceptHandler_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 448 | _Py_IDENTIFIER(type); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 449 | static char *ExceptHandler_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 450 | "type", |
| 451 | "name", |
| 452 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 453 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 454 | static PyTypeObject *arguments_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 455 | static PyObject* ast2obj_arguments(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 456 | _Py_IDENTIFIER(vararg); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 457 | _Py_IDENTIFIER(kwonlyargs); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 458 | _Py_IDENTIFIER(kw_defaults); |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 459 | _Py_IDENTIFIER(kwarg); |
| 460 | _Py_IDENTIFIER(defaults); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 461 | static char *arguments_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 462 | "args", |
| 463 | "vararg", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 464 | "kwonlyargs", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 465 | "kw_defaults", |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 466 | "kwarg", |
| 467 | "defaults", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 468 | }; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 469 | static PyTypeObject *arg_type; |
| 470 | static PyObject* ast2obj_arg(void*); |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 471 | static char *arg_attributes[] = { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 472 | "lineno", |
| 473 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 474 | "end_lineno", |
| 475 | "end_col_offset", |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 476 | }; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 477 | _Py_IDENTIFIER(arg); |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 478 | static char *arg_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 479 | "arg", |
| 480 | "annotation", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 481 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 482 | static PyTypeObject *keyword_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 483 | static PyObject* ast2obj_keyword(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 484 | static char *keyword_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 485 | "arg", |
| 486 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 487 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 488 | static PyTypeObject *alias_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 489 | static PyObject* ast2obj_alias(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 490 | _Py_IDENTIFIER(asname); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 491 | static char *alias_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 492 | "name", |
| 493 | "asname", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 494 | }; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 495 | static PyTypeObject *withitem_type; |
| 496 | static PyObject* ast2obj_withitem(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 497 | _Py_IDENTIFIER(context_expr); |
| 498 | _Py_IDENTIFIER(optional_vars); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 499 | static char *withitem_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 500 | "context_expr", |
| 501 | "optional_vars", |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 502 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 503 | |
| 504 | |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 505 | _Py_IDENTIFIER(_fields); |
| 506 | _Py_IDENTIFIER(_attributes); |
| 507 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 508 | typedef struct { |
Victor Stinner | 45e50de | 2012-03-13 01:17:31 +0100 | [diff] [blame] | 509 | PyObject_HEAD |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 510 | PyObject *dict; |
| 511 | } AST_object; |
| 512 | |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 513 | static void |
| 514 | ast_dealloc(AST_object *self) |
| 515 | { |
INADA Naoki | a6296d3 | 2017-08-24 14:55:17 +0900 | [diff] [blame] | 516 | /* bpo-31095: UnTrack is needed before calling any callbacks */ |
| 517 | PyObject_GC_UnTrack(self); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 518 | Py_CLEAR(self->dict); |
Antoine Pitrou | 5075074 | 2012-07-08 12:43:32 +0200 | [diff] [blame] | 519 | Py_TYPE(self)->tp_free(self); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 520 | } |
| 521 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 522 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 523 | ast_traverse(AST_object *self, visitproc visit, void *arg) |
| 524 | { |
| 525 | Py_VISIT(self->dict); |
| 526 | return 0; |
| 527 | } |
| 528 | |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 529 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 530 | ast_clear(AST_object *self) |
| 531 | { |
| 532 | Py_CLEAR(self->dict); |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 533 | return 0; |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | static int |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 537 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 538 | { |
| 539 | Py_ssize_t i, numfields = 0; |
| 540 | int res = -1; |
| 541 | PyObject *key, *value, *fields; |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 542 | if (_PyObject_LookupAttrId((PyObject*)Py_TYPE(self), &PyId__fields, &fields) < 0) { |
| 543 | goto cleanup; |
| 544 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 545 | if (fields) { |
| 546 | numfields = PySequence_Size(fields); |
| 547 | if (numfields == -1) |
| 548 | goto cleanup; |
| 549 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 550 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 551 | res = 0; /* if no error occurs, this stays 0 to the end */ |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 552 | if (numfields < PyTuple_GET_SIZE(args)) { |
| 553 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most " |
| 554 | "%zd positional argument%s", |
| 555 | Py_TYPE(self)->tp_name, |
| 556 | numfields, numfields == 1 ? "" : "s"); |
| 557 | res = -1; |
| 558 | goto cleanup; |
| 559 | } |
| 560 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
| 561 | /* cannot be reached when fields is NULL */ |
| 562 | PyObject *name = PySequence_GetItem(fields, i); |
| 563 | if (!name) { |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 564 | res = -1; |
| 565 | goto cleanup; |
| 566 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 567 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
| 568 | Py_DECREF(name); |
| 569 | if (res < 0) |
| 570 | goto cleanup; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 571 | } |
| 572 | if (kw) { |
| 573 | i = 0; /* needed by PyDict_Next */ |
| 574 | while (PyDict_Next(kw, &i, &key, &value)) { |
| 575 | res = PyObject_SetAttr(self, key, value); |
| 576 | if (res < 0) |
| 577 | goto cleanup; |
| 578 | } |
| 579 | } |
| 580 | cleanup: |
| 581 | Py_XDECREF(fields); |
| 582 | return res; |
| 583 | } |
| 584 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 585 | /* Pickling support */ |
| 586 | static PyObject * |
| 587 | ast_type_reduce(PyObject *self, PyObject *unused) |
| 588 | { |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 589 | _Py_IDENTIFIER(__dict__); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 590 | PyObject *dict; |
| 591 | if (_PyObject_LookupAttrId(self, &PyId___dict__, &dict) < 0) { |
| 592 | return NULL; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 593 | } |
| 594 | if (dict) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 595 | return Py_BuildValue("O()N", Py_TYPE(self), dict); |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 596 | } |
| 597 | return Py_BuildValue("O()", Py_TYPE(self)); |
| 598 | } |
| 599 | |
| 600 | static PyMethodDef ast_type_methods[] = { |
| 601 | {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, |
| 602 | {NULL} |
| 603 | }; |
| 604 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 605 | static PyGetSetDef ast_type_getsets[] = { |
| 606 | {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict}, |
| 607 | {NULL} |
| 608 | }; |
| 609 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 610 | static PyTypeObject AST_type = { |
| 611 | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 612 | "_ast.AST", |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 613 | sizeof(AST_object), |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 614 | 0, |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 615 | (destructor)ast_dealloc, /* tp_dealloc */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 616 | 0, /* tp_print */ |
| 617 | 0, /* tp_getattr */ |
| 618 | 0, /* tp_setattr */ |
Mark Dickinson | e94c679 | 2009-02-02 20:36:42 +0000 | [diff] [blame] | 619 | 0, /* tp_reserved */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 620 | 0, /* tp_repr */ |
| 621 | 0, /* tp_as_number */ |
| 622 | 0, /* tp_as_sequence */ |
| 623 | 0, /* tp_as_mapping */ |
| 624 | 0, /* tp_hash */ |
| 625 | 0, /* tp_call */ |
| 626 | 0, /* tp_str */ |
| 627 | PyObject_GenericGetAttr, /* tp_getattro */ |
| 628 | PyObject_GenericSetAttr, /* tp_setattro */ |
| 629 | 0, /* tp_as_buffer */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 630 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 631 | 0, /* tp_doc */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 632 | (traverseproc)ast_traverse, /* tp_traverse */ |
| 633 | (inquiry)ast_clear, /* tp_clear */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 634 | 0, /* tp_richcompare */ |
| 635 | 0, /* tp_weaklistoffset */ |
| 636 | 0, /* tp_iter */ |
| 637 | 0, /* tp_iternext */ |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 638 | ast_type_methods, /* tp_methods */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 639 | 0, /* tp_members */ |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 640 | ast_type_getsets, /* tp_getset */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 641 | 0, /* tp_base */ |
| 642 | 0, /* tp_dict */ |
| 643 | 0, /* tp_descr_get */ |
| 644 | 0, /* tp_descr_set */ |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 645 | offsetof(AST_object, dict),/* tp_dictoffset */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 646 | (initproc)ast_type_init, /* tp_init */ |
| 647 | PyType_GenericAlloc, /* tp_alloc */ |
| 648 | PyType_GenericNew, /* tp_new */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 649 | PyObject_GC_Del, /* tp_free */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 650 | }; |
| 651 | |
| 652 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 653 | static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields) |
| 654 | { |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 655 | _Py_IDENTIFIER(__module__); |
| 656 | _Py_IDENTIFIER(_ast); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 657 | PyObject *fnames, *result; |
| 658 | int i; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 659 | fnames = PyTuple_New(num_fields); |
| 660 | if (!fnames) return NULL; |
| 661 | for (i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 662 | PyObject *field = PyUnicode_FromString(fields[i]); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 663 | if (!field) { |
| 664 | Py_DECREF(fnames); |
| 665 | return NULL; |
| 666 | } |
| 667 | PyTuple_SET_ITEM(fnames, i, field); |
| 668 | } |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 669 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOO}", |
| 670 | type, base, |
| 671 | _PyUnicode_FromId(&PyId__fields), fnames, |
| 672 | _PyUnicode_FromId(&PyId___module__), |
| 673 | _PyUnicode_FromId(&PyId__ast)); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 674 | Py_DECREF(fnames); |
| 675 | return (PyTypeObject*)result; |
| 676 | } |
| 677 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 678 | static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) |
| 679 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 680 | int i, result; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 681 | PyObject *s, *l = PyTuple_New(num_fields); |
Benjamin Peterson | 3e5cd1d | 2010-06-27 21:45:24 +0000 | [diff] [blame] | 682 | if (!l) |
| 683 | return 0; |
| 684 | for (i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 685 | s = PyUnicode_FromString(attrs[i]); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 686 | if (!s) { |
| 687 | Py_DECREF(l); |
| 688 | return 0; |
| 689 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 690 | PyTuple_SET_ITEM(l, i, s); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 691 | } |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 692 | result = _PyObject_SetAttrId((PyObject*)type, &PyId__attributes, l) >= 0; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 693 | Py_DECREF(l); |
| 694 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 695 | } |
| 696 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 697 | /* Conversion AST -> Python */ |
| 698 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 699 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 700 | { |
Benjamin Peterson | 77fa937 | 2012-05-15 10:10:27 -0700 | [diff] [blame] | 701 | Py_ssize_t i, n = asdl_seq_LEN(seq); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 702 | PyObject *result = PyList_New(n); |
| 703 | PyObject *value; |
| 704 | if (!result) |
| 705 | return NULL; |
| 706 | for (i = 0; i < n; i++) { |
| 707 | value = func(asdl_seq_GET(seq, i)); |
| 708 | if (!value) { |
| 709 | Py_DECREF(result); |
| 710 | return NULL; |
| 711 | } |
| 712 | PyList_SET_ITEM(result, i, value); |
| 713 | } |
| 714 | return result; |
| 715 | } |
| 716 | |
| 717 | static PyObject* ast2obj_object(void *o) |
| 718 | { |
| 719 | if (!o) |
| 720 | o = Py_None; |
| 721 | Py_INCREF((PyObject*)o); |
| 722 | return (PyObject*)o; |
| 723 | } |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 724 | #define ast2obj_singleton ast2obj_object |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 725 | #define ast2obj_constant ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 726 | #define ast2obj_identifier ast2obj_object |
| 727 | #define ast2obj_string ast2obj_object |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 728 | #define ast2obj_bytes ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 729 | |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 730 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 731 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 732 | return PyLong_FromLong(b); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 733 | } |
| 734 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 735 | /* Conversion Python -> AST */ |
| 736 | |
| 737 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 738 | { |
| 739 | if (obj == Py_None) |
| 740 | obj = NULL; |
Christian Heimes | 70c94e7 | 2013-07-27 00:33:13 +0200 | [diff] [blame] | 741 | if (obj) { |
| 742 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 743 | *out = NULL; |
| 744 | return -1; |
| 745 | } |
| 746 | Py_INCREF(obj); |
| 747 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 748 | *out = obj; |
| 749 | return 0; |
| 750 | } |
| 751 | |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 752 | static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena) |
| 753 | { |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 754 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 755 | *out = NULL; |
| 756 | return -1; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 757 | } |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 758 | Py_INCREF(obj); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 759 | *out = obj; |
| 760 | return 0; |
| 761 | } |
| 762 | |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 763 | static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 764 | { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 765 | if (!PyUnicode_CheckExact(obj) && obj != Py_None) { |
| 766 | PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 767 | return 1; |
| 768 | } |
| 769 | return obj2ast_object(obj, out, arena); |
| 770 | } |
| 771 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 772 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 773 | { |
| 774 | int i; |
| 775 | if (!PyLong_Check(obj)) { |
Amaury Forgeot d'Arc | 5e8f810 | 2011-11-22 21:52:30 +0100 | [diff] [blame] | 776 | PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 777 | return 1; |
| 778 | } |
| 779 | |
Serhiy Storchaka | 56f6e76 | 2015-09-06 21:25:30 +0300 | [diff] [blame] | 780 | i = _PyLong_AsInt(obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 781 | if (i == -1 && PyErr_Occurred()) |
| 782 | return 1; |
| 783 | *out = i; |
| 784 | return 0; |
| 785 | } |
| 786 | |
Benjamin Peterson | 1a6e0d0 | 2008-10-25 15:49:17 +0000 | [diff] [blame] | 787 | static int add_ast_fields(void) |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 788 | { |
| 789 | PyObject *empty_tuple, *d; |
| 790 | if (PyType_Ready(&AST_type) < 0) |
| 791 | return -1; |
| 792 | d = AST_type.tp_dict; |
| 793 | empty_tuple = PyTuple_New(0); |
| 794 | if (!empty_tuple || |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 795 | _PyDict_SetItemId(d, &PyId__fields, empty_tuple) < 0 || |
| 796 | _PyDict_SetItemId(d, &PyId__attributes, empty_tuple) < 0) { |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 797 | Py_XDECREF(empty_tuple); |
| 798 | return -1; |
| 799 | } |
| 800 | Py_DECREF(empty_tuple); |
| 801 | return 0; |
| 802 | } |
| 803 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 804 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 805 | static int init_types(void) |
| 806 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 807 | static int initialized; |
| 808 | if (initialized) return 1; |
| 809 | if (add_ast_fields() < 0) return 0; |
| 810 | mod_type = make_type("mod", &AST_type, NULL, 0); |
| 811 | if (!mod_type) return 0; |
| 812 | if (!add_attributes(mod_type, NULL, 0)) return 0; |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 813 | Module_type = make_type("Module", mod_type, Module_fields, 1); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 814 | if (!Module_type) return 0; |
| 815 | Interactive_type = make_type("Interactive", mod_type, Interactive_fields, |
| 816 | 1); |
| 817 | if (!Interactive_type) return 0; |
| 818 | Expression_type = make_type("Expression", mod_type, Expression_fields, 1); |
| 819 | if (!Expression_type) return 0; |
| 820 | Suite_type = make_type("Suite", mod_type, Suite_fields, 1); |
| 821 | if (!Suite_type) return 0; |
| 822 | stmt_type = make_type("stmt", &AST_type, NULL, 0); |
| 823 | if (!stmt_type) return 0; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 824 | if (!add_attributes(stmt_type, stmt_attributes, 4)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 825 | FunctionDef_type = make_type("FunctionDef", stmt_type, FunctionDef_fields, |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 826 | 5); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 827 | if (!FunctionDef_type) return 0; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 828 | AsyncFunctionDef_type = make_type("AsyncFunctionDef", stmt_type, |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 829 | AsyncFunctionDef_fields, 5); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 830 | if (!AsyncFunctionDef_type) return 0; |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 831 | ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 5); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 832 | if (!ClassDef_type) return 0; |
| 833 | Return_type = make_type("Return", stmt_type, Return_fields, 1); |
| 834 | if (!Return_type) return 0; |
| 835 | Delete_type = make_type("Delete", stmt_type, Delete_fields, 1); |
| 836 | if (!Delete_type) return 0; |
| 837 | Assign_type = make_type("Assign", stmt_type, Assign_fields, 2); |
| 838 | if (!Assign_type) return 0; |
| 839 | AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); |
| 840 | if (!AugAssign_type) return 0; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 841 | AnnAssign_type = make_type("AnnAssign", stmt_type, AnnAssign_fields, 4); |
| 842 | if (!AnnAssign_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 843 | For_type = make_type("For", stmt_type, For_fields, 4); |
| 844 | if (!For_type) return 0; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 845 | AsyncFor_type = make_type("AsyncFor", stmt_type, AsyncFor_fields, 4); |
| 846 | if (!AsyncFor_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 847 | While_type = make_type("While", stmt_type, While_fields, 3); |
| 848 | if (!While_type) return 0; |
| 849 | If_type = make_type("If", stmt_type, If_fields, 3); |
| 850 | if (!If_type) return 0; |
| 851 | With_type = make_type("With", stmt_type, With_fields, 2); |
| 852 | if (!With_type) return 0; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 853 | AsyncWith_type = make_type("AsyncWith", stmt_type, AsyncWith_fields, 2); |
| 854 | if (!AsyncWith_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 855 | Raise_type = make_type("Raise", stmt_type, Raise_fields, 2); |
| 856 | if (!Raise_type) return 0; |
| 857 | Try_type = make_type("Try", stmt_type, Try_fields, 4); |
| 858 | if (!Try_type) return 0; |
| 859 | Assert_type = make_type("Assert", stmt_type, Assert_fields, 2); |
| 860 | if (!Assert_type) return 0; |
| 861 | Import_type = make_type("Import", stmt_type, Import_fields, 1); |
| 862 | if (!Import_type) return 0; |
| 863 | ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, 3); |
| 864 | if (!ImportFrom_type) return 0; |
| 865 | Global_type = make_type("Global", stmt_type, Global_fields, 1); |
| 866 | if (!Global_type) return 0; |
| 867 | Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1); |
| 868 | if (!Nonlocal_type) return 0; |
| 869 | Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); |
| 870 | if (!Expr_type) return 0; |
| 871 | Pass_type = make_type("Pass", stmt_type, NULL, 0); |
| 872 | if (!Pass_type) return 0; |
| 873 | Break_type = make_type("Break", stmt_type, NULL, 0); |
| 874 | if (!Break_type) return 0; |
| 875 | Continue_type = make_type("Continue", stmt_type, NULL, 0); |
| 876 | if (!Continue_type) return 0; |
| 877 | expr_type = make_type("expr", &AST_type, NULL, 0); |
| 878 | if (!expr_type) return 0; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 879 | if (!add_attributes(expr_type, expr_attributes, 4)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 880 | BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2); |
| 881 | if (!BoolOp_type) return 0; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 882 | NamedExpr_type = make_type("NamedExpr", expr_type, NamedExpr_fields, 2); |
| 883 | if (!NamedExpr_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 884 | BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3); |
| 885 | if (!BinOp_type) return 0; |
| 886 | UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2); |
| 887 | if (!UnaryOp_type) return 0; |
| 888 | Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2); |
| 889 | if (!Lambda_type) return 0; |
| 890 | IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); |
| 891 | if (!IfExp_type) return 0; |
| 892 | Dict_type = make_type("Dict", expr_type, Dict_fields, 2); |
| 893 | if (!Dict_type) return 0; |
| 894 | Set_type = make_type("Set", expr_type, Set_fields, 1); |
| 895 | if (!Set_type) return 0; |
| 896 | ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); |
| 897 | if (!ListComp_type) return 0; |
| 898 | SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2); |
| 899 | if (!SetComp_type) return 0; |
| 900 | DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3); |
| 901 | if (!DictComp_type) return 0; |
| 902 | GeneratorExp_type = make_type("GeneratorExp", expr_type, |
| 903 | GeneratorExp_fields, 2); |
| 904 | if (!GeneratorExp_type) return 0; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 905 | Await_type = make_type("Await", expr_type, Await_fields, 1); |
| 906 | if (!Await_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 907 | Yield_type = make_type("Yield", expr_type, Yield_fields, 1); |
| 908 | if (!Yield_type) return 0; |
| 909 | YieldFrom_type = make_type("YieldFrom", expr_type, YieldFrom_fields, 1); |
| 910 | if (!YieldFrom_type) return 0; |
| 911 | Compare_type = make_type("Compare", expr_type, Compare_fields, 3); |
| 912 | if (!Compare_type) return 0; |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 913 | Call_type = make_type("Call", expr_type, Call_fields, 3); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 914 | if (!Call_type) return 0; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 915 | FormattedValue_type = make_type("FormattedValue", expr_type, |
| 916 | FormattedValue_fields, 3); |
| 917 | if (!FormattedValue_type) return 0; |
| 918 | JoinedStr_type = make_type("JoinedStr", expr_type, JoinedStr_fields, 1); |
| 919 | if (!JoinedStr_type) return 0; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 920 | Constant_type = make_type("Constant", expr_type, Constant_fields, 1); |
| 921 | if (!Constant_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 922 | Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); |
| 923 | if (!Attribute_type) return 0; |
| 924 | Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); |
| 925 | if (!Subscript_type) return 0; |
| 926 | Starred_type = make_type("Starred", expr_type, Starred_fields, 2); |
| 927 | if (!Starred_type) return 0; |
| 928 | Name_type = make_type("Name", expr_type, Name_fields, 2); |
| 929 | if (!Name_type) return 0; |
| 930 | List_type = make_type("List", expr_type, List_fields, 2); |
| 931 | if (!List_type) return 0; |
| 932 | Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2); |
| 933 | if (!Tuple_type) return 0; |
| 934 | expr_context_type = make_type("expr_context", &AST_type, NULL, 0); |
| 935 | if (!expr_context_type) return 0; |
| 936 | if (!add_attributes(expr_context_type, NULL, 0)) return 0; |
| 937 | Load_type = make_type("Load", expr_context_type, NULL, 0); |
| 938 | if (!Load_type) return 0; |
| 939 | Load_singleton = PyType_GenericNew(Load_type, NULL, NULL); |
| 940 | if (!Load_singleton) return 0; |
| 941 | Store_type = make_type("Store", expr_context_type, NULL, 0); |
| 942 | if (!Store_type) return 0; |
| 943 | Store_singleton = PyType_GenericNew(Store_type, NULL, NULL); |
| 944 | if (!Store_singleton) return 0; |
| 945 | Del_type = make_type("Del", expr_context_type, NULL, 0); |
| 946 | if (!Del_type) return 0; |
| 947 | Del_singleton = PyType_GenericNew(Del_type, NULL, NULL); |
| 948 | if (!Del_singleton) return 0; |
| 949 | AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0); |
| 950 | if (!AugLoad_type) return 0; |
| 951 | AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL); |
| 952 | if (!AugLoad_singleton) return 0; |
| 953 | AugStore_type = make_type("AugStore", expr_context_type, NULL, 0); |
| 954 | if (!AugStore_type) return 0; |
| 955 | AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL); |
| 956 | if (!AugStore_singleton) return 0; |
| 957 | Param_type = make_type("Param", expr_context_type, NULL, 0); |
| 958 | if (!Param_type) return 0; |
| 959 | Param_singleton = PyType_GenericNew(Param_type, NULL, NULL); |
| 960 | if (!Param_singleton) return 0; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 961 | NamedStore_type = make_type("NamedStore", expr_context_type, NULL, 0); |
| 962 | if (!NamedStore_type) return 0; |
| 963 | NamedStore_singleton = PyType_GenericNew(NamedStore_type, NULL, NULL); |
| 964 | if (!NamedStore_singleton) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 965 | slice_type = make_type("slice", &AST_type, NULL, 0); |
| 966 | if (!slice_type) return 0; |
| 967 | if (!add_attributes(slice_type, NULL, 0)) return 0; |
| 968 | Slice_type = make_type("Slice", slice_type, Slice_fields, 3); |
| 969 | if (!Slice_type) return 0; |
| 970 | ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); |
| 971 | if (!ExtSlice_type) return 0; |
| 972 | Index_type = make_type("Index", slice_type, Index_fields, 1); |
| 973 | if (!Index_type) return 0; |
| 974 | boolop_type = make_type("boolop", &AST_type, NULL, 0); |
| 975 | if (!boolop_type) return 0; |
| 976 | if (!add_attributes(boolop_type, NULL, 0)) return 0; |
| 977 | And_type = make_type("And", boolop_type, NULL, 0); |
| 978 | if (!And_type) return 0; |
| 979 | And_singleton = PyType_GenericNew(And_type, NULL, NULL); |
| 980 | if (!And_singleton) return 0; |
| 981 | Or_type = make_type("Or", boolop_type, NULL, 0); |
| 982 | if (!Or_type) return 0; |
| 983 | Or_singleton = PyType_GenericNew(Or_type, NULL, NULL); |
| 984 | if (!Or_singleton) return 0; |
| 985 | operator_type = make_type("operator", &AST_type, NULL, 0); |
| 986 | if (!operator_type) return 0; |
| 987 | if (!add_attributes(operator_type, NULL, 0)) return 0; |
| 988 | Add_type = make_type("Add", operator_type, NULL, 0); |
| 989 | if (!Add_type) return 0; |
| 990 | Add_singleton = PyType_GenericNew(Add_type, NULL, NULL); |
| 991 | if (!Add_singleton) return 0; |
| 992 | Sub_type = make_type("Sub", operator_type, NULL, 0); |
| 993 | if (!Sub_type) return 0; |
| 994 | Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL); |
| 995 | if (!Sub_singleton) return 0; |
| 996 | Mult_type = make_type("Mult", operator_type, NULL, 0); |
| 997 | if (!Mult_type) return 0; |
| 998 | Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL); |
| 999 | if (!Mult_singleton) return 0; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 1000 | MatMult_type = make_type("MatMult", operator_type, NULL, 0); |
| 1001 | if (!MatMult_type) return 0; |
| 1002 | MatMult_singleton = PyType_GenericNew(MatMult_type, NULL, NULL); |
| 1003 | if (!MatMult_singleton) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1004 | Div_type = make_type("Div", operator_type, NULL, 0); |
| 1005 | if (!Div_type) return 0; |
| 1006 | Div_singleton = PyType_GenericNew(Div_type, NULL, NULL); |
| 1007 | if (!Div_singleton) return 0; |
| 1008 | Mod_type = make_type("Mod", operator_type, NULL, 0); |
| 1009 | if (!Mod_type) return 0; |
| 1010 | Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL); |
| 1011 | if (!Mod_singleton) return 0; |
| 1012 | Pow_type = make_type("Pow", operator_type, NULL, 0); |
| 1013 | if (!Pow_type) return 0; |
| 1014 | Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL); |
| 1015 | if (!Pow_singleton) return 0; |
| 1016 | LShift_type = make_type("LShift", operator_type, NULL, 0); |
| 1017 | if (!LShift_type) return 0; |
| 1018 | LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL); |
| 1019 | if (!LShift_singleton) return 0; |
| 1020 | RShift_type = make_type("RShift", operator_type, NULL, 0); |
| 1021 | if (!RShift_type) return 0; |
| 1022 | RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL); |
| 1023 | if (!RShift_singleton) return 0; |
| 1024 | BitOr_type = make_type("BitOr", operator_type, NULL, 0); |
| 1025 | if (!BitOr_type) return 0; |
| 1026 | BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL); |
| 1027 | if (!BitOr_singleton) return 0; |
| 1028 | BitXor_type = make_type("BitXor", operator_type, NULL, 0); |
| 1029 | if (!BitXor_type) return 0; |
| 1030 | BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL); |
| 1031 | if (!BitXor_singleton) return 0; |
| 1032 | BitAnd_type = make_type("BitAnd", operator_type, NULL, 0); |
| 1033 | if (!BitAnd_type) return 0; |
| 1034 | BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL); |
| 1035 | if (!BitAnd_singleton) return 0; |
| 1036 | FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0); |
| 1037 | if (!FloorDiv_type) return 0; |
| 1038 | FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL); |
| 1039 | if (!FloorDiv_singleton) return 0; |
| 1040 | unaryop_type = make_type("unaryop", &AST_type, NULL, 0); |
| 1041 | if (!unaryop_type) return 0; |
| 1042 | if (!add_attributes(unaryop_type, NULL, 0)) return 0; |
| 1043 | Invert_type = make_type("Invert", unaryop_type, NULL, 0); |
| 1044 | if (!Invert_type) return 0; |
| 1045 | Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL); |
| 1046 | if (!Invert_singleton) return 0; |
| 1047 | Not_type = make_type("Not", unaryop_type, NULL, 0); |
| 1048 | if (!Not_type) return 0; |
| 1049 | Not_singleton = PyType_GenericNew(Not_type, NULL, NULL); |
| 1050 | if (!Not_singleton) return 0; |
| 1051 | UAdd_type = make_type("UAdd", unaryop_type, NULL, 0); |
| 1052 | if (!UAdd_type) return 0; |
| 1053 | UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL); |
| 1054 | if (!UAdd_singleton) return 0; |
| 1055 | USub_type = make_type("USub", unaryop_type, NULL, 0); |
| 1056 | if (!USub_type) return 0; |
| 1057 | USub_singleton = PyType_GenericNew(USub_type, NULL, NULL); |
| 1058 | if (!USub_singleton) return 0; |
| 1059 | cmpop_type = make_type("cmpop", &AST_type, NULL, 0); |
| 1060 | if (!cmpop_type) return 0; |
| 1061 | if (!add_attributes(cmpop_type, NULL, 0)) return 0; |
| 1062 | Eq_type = make_type("Eq", cmpop_type, NULL, 0); |
| 1063 | if (!Eq_type) return 0; |
| 1064 | Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL); |
| 1065 | if (!Eq_singleton) return 0; |
| 1066 | NotEq_type = make_type("NotEq", cmpop_type, NULL, 0); |
| 1067 | if (!NotEq_type) return 0; |
| 1068 | NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL); |
| 1069 | if (!NotEq_singleton) return 0; |
| 1070 | Lt_type = make_type("Lt", cmpop_type, NULL, 0); |
| 1071 | if (!Lt_type) return 0; |
| 1072 | Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL); |
| 1073 | if (!Lt_singleton) return 0; |
| 1074 | LtE_type = make_type("LtE", cmpop_type, NULL, 0); |
| 1075 | if (!LtE_type) return 0; |
| 1076 | LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL); |
| 1077 | if (!LtE_singleton) return 0; |
| 1078 | Gt_type = make_type("Gt", cmpop_type, NULL, 0); |
| 1079 | if (!Gt_type) return 0; |
| 1080 | Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL); |
| 1081 | if (!Gt_singleton) return 0; |
| 1082 | GtE_type = make_type("GtE", cmpop_type, NULL, 0); |
| 1083 | if (!GtE_type) return 0; |
| 1084 | GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL); |
| 1085 | if (!GtE_singleton) return 0; |
| 1086 | Is_type = make_type("Is", cmpop_type, NULL, 0); |
| 1087 | if (!Is_type) return 0; |
| 1088 | Is_singleton = PyType_GenericNew(Is_type, NULL, NULL); |
| 1089 | if (!Is_singleton) return 0; |
| 1090 | IsNot_type = make_type("IsNot", cmpop_type, NULL, 0); |
| 1091 | if (!IsNot_type) return 0; |
| 1092 | IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL); |
| 1093 | if (!IsNot_singleton) return 0; |
| 1094 | In_type = make_type("In", cmpop_type, NULL, 0); |
| 1095 | if (!In_type) return 0; |
| 1096 | In_singleton = PyType_GenericNew(In_type, NULL, NULL); |
| 1097 | if (!In_singleton) return 0; |
| 1098 | NotIn_type = make_type("NotIn", cmpop_type, NULL, 0); |
| 1099 | if (!NotIn_type) return 0; |
| 1100 | NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL); |
| 1101 | if (!NotIn_singleton) return 0; |
| 1102 | comprehension_type = make_type("comprehension", &AST_type, |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 1103 | comprehension_fields, 4); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1104 | if (!comprehension_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1105 | if (!add_attributes(comprehension_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1106 | excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0); |
| 1107 | if (!excepthandler_type) return 0; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1108 | if (!add_attributes(excepthandler_type, excepthandler_attributes, 4)) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1109 | return 0; |
| 1110 | ExceptHandler_type = make_type("ExceptHandler", excepthandler_type, |
| 1111 | ExceptHandler_fields, 3); |
| 1112 | if (!ExceptHandler_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1113 | arguments_type = make_type("arguments", &AST_type, arguments_fields, 6); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1114 | if (!arguments_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1115 | if (!add_attributes(arguments_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1116 | arg_type = make_type("arg", &AST_type, arg_fields, 2); |
| 1117 | if (!arg_type) return 0; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1118 | if (!add_attributes(arg_type, arg_attributes, 4)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1119 | keyword_type = make_type("keyword", &AST_type, keyword_fields, 2); |
| 1120 | if (!keyword_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1121 | if (!add_attributes(keyword_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1122 | alias_type = make_type("alias", &AST_type, alias_fields, 2); |
| 1123 | if (!alias_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1124 | if (!add_attributes(alias_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1125 | withitem_type = make_type("withitem", &AST_type, withitem_fields, 2); |
| 1126 | if (!withitem_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1127 | if (!add_attributes(withitem_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1128 | initialized = 1; |
| 1129 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1130 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 1131 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1132 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 1133 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 1134 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 1135 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 1136 | arena); |
| 1137 | static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena); |
| 1138 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 1139 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 1140 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 1141 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 1142 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 1143 | arena); |
| 1144 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 1145 | arena); |
| 1146 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 1147 | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
| 1148 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 1149 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1150 | 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] | 1151 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1152 | mod_ty |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 1153 | Module(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1154 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1155 | mod_ty p; |
| 1156 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1157 | if (!p) |
| 1158 | return NULL; |
| 1159 | p->kind = Module_kind; |
| 1160 | p->v.Module.body = body; |
| 1161 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1162 | } |
| 1163 | |
| 1164 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1165 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1166 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1167 | mod_ty p; |
| 1168 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1169 | if (!p) |
| 1170 | return NULL; |
| 1171 | p->kind = Interactive_kind; |
| 1172 | p->v.Interactive.body = body; |
| 1173 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1177 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1178 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1179 | mod_ty p; |
| 1180 | if (!body) { |
| 1181 | PyErr_SetString(PyExc_ValueError, |
| 1182 | "field body is required for Expression"); |
| 1183 | return NULL; |
| 1184 | } |
| 1185 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1186 | if (!p) |
| 1187 | return NULL; |
| 1188 | p->kind = Expression_kind; |
| 1189 | p->v.Expression.body = body; |
| 1190 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1194 | Suite(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1195 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1196 | mod_ty p; |
| 1197 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1198 | if (!p) |
| 1199 | return NULL; |
| 1200 | p->kind = Suite_kind; |
| 1201 | p->v.Suite.body = body; |
| 1202 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | stmt_ty |
| 1206 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1207 | decorator_list, expr_ty returns, int lineno, int col_offset, int |
| 1208 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1209 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1210 | stmt_ty p; |
| 1211 | if (!name) { |
| 1212 | PyErr_SetString(PyExc_ValueError, |
| 1213 | "field name is required for FunctionDef"); |
| 1214 | return NULL; |
| 1215 | } |
| 1216 | if (!args) { |
| 1217 | PyErr_SetString(PyExc_ValueError, |
| 1218 | "field args is required for FunctionDef"); |
| 1219 | return NULL; |
| 1220 | } |
| 1221 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1222 | if (!p) |
| 1223 | return NULL; |
| 1224 | p->kind = FunctionDef_kind; |
| 1225 | p->v.FunctionDef.name = name; |
| 1226 | p->v.FunctionDef.args = args; |
| 1227 | p->v.FunctionDef.body = body; |
| 1228 | p->v.FunctionDef.decorator_list = decorator_list; |
| 1229 | p->v.FunctionDef.returns = returns; |
| 1230 | p->lineno = lineno; |
| 1231 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1232 | p->end_lineno = end_lineno; |
| 1233 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1234 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | stmt_ty |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1238 | AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 1239 | * decorator_list, expr_ty returns, int lineno, int col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1240 | int end_lineno, int end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1241 | { |
| 1242 | stmt_ty p; |
| 1243 | if (!name) { |
| 1244 | PyErr_SetString(PyExc_ValueError, |
| 1245 | "field name is required for AsyncFunctionDef"); |
| 1246 | return NULL; |
| 1247 | } |
| 1248 | if (!args) { |
| 1249 | PyErr_SetString(PyExc_ValueError, |
| 1250 | "field args is required for AsyncFunctionDef"); |
| 1251 | return NULL; |
| 1252 | } |
| 1253 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1254 | if (!p) |
| 1255 | return NULL; |
| 1256 | p->kind = AsyncFunctionDef_kind; |
| 1257 | p->v.AsyncFunctionDef.name = name; |
| 1258 | p->v.AsyncFunctionDef.args = args; |
| 1259 | p->v.AsyncFunctionDef.body = body; |
| 1260 | p->v.AsyncFunctionDef.decorator_list = decorator_list; |
| 1261 | p->v.AsyncFunctionDef.returns = returns; |
| 1262 | p->lineno = lineno; |
| 1263 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1264 | p->end_lineno = end_lineno; |
| 1265 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1266 | return p; |
| 1267 | } |
| 1268 | |
| 1269 | stmt_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 1270 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1271 | body, asdl_seq * decorator_list, int lineno, int col_offset, int |
| 1272 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1273 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1274 | stmt_ty p; |
| 1275 | if (!name) { |
| 1276 | PyErr_SetString(PyExc_ValueError, |
| 1277 | "field name is required for ClassDef"); |
| 1278 | return NULL; |
| 1279 | } |
| 1280 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1281 | if (!p) |
| 1282 | return NULL; |
| 1283 | p->kind = ClassDef_kind; |
| 1284 | p->v.ClassDef.name = name; |
| 1285 | p->v.ClassDef.bases = bases; |
| 1286 | p->v.ClassDef.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1287 | p->v.ClassDef.body = body; |
| 1288 | p->v.ClassDef.decorator_list = decorator_list; |
| 1289 | p->lineno = lineno; |
| 1290 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1291 | p->end_lineno = end_lineno; |
| 1292 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1293 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1294 | } |
| 1295 | |
| 1296 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1297 | Return(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 1298 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1299 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1300 | stmt_ty p; |
| 1301 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1302 | if (!p) |
| 1303 | return NULL; |
| 1304 | p->kind = Return_kind; |
| 1305 | p->v.Return.value = value; |
| 1306 | p->lineno = lineno; |
| 1307 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1308 | p->end_lineno = end_lineno; |
| 1309 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1310 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1311 | } |
| 1312 | |
| 1313 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1314 | Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int |
| 1315 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1316 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1317 | stmt_ty p; |
| 1318 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1319 | if (!p) |
| 1320 | return NULL; |
| 1321 | p->kind = Delete_kind; |
| 1322 | p->v.Delete.targets = targets; |
| 1323 | p->lineno = lineno; |
| 1324 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1325 | p->end_lineno = end_lineno; |
| 1326 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1327 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1328 | } |
| 1329 | |
| 1330 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1331 | Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, int |
| 1332 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1333 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1334 | stmt_ty p; |
| 1335 | if (!value) { |
| 1336 | PyErr_SetString(PyExc_ValueError, |
| 1337 | "field value is required for Assign"); |
| 1338 | return NULL; |
| 1339 | } |
| 1340 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1341 | if (!p) |
| 1342 | return NULL; |
| 1343 | p->kind = Assign_kind; |
| 1344 | p->v.Assign.targets = targets; |
| 1345 | p->v.Assign.value = value; |
| 1346 | p->lineno = lineno; |
| 1347 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1348 | p->end_lineno = end_lineno; |
| 1349 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1350 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1354 | AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1355 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1356 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1357 | stmt_ty p; |
| 1358 | if (!target) { |
| 1359 | PyErr_SetString(PyExc_ValueError, |
| 1360 | "field target is required for AugAssign"); |
| 1361 | return NULL; |
| 1362 | } |
| 1363 | if (!op) { |
| 1364 | PyErr_SetString(PyExc_ValueError, |
| 1365 | "field op is required for AugAssign"); |
| 1366 | return NULL; |
| 1367 | } |
| 1368 | if (!value) { |
| 1369 | PyErr_SetString(PyExc_ValueError, |
| 1370 | "field value is required for AugAssign"); |
| 1371 | return NULL; |
| 1372 | } |
| 1373 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1374 | if (!p) |
| 1375 | return NULL; |
| 1376 | p->kind = AugAssign_kind; |
| 1377 | p->v.AugAssign.target = target; |
| 1378 | p->v.AugAssign.op = op; |
| 1379 | p->v.AugAssign.value = value; |
| 1380 | p->lineno = lineno; |
| 1381 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1382 | p->end_lineno = end_lineno; |
| 1383 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1384 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1385 | } |
| 1386 | |
| 1387 | stmt_ty |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 1388 | AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1389 | lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 1390 | *arena) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 1391 | { |
| 1392 | stmt_ty p; |
| 1393 | if (!target) { |
| 1394 | PyErr_SetString(PyExc_ValueError, |
| 1395 | "field target is required for AnnAssign"); |
| 1396 | return NULL; |
| 1397 | } |
| 1398 | if (!annotation) { |
| 1399 | PyErr_SetString(PyExc_ValueError, |
| 1400 | "field annotation is required for AnnAssign"); |
| 1401 | return NULL; |
| 1402 | } |
| 1403 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1404 | if (!p) |
| 1405 | return NULL; |
| 1406 | p->kind = AnnAssign_kind; |
| 1407 | p->v.AnnAssign.target = target; |
| 1408 | p->v.AnnAssign.annotation = annotation; |
| 1409 | p->v.AnnAssign.value = value; |
| 1410 | p->v.AnnAssign.simple = simple; |
| 1411 | p->lineno = lineno; |
| 1412 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1413 | p->end_lineno = end_lineno; |
| 1414 | p->end_col_offset = end_col_offset; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 1415 | return p; |
| 1416 | } |
| 1417 | |
| 1418 | stmt_ty |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1419 | For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1420 | lineno, int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1421 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1422 | stmt_ty p; |
| 1423 | if (!target) { |
| 1424 | PyErr_SetString(PyExc_ValueError, |
| 1425 | "field target is required for For"); |
| 1426 | return NULL; |
| 1427 | } |
| 1428 | if (!iter) { |
| 1429 | PyErr_SetString(PyExc_ValueError, |
| 1430 | "field iter is required for For"); |
| 1431 | return NULL; |
| 1432 | } |
| 1433 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1434 | if (!p) |
| 1435 | return NULL; |
| 1436 | p->kind = For_kind; |
| 1437 | p->v.For.target = target; |
| 1438 | p->v.For.iter = iter; |
| 1439 | p->v.For.body = body; |
| 1440 | p->v.For.orelse = orelse; |
| 1441 | p->lineno = lineno; |
| 1442 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1443 | p->end_lineno = end_lineno; |
| 1444 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1445 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | stmt_ty |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1449 | AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1450 | lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 1451 | *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1452 | { |
| 1453 | stmt_ty p; |
| 1454 | if (!target) { |
| 1455 | PyErr_SetString(PyExc_ValueError, |
| 1456 | "field target is required for AsyncFor"); |
| 1457 | return NULL; |
| 1458 | } |
| 1459 | if (!iter) { |
| 1460 | PyErr_SetString(PyExc_ValueError, |
| 1461 | "field iter is required for AsyncFor"); |
| 1462 | return NULL; |
| 1463 | } |
| 1464 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1465 | if (!p) |
| 1466 | return NULL; |
| 1467 | p->kind = AsyncFor_kind; |
| 1468 | p->v.AsyncFor.target = target; |
| 1469 | p->v.AsyncFor.iter = iter; |
| 1470 | p->v.AsyncFor.body = body; |
| 1471 | p->v.AsyncFor.orelse = orelse; |
| 1472 | p->lineno = lineno; |
| 1473 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1474 | p->end_lineno = end_lineno; |
| 1475 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1476 | return p; |
| 1477 | } |
| 1478 | |
| 1479 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1480 | While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1481 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1482 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1483 | stmt_ty p; |
| 1484 | if (!test) { |
| 1485 | PyErr_SetString(PyExc_ValueError, |
| 1486 | "field test is required for While"); |
| 1487 | return NULL; |
| 1488 | } |
| 1489 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1490 | if (!p) |
| 1491 | return NULL; |
| 1492 | p->kind = While_kind; |
| 1493 | p->v.While.test = test; |
| 1494 | p->v.While.body = body; |
| 1495 | p->v.While.orelse = orelse; |
| 1496 | p->lineno = lineno; |
| 1497 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1498 | p->end_lineno = end_lineno; |
| 1499 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1500 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1504 | If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1505 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1506 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1507 | stmt_ty p; |
| 1508 | if (!test) { |
| 1509 | PyErr_SetString(PyExc_ValueError, |
| 1510 | "field test is required for If"); |
| 1511 | return NULL; |
| 1512 | } |
| 1513 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1514 | if (!p) |
| 1515 | return NULL; |
| 1516 | p->kind = If_kind; |
| 1517 | p->v.If.test = test; |
| 1518 | p->v.If.body = body; |
| 1519 | p->v.If.orelse = orelse; |
| 1520 | p->lineno = lineno; |
| 1521 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1522 | p->end_lineno = end_lineno; |
| 1523 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1524 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1525 | } |
| 1526 | |
| 1527 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1528 | With(asdl_seq * items, asdl_seq * body, int lineno, int col_offset, int |
| 1529 | end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1530 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1531 | stmt_ty p; |
| 1532 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1533 | if (!p) |
| 1534 | return NULL; |
| 1535 | p->kind = With_kind; |
| 1536 | p->v.With.items = items; |
| 1537 | p->v.With.body = body; |
| 1538 | p->lineno = lineno; |
| 1539 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1540 | p->end_lineno = end_lineno; |
| 1541 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1542 | return p; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1543 | } |
| 1544 | |
| 1545 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1546 | AsyncWith(asdl_seq * items, asdl_seq * body, int lineno, int col_offset, int |
| 1547 | end_lineno, int end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1548 | { |
| 1549 | stmt_ty p; |
| 1550 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1551 | if (!p) |
| 1552 | return NULL; |
| 1553 | p->kind = AsyncWith_kind; |
| 1554 | p->v.AsyncWith.items = items; |
| 1555 | p->v.AsyncWith.body = body; |
| 1556 | p->lineno = lineno; |
| 1557 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1558 | p->end_lineno = end_lineno; |
| 1559 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1560 | return p; |
| 1561 | } |
| 1562 | |
| 1563 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1564 | Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno, |
| 1565 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1566 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1567 | stmt_ty p; |
| 1568 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1569 | if (!p) |
| 1570 | return NULL; |
| 1571 | p->kind = Raise_kind; |
| 1572 | p->v.Raise.exc = exc; |
| 1573 | p->v.Raise.cause = cause; |
| 1574 | p->lineno = lineno; |
| 1575 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1576 | p->end_lineno = end_lineno; |
| 1577 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1578 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | stmt_ty |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 1582 | Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1583 | finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 1584 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1585 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1586 | stmt_ty p; |
| 1587 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1588 | if (!p) |
| 1589 | return NULL; |
| 1590 | p->kind = Try_kind; |
| 1591 | p->v.Try.body = body; |
| 1592 | p->v.Try.handlers = handlers; |
| 1593 | p->v.Try.orelse = orelse; |
| 1594 | p->v.Try.finalbody = finalbody; |
| 1595 | p->lineno = lineno; |
| 1596 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1597 | p->end_lineno = end_lineno; |
| 1598 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1599 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1600 | } |
| 1601 | |
| 1602 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1603 | Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno, |
| 1604 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1605 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1606 | stmt_ty p; |
| 1607 | if (!test) { |
| 1608 | PyErr_SetString(PyExc_ValueError, |
| 1609 | "field test is required for Assert"); |
| 1610 | return NULL; |
| 1611 | } |
| 1612 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1613 | if (!p) |
| 1614 | return NULL; |
| 1615 | p->kind = Assert_kind; |
| 1616 | p->v.Assert.test = test; |
| 1617 | p->v.Assert.msg = msg; |
| 1618 | p->lineno = lineno; |
| 1619 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1620 | p->end_lineno = end_lineno; |
| 1621 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1622 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1623 | } |
| 1624 | |
| 1625 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1626 | Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 1627 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1628 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1629 | stmt_ty p; |
| 1630 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1631 | if (!p) |
| 1632 | return NULL; |
| 1633 | p->kind = Import_kind; |
| 1634 | p->v.Import.names = names; |
| 1635 | p->lineno = lineno; |
| 1636 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1637 | p->end_lineno = end_lineno; |
| 1638 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1639 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1640 | } |
| 1641 | |
| 1642 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1643 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1644 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1645 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1646 | stmt_ty p; |
| 1647 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1648 | if (!p) |
| 1649 | return NULL; |
| 1650 | p->kind = ImportFrom_kind; |
| 1651 | p->v.ImportFrom.module = module; |
| 1652 | p->v.ImportFrom.names = names; |
| 1653 | p->v.ImportFrom.level = level; |
| 1654 | p->lineno = lineno; |
| 1655 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1656 | p->end_lineno = end_lineno; |
| 1657 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1658 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1659 | } |
| 1660 | |
| 1661 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1662 | Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 1663 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1664 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1665 | stmt_ty p; |
| 1666 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1667 | if (!p) |
| 1668 | return NULL; |
| 1669 | p->kind = Global_kind; |
| 1670 | p->v.Global.names = names; |
| 1671 | p->lineno = lineno; |
| 1672 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1673 | p->end_lineno = end_lineno; |
| 1674 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1675 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1676 | } |
| 1677 | |
| 1678 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1679 | Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 1680 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 1681 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1682 | stmt_ty p; |
| 1683 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1684 | if (!p) |
| 1685 | return NULL; |
| 1686 | p->kind = Nonlocal_kind; |
| 1687 | p->v.Nonlocal.names = names; |
| 1688 | p->lineno = lineno; |
| 1689 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1690 | p->end_lineno = end_lineno; |
| 1691 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1692 | return p; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 1693 | } |
| 1694 | |
| 1695 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1696 | Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 1697 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1698 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1699 | stmt_ty p; |
| 1700 | if (!value) { |
| 1701 | PyErr_SetString(PyExc_ValueError, |
| 1702 | "field value is required for Expr"); |
| 1703 | return NULL; |
| 1704 | } |
| 1705 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1706 | if (!p) |
| 1707 | return NULL; |
| 1708 | p->kind = Expr_kind; |
| 1709 | p->v.Expr.value = value; |
| 1710 | p->lineno = lineno; |
| 1711 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1712 | p->end_lineno = end_lineno; |
| 1713 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1714 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1718 | Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 1719 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1720 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1721 | stmt_ty p; |
| 1722 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1723 | if (!p) |
| 1724 | return NULL; |
| 1725 | p->kind = Pass_kind; |
| 1726 | p->lineno = lineno; |
| 1727 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1728 | p->end_lineno = end_lineno; |
| 1729 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1730 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1731 | } |
| 1732 | |
| 1733 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1734 | Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 1735 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1736 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1737 | stmt_ty p; |
| 1738 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1739 | if (!p) |
| 1740 | return NULL; |
| 1741 | p->kind = Break_kind; |
| 1742 | p->lineno = lineno; |
| 1743 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1744 | p->end_lineno = end_lineno; |
| 1745 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1746 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1747 | } |
| 1748 | |
| 1749 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1750 | Continue(int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 1751 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1752 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1753 | stmt_ty p; |
| 1754 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1755 | if (!p) |
| 1756 | return NULL; |
| 1757 | p->kind = Continue_kind; |
| 1758 | p->lineno = lineno; |
| 1759 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1760 | p->end_lineno = end_lineno; |
| 1761 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1762 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1766 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int |
| 1767 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1768 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1769 | expr_ty p; |
| 1770 | if (!op) { |
| 1771 | PyErr_SetString(PyExc_ValueError, |
| 1772 | "field op is required for BoolOp"); |
| 1773 | return NULL; |
| 1774 | } |
| 1775 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1776 | if (!p) |
| 1777 | return NULL; |
| 1778 | p->kind = BoolOp_kind; |
| 1779 | p->v.BoolOp.op = op; |
| 1780 | p->v.BoolOp.values = values; |
| 1781 | p->lineno = lineno; |
| 1782 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1783 | p->end_lineno = end_lineno; |
| 1784 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1785 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | expr_ty |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 1789 | NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int |
| 1790 | end_lineno, int end_col_offset, PyArena *arena) |
| 1791 | { |
| 1792 | expr_ty p; |
| 1793 | if (!target) { |
| 1794 | PyErr_SetString(PyExc_ValueError, |
| 1795 | "field target is required for NamedExpr"); |
| 1796 | return NULL; |
| 1797 | } |
| 1798 | if (!value) { |
| 1799 | PyErr_SetString(PyExc_ValueError, |
| 1800 | "field value is required for NamedExpr"); |
| 1801 | return NULL; |
| 1802 | } |
| 1803 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1804 | if (!p) |
| 1805 | return NULL; |
| 1806 | p->kind = NamedExpr_kind; |
| 1807 | p->v.NamedExpr.target = target; |
| 1808 | p->v.NamedExpr.value = value; |
| 1809 | p->lineno = lineno; |
| 1810 | p->col_offset = col_offset; |
| 1811 | p->end_lineno = end_lineno; |
| 1812 | p->end_col_offset = end_col_offset; |
| 1813 | return p; |
| 1814 | } |
| 1815 | |
| 1816 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1817 | BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1818 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1819 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1820 | expr_ty p; |
| 1821 | if (!left) { |
| 1822 | PyErr_SetString(PyExc_ValueError, |
| 1823 | "field left is required for BinOp"); |
| 1824 | return NULL; |
| 1825 | } |
| 1826 | if (!op) { |
| 1827 | PyErr_SetString(PyExc_ValueError, |
| 1828 | "field op is required for BinOp"); |
| 1829 | return NULL; |
| 1830 | } |
| 1831 | if (!right) { |
| 1832 | PyErr_SetString(PyExc_ValueError, |
| 1833 | "field right is required for BinOp"); |
| 1834 | return NULL; |
| 1835 | } |
| 1836 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1837 | if (!p) |
| 1838 | return NULL; |
| 1839 | p->kind = BinOp_kind; |
| 1840 | p->v.BinOp.left = left; |
| 1841 | p->v.BinOp.op = op; |
| 1842 | p->v.BinOp.right = right; |
| 1843 | p->lineno = lineno; |
| 1844 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1845 | p->end_lineno = end_lineno; |
| 1846 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1847 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1848 | } |
| 1849 | |
| 1850 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1851 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int |
| 1852 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1853 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1854 | expr_ty p; |
| 1855 | if (!op) { |
| 1856 | PyErr_SetString(PyExc_ValueError, |
| 1857 | "field op is required for UnaryOp"); |
| 1858 | return NULL; |
| 1859 | } |
| 1860 | if (!operand) { |
| 1861 | PyErr_SetString(PyExc_ValueError, |
| 1862 | "field operand is required for UnaryOp"); |
| 1863 | return NULL; |
| 1864 | } |
| 1865 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1866 | if (!p) |
| 1867 | return NULL; |
| 1868 | p->kind = UnaryOp_kind; |
| 1869 | p->v.UnaryOp.op = op; |
| 1870 | p->v.UnaryOp.operand = operand; |
| 1871 | p->lineno = lineno; |
| 1872 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1873 | p->end_lineno = end_lineno; |
| 1874 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1875 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1876 | } |
| 1877 | |
| 1878 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1879 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int |
| 1880 | end_lineno, int end_col_offset, 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 (!args) { |
| 1884 | PyErr_SetString(PyExc_ValueError, |
| 1885 | "field args is required for Lambda"); |
| 1886 | return NULL; |
| 1887 | } |
| 1888 | if (!body) { |
| 1889 | PyErr_SetString(PyExc_ValueError, |
| 1890 | "field body is required for Lambda"); |
| 1891 | return NULL; |
| 1892 | } |
| 1893 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1894 | if (!p) |
| 1895 | return NULL; |
| 1896 | p->kind = Lambda_kind; |
| 1897 | p->v.Lambda.args = args; |
| 1898 | p->v.Lambda.body = body; |
| 1899 | p->lineno = lineno; |
| 1900 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1901 | p->end_lineno = end_lineno; |
| 1902 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1903 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1904 | } |
| 1905 | |
| 1906 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1907 | IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1908 | int end_lineno, int end_col_offset, PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1909 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1910 | expr_ty p; |
| 1911 | if (!test) { |
| 1912 | PyErr_SetString(PyExc_ValueError, |
| 1913 | "field test is required for IfExp"); |
| 1914 | return NULL; |
| 1915 | } |
| 1916 | if (!body) { |
| 1917 | PyErr_SetString(PyExc_ValueError, |
| 1918 | "field body is required for IfExp"); |
| 1919 | return NULL; |
| 1920 | } |
| 1921 | if (!orelse) { |
| 1922 | PyErr_SetString(PyExc_ValueError, |
| 1923 | "field orelse is required for IfExp"); |
| 1924 | return NULL; |
| 1925 | } |
| 1926 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1927 | if (!p) |
| 1928 | return NULL; |
| 1929 | p->kind = IfExp_kind; |
| 1930 | p->v.IfExp.test = test; |
| 1931 | p->v.IfExp.body = body; |
| 1932 | p->v.IfExp.orelse = orelse; |
| 1933 | p->lineno = lineno; |
| 1934 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1935 | p->end_lineno = end_lineno; |
| 1936 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1937 | return p; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1938 | } |
| 1939 | |
| 1940 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1941 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int |
| 1942 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1943 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1944 | expr_ty p; |
| 1945 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1946 | if (!p) |
| 1947 | return NULL; |
| 1948 | p->kind = Dict_kind; |
| 1949 | p->v.Dict.keys = keys; |
| 1950 | p->v.Dict.values = values; |
| 1951 | p->lineno = lineno; |
| 1952 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1953 | p->end_lineno = end_lineno; |
| 1954 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1955 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1959 | Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int |
| 1960 | end_col_offset, PyArena *arena) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1961 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1962 | expr_ty p; |
| 1963 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1964 | if (!p) |
| 1965 | return NULL; |
| 1966 | p->kind = Set_kind; |
| 1967 | p->v.Set.elts = elts; |
| 1968 | p->lineno = lineno; |
| 1969 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1970 | p->end_lineno = end_lineno; |
| 1971 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1972 | return p; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1973 | } |
| 1974 | |
| 1975 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1976 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 1977 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1978 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1979 | expr_ty p; |
| 1980 | if (!elt) { |
| 1981 | PyErr_SetString(PyExc_ValueError, |
| 1982 | "field elt is required for ListComp"); |
| 1983 | return NULL; |
| 1984 | } |
| 1985 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1986 | if (!p) |
| 1987 | return NULL; |
| 1988 | p->kind = ListComp_kind; |
| 1989 | p->v.ListComp.elt = elt; |
| 1990 | p->v.ListComp.generators = generators; |
| 1991 | p->lineno = lineno; |
| 1992 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1993 | p->end_lineno = end_lineno; |
| 1994 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1995 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1996 | } |
| 1997 | |
| 1998 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1999 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 2000 | end_lineno, int end_col_offset, PyArena *arena) |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2001 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2002 | expr_ty p; |
| 2003 | if (!elt) { |
| 2004 | PyErr_SetString(PyExc_ValueError, |
| 2005 | "field elt is required for SetComp"); |
| 2006 | return NULL; |
| 2007 | } |
| 2008 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2009 | if (!p) |
| 2010 | return NULL; |
| 2011 | p->kind = SetComp_kind; |
| 2012 | p->v.SetComp.elt = elt; |
| 2013 | p->v.SetComp.generators = generators; |
| 2014 | p->lineno = lineno; |
| 2015 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2016 | p->end_lineno = end_lineno; |
| 2017 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2018 | return p; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2019 | } |
| 2020 | |
| 2021 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2022 | DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2023 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2024 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2025 | expr_ty p; |
| 2026 | if (!key) { |
| 2027 | PyErr_SetString(PyExc_ValueError, |
| 2028 | "field key is required for DictComp"); |
| 2029 | return NULL; |
| 2030 | } |
| 2031 | if (!value) { |
| 2032 | PyErr_SetString(PyExc_ValueError, |
| 2033 | "field value is required for DictComp"); |
| 2034 | return NULL; |
| 2035 | } |
| 2036 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2037 | if (!p) |
| 2038 | return NULL; |
| 2039 | p->kind = DictComp_kind; |
| 2040 | p->v.DictComp.key = key; |
| 2041 | p->v.DictComp.value = value; |
| 2042 | p->v.DictComp.generators = generators; |
| 2043 | p->lineno = lineno; |
| 2044 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2045 | p->end_lineno = end_lineno; |
| 2046 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2047 | return p; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2048 | } |
| 2049 | |
| 2050 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2051 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2052 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2053 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2054 | expr_ty p; |
| 2055 | if (!elt) { |
| 2056 | PyErr_SetString(PyExc_ValueError, |
| 2057 | "field elt is required for GeneratorExp"); |
| 2058 | return NULL; |
| 2059 | } |
| 2060 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2061 | if (!p) |
| 2062 | return NULL; |
| 2063 | p->kind = GeneratorExp_kind; |
| 2064 | p->v.GeneratorExp.elt = elt; |
| 2065 | p->v.GeneratorExp.generators = generators; |
| 2066 | p->lineno = lineno; |
| 2067 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2068 | p->end_lineno = end_lineno; |
| 2069 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2070 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2071 | } |
| 2072 | |
| 2073 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2074 | Await(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2075 | end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2076 | { |
| 2077 | expr_ty p; |
| 2078 | if (!value) { |
| 2079 | PyErr_SetString(PyExc_ValueError, |
| 2080 | "field value is required for Await"); |
| 2081 | return NULL; |
| 2082 | } |
| 2083 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2084 | if (!p) |
| 2085 | return NULL; |
| 2086 | p->kind = Await_kind; |
| 2087 | p->v.Await.value = value; |
| 2088 | p->lineno = lineno; |
| 2089 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2090 | p->end_lineno = end_lineno; |
| 2091 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2092 | return p; |
| 2093 | } |
| 2094 | |
| 2095 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2096 | Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2097 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2098 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2099 | expr_ty p; |
| 2100 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2101 | if (!p) |
| 2102 | return NULL; |
| 2103 | p->kind = Yield_kind; |
| 2104 | p->v.Yield.value = value; |
| 2105 | p->lineno = lineno; |
| 2106 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2107 | p->end_lineno = end_lineno; |
| 2108 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2109 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2110 | } |
| 2111 | |
| 2112 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2113 | YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2114 | end_col_offset, PyArena *arena) |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2115 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2116 | expr_ty p; |
| 2117 | if (!value) { |
| 2118 | PyErr_SetString(PyExc_ValueError, |
| 2119 | "field value is required for YieldFrom"); |
| 2120 | return NULL; |
| 2121 | } |
| 2122 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2123 | if (!p) |
| 2124 | return NULL; |
| 2125 | p->kind = YieldFrom_kind; |
| 2126 | p->v.YieldFrom.value = value; |
| 2127 | p->lineno = lineno; |
| 2128 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2129 | p->end_lineno = end_lineno; |
| 2130 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2131 | return p; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2132 | } |
| 2133 | |
| 2134 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2135 | Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2136 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2137 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2138 | expr_ty p; |
| 2139 | if (!left) { |
| 2140 | PyErr_SetString(PyExc_ValueError, |
| 2141 | "field left is required for Compare"); |
| 2142 | return NULL; |
| 2143 | } |
| 2144 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2145 | if (!p) |
| 2146 | return NULL; |
| 2147 | p->kind = Compare_kind; |
| 2148 | p->v.Compare.left = left; |
| 2149 | p->v.Compare.ops = ops; |
| 2150 | p->v.Compare.comparators = comparators; |
| 2151 | p->lineno = lineno; |
| 2152 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2153 | p->end_lineno = end_lineno; |
| 2154 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2155 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2156 | } |
| 2157 | |
| 2158 | expr_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 2159 | Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2160 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2161 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2162 | expr_ty p; |
| 2163 | if (!func) { |
| 2164 | PyErr_SetString(PyExc_ValueError, |
| 2165 | "field func is required for Call"); |
| 2166 | return NULL; |
| 2167 | } |
| 2168 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2169 | if (!p) |
| 2170 | return NULL; |
| 2171 | p->kind = Call_kind; |
| 2172 | p->v.Call.func = func; |
| 2173 | p->v.Call.args = args; |
| 2174 | p->v.Call.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2175 | p->lineno = lineno; |
| 2176 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2177 | p->end_lineno = end_lineno; |
| 2178 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2179 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2180 | } |
| 2181 | |
| 2182 | expr_ty |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2183 | FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2184 | int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2185 | *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2186 | { |
| 2187 | expr_ty p; |
| 2188 | if (!value) { |
| 2189 | PyErr_SetString(PyExc_ValueError, |
| 2190 | "field value is required for FormattedValue"); |
| 2191 | return NULL; |
| 2192 | } |
| 2193 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2194 | if (!p) |
| 2195 | return NULL; |
| 2196 | p->kind = FormattedValue_kind; |
| 2197 | p->v.FormattedValue.value = value; |
| 2198 | p->v.FormattedValue.conversion = conversion; |
| 2199 | p->v.FormattedValue.format_spec = format_spec; |
| 2200 | p->lineno = lineno; |
| 2201 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2202 | p->end_lineno = end_lineno; |
| 2203 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2204 | return p; |
| 2205 | } |
| 2206 | |
| 2207 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2208 | JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int |
| 2209 | end_col_offset, PyArena *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2210 | { |
| 2211 | expr_ty p; |
| 2212 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2213 | if (!p) |
| 2214 | return NULL; |
| 2215 | p->kind = JoinedStr_kind; |
| 2216 | p->v.JoinedStr.values = values; |
| 2217 | p->lineno = lineno; |
| 2218 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2219 | p->end_lineno = end_lineno; |
| 2220 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2221 | return p; |
| 2222 | } |
| 2223 | |
| 2224 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2225 | Constant(constant value, int lineno, int col_offset, int end_lineno, int |
| 2226 | end_col_offset, PyArena *arena) |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 2227 | { |
| 2228 | expr_ty p; |
| 2229 | if (!value) { |
| 2230 | PyErr_SetString(PyExc_ValueError, |
| 2231 | "field value is required for Constant"); |
| 2232 | return NULL; |
| 2233 | } |
| 2234 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2235 | if (!p) |
| 2236 | return NULL; |
| 2237 | p->kind = Constant_kind; |
| 2238 | p->v.Constant.value = value; |
| 2239 | p->lineno = lineno; |
| 2240 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2241 | p->end_lineno = end_lineno; |
| 2242 | p->end_col_offset = end_col_offset; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 2243 | return p; |
| 2244 | } |
| 2245 | |
| 2246 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2247 | Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2248 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2249 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2250 | expr_ty p; |
| 2251 | if (!value) { |
| 2252 | PyErr_SetString(PyExc_ValueError, |
| 2253 | "field value is required for Attribute"); |
| 2254 | return NULL; |
| 2255 | } |
| 2256 | if (!attr) { |
| 2257 | PyErr_SetString(PyExc_ValueError, |
| 2258 | "field attr is required for Attribute"); |
| 2259 | return NULL; |
| 2260 | } |
| 2261 | if (!ctx) { |
| 2262 | PyErr_SetString(PyExc_ValueError, |
| 2263 | "field ctx is required for Attribute"); |
| 2264 | return NULL; |
| 2265 | } |
| 2266 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2267 | if (!p) |
| 2268 | return NULL; |
| 2269 | p->kind = Attribute_kind; |
| 2270 | p->v.Attribute.value = value; |
| 2271 | p->v.Attribute.attr = attr; |
| 2272 | p->v.Attribute.ctx = ctx; |
| 2273 | p->lineno = lineno; |
| 2274 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2275 | p->end_lineno = end_lineno; |
| 2276 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2277 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2278 | } |
| 2279 | |
| 2280 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2281 | Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2282 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2283 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2284 | expr_ty p; |
| 2285 | if (!value) { |
| 2286 | PyErr_SetString(PyExc_ValueError, |
| 2287 | "field value is required for Subscript"); |
| 2288 | return NULL; |
| 2289 | } |
| 2290 | if (!slice) { |
| 2291 | PyErr_SetString(PyExc_ValueError, |
| 2292 | "field slice is required for Subscript"); |
| 2293 | return NULL; |
| 2294 | } |
| 2295 | if (!ctx) { |
| 2296 | PyErr_SetString(PyExc_ValueError, |
| 2297 | "field ctx is required for Subscript"); |
| 2298 | return NULL; |
| 2299 | } |
| 2300 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2301 | if (!p) |
| 2302 | return NULL; |
| 2303 | p->kind = Subscript_kind; |
| 2304 | p->v.Subscript.value = value; |
| 2305 | p->v.Subscript.slice = slice; |
| 2306 | p->v.Subscript.ctx = ctx; |
| 2307 | p->lineno = lineno; |
| 2308 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2309 | p->end_lineno = end_lineno; |
| 2310 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2311 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2312 | } |
| 2313 | |
| 2314 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2315 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int |
| 2316 | end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2317 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2318 | expr_ty p; |
| 2319 | if (!value) { |
| 2320 | PyErr_SetString(PyExc_ValueError, |
| 2321 | "field value is required for Starred"); |
| 2322 | return NULL; |
| 2323 | } |
| 2324 | if (!ctx) { |
| 2325 | PyErr_SetString(PyExc_ValueError, |
| 2326 | "field ctx is required for Starred"); |
| 2327 | return NULL; |
| 2328 | } |
| 2329 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2330 | if (!p) |
| 2331 | return NULL; |
| 2332 | p->kind = Starred_kind; |
| 2333 | p->v.Starred.value = value; |
| 2334 | p->v.Starred.ctx = ctx; |
| 2335 | p->lineno = lineno; |
| 2336 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2337 | p->end_lineno = end_lineno; |
| 2338 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2339 | return p; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2340 | } |
| 2341 | |
| 2342 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2343 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int |
| 2344 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2345 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2346 | expr_ty p; |
| 2347 | if (!id) { |
| 2348 | PyErr_SetString(PyExc_ValueError, |
| 2349 | "field id is required for Name"); |
| 2350 | return NULL; |
| 2351 | } |
| 2352 | if (!ctx) { |
| 2353 | PyErr_SetString(PyExc_ValueError, |
| 2354 | "field ctx is required for Name"); |
| 2355 | return NULL; |
| 2356 | } |
| 2357 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2358 | if (!p) |
| 2359 | return NULL; |
| 2360 | p->kind = Name_kind; |
| 2361 | p->v.Name.id = id; |
| 2362 | p->v.Name.ctx = ctx; |
| 2363 | p->lineno = lineno; |
| 2364 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2365 | p->end_lineno = end_lineno; |
| 2366 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2367 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2368 | } |
| 2369 | |
| 2370 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2371 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 2372 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2373 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2374 | expr_ty p; |
| 2375 | if (!ctx) { |
| 2376 | PyErr_SetString(PyExc_ValueError, |
| 2377 | "field ctx is required for List"); |
| 2378 | return NULL; |
| 2379 | } |
| 2380 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2381 | if (!p) |
| 2382 | return NULL; |
| 2383 | p->kind = List_kind; |
| 2384 | p->v.List.elts = elts; |
| 2385 | p->v.List.ctx = ctx; |
| 2386 | p->lineno = lineno; |
| 2387 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2388 | p->end_lineno = end_lineno; |
| 2389 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2390 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2391 | } |
| 2392 | |
| 2393 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2394 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 2395 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2396 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2397 | expr_ty p; |
| 2398 | if (!ctx) { |
| 2399 | PyErr_SetString(PyExc_ValueError, |
| 2400 | "field ctx is required for Tuple"); |
| 2401 | return NULL; |
| 2402 | } |
| 2403 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2404 | if (!p) |
| 2405 | return NULL; |
| 2406 | p->kind = Tuple_kind; |
| 2407 | p->v.Tuple.elts = elts; |
| 2408 | p->v.Tuple.ctx = ctx; |
| 2409 | p->lineno = lineno; |
| 2410 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2411 | p->end_lineno = end_lineno; |
| 2412 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2413 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2414 | } |
| 2415 | |
| 2416 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2417 | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2418 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2419 | slice_ty p; |
| 2420 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2421 | if (!p) |
| 2422 | return NULL; |
| 2423 | p->kind = Slice_kind; |
| 2424 | p->v.Slice.lower = lower; |
| 2425 | p->v.Slice.upper = upper; |
| 2426 | p->v.Slice.step = step; |
| 2427 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2428 | } |
| 2429 | |
| 2430 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2431 | ExtSlice(asdl_seq * dims, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2432 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2433 | slice_ty p; |
| 2434 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2435 | if (!p) |
| 2436 | return NULL; |
| 2437 | p->kind = ExtSlice_kind; |
| 2438 | p->v.ExtSlice.dims = dims; |
| 2439 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2440 | } |
| 2441 | |
| 2442 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2443 | Index(expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2444 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2445 | slice_ty p; |
| 2446 | if (!value) { |
| 2447 | PyErr_SetString(PyExc_ValueError, |
| 2448 | "field value is required for Index"); |
| 2449 | return NULL; |
| 2450 | } |
| 2451 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2452 | if (!p) |
| 2453 | return NULL; |
| 2454 | p->kind = Index_kind; |
| 2455 | p->v.Index.value = value; |
| 2456 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2457 | } |
| 2458 | |
| 2459 | comprehension_ty |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 2460 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async, |
| 2461 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2462 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2463 | comprehension_ty p; |
| 2464 | if (!target) { |
| 2465 | PyErr_SetString(PyExc_ValueError, |
| 2466 | "field target is required for comprehension"); |
| 2467 | return NULL; |
| 2468 | } |
| 2469 | if (!iter) { |
| 2470 | PyErr_SetString(PyExc_ValueError, |
| 2471 | "field iter is required for comprehension"); |
| 2472 | return NULL; |
| 2473 | } |
| 2474 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2475 | if (!p) |
| 2476 | return NULL; |
| 2477 | p->target = target; |
| 2478 | p->iter = iter; |
| 2479 | p->ifs = ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 2480 | p->is_async = is_async; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2481 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2482 | } |
| 2483 | |
| 2484 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 2485 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2486 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2487 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2488 | excepthandler_ty p; |
| 2489 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2490 | if (!p) |
| 2491 | return NULL; |
| 2492 | p->kind = ExceptHandler_kind; |
| 2493 | p->v.ExceptHandler.type = type; |
| 2494 | p->v.ExceptHandler.name = name; |
| 2495 | p->v.ExceptHandler.body = body; |
| 2496 | p->lineno = lineno; |
| 2497 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2498 | p->end_lineno = end_lineno; |
| 2499 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2500 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2501 | } |
| 2502 | |
| 2503 | arguments_ty |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 2504 | arguments(asdl_seq * args, arg_ty vararg, asdl_seq * kwonlyargs, asdl_seq * |
| 2505 | kw_defaults, arg_ty kwarg, asdl_seq * defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2506 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2507 | arguments_ty p; |
| 2508 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2509 | if (!p) |
| 2510 | return NULL; |
| 2511 | p->args = args; |
| 2512 | p->vararg = vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2513 | p->kwonlyargs = kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2514 | p->kw_defaults = kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 2515 | p->kwarg = kwarg; |
| 2516 | p->defaults = defaults; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2517 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2518 | } |
| 2519 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2520 | arg_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2521 | arg(identifier arg, expr_ty annotation, int lineno, int col_offset, int |
| 2522 | end_lineno, int end_col_offset, PyArena *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2523 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2524 | arg_ty p; |
| 2525 | if (!arg) { |
| 2526 | PyErr_SetString(PyExc_ValueError, |
| 2527 | "field arg is required for arg"); |
| 2528 | return NULL; |
| 2529 | } |
| 2530 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2531 | if (!p) |
| 2532 | return NULL; |
| 2533 | p->arg = arg; |
| 2534 | p->annotation = annotation; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 2535 | p->lineno = lineno; |
| 2536 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2537 | p->end_lineno = end_lineno; |
| 2538 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2539 | return p; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2540 | } |
| 2541 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2542 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2543 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2544 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2545 | keyword_ty p; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2546 | if (!value) { |
| 2547 | PyErr_SetString(PyExc_ValueError, |
| 2548 | "field value is required for keyword"); |
| 2549 | return NULL; |
| 2550 | } |
| 2551 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2552 | if (!p) |
| 2553 | return NULL; |
| 2554 | p->arg = arg; |
| 2555 | p->value = value; |
| 2556 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2557 | } |
| 2558 | |
| 2559 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2560 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2561 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2562 | alias_ty p; |
| 2563 | if (!name) { |
| 2564 | PyErr_SetString(PyExc_ValueError, |
| 2565 | "field name is required for alias"); |
| 2566 | return NULL; |
| 2567 | } |
| 2568 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2569 | if (!p) |
| 2570 | return NULL; |
| 2571 | p->name = name; |
| 2572 | p->asname = asname; |
| 2573 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2574 | } |
| 2575 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2576 | withitem_ty |
| 2577 | withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) |
| 2578 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2579 | withitem_ty p; |
| 2580 | if (!context_expr) { |
| 2581 | PyErr_SetString(PyExc_ValueError, |
| 2582 | "field context_expr is required for withitem"); |
| 2583 | return NULL; |
| 2584 | } |
| 2585 | p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2586 | if (!p) |
| 2587 | return NULL; |
| 2588 | p->context_expr = context_expr; |
| 2589 | p->optional_vars = optional_vars; |
| 2590 | return p; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2591 | } |
| 2592 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2593 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2594 | PyObject* |
| 2595 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2596 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2597 | mod_ty o = (mod_ty)_o; |
| 2598 | PyObject *result = NULL, *value = NULL; |
| 2599 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 2600 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2601 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2602 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2603 | switch (o->kind) { |
| 2604 | case Module_kind: |
| 2605 | result = PyType_GenericNew(Module_type, NULL, NULL); |
| 2606 | if (!result) goto failed; |
| 2607 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 2608 | if (!value) goto failed; |
| 2609 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2610 | goto failed; |
| 2611 | Py_DECREF(value); |
| 2612 | break; |
| 2613 | case Interactive_kind: |
| 2614 | result = PyType_GenericNew(Interactive_type, NULL, NULL); |
| 2615 | if (!result) goto failed; |
| 2616 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 2617 | if (!value) goto failed; |
| 2618 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2619 | goto failed; |
| 2620 | Py_DECREF(value); |
| 2621 | break; |
| 2622 | case Expression_kind: |
| 2623 | result = PyType_GenericNew(Expression_type, NULL, NULL); |
| 2624 | if (!result) goto failed; |
| 2625 | value = ast2obj_expr(o->v.Expression.body); |
| 2626 | if (!value) goto failed; |
| 2627 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2628 | goto failed; |
| 2629 | Py_DECREF(value); |
| 2630 | break; |
| 2631 | case Suite_kind: |
| 2632 | result = PyType_GenericNew(Suite_type, NULL, NULL); |
| 2633 | if (!result) goto failed; |
| 2634 | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
| 2635 | if (!value) goto failed; |
| 2636 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2637 | goto failed; |
| 2638 | Py_DECREF(value); |
| 2639 | break; |
| 2640 | } |
| 2641 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2642 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2643 | Py_XDECREF(value); |
| 2644 | Py_XDECREF(result); |
| 2645 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2646 | } |
| 2647 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2648 | PyObject* |
| 2649 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2650 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2651 | stmt_ty o = (stmt_ty)_o; |
| 2652 | PyObject *result = NULL, *value = NULL; |
| 2653 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 2654 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2655 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2656 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2657 | switch (o->kind) { |
| 2658 | case FunctionDef_kind: |
| 2659 | result = PyType_GenericNew(FunctionDef_type, NULL, NULL); |
| 2660 | if (!result) goto failed; |
| 2661 | value = ast2obj_identifier(o->v.FunctionDef.name); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2662 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2663 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2664 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2665 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2666 | value = ast2obj_arguments(o->v.FunctionDef.args); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2667 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2668 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 2669 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2670 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2671 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 2672 | if (!value) goto failed; |
| 2673 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2674 | goto failed; |
| 2675 | Py_DECREF(value); |
| 2676 | value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr); |
| 2677 | if (!value) goto failed; |
| 2678 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2679 | goto failed; |
| 2680 | Py_DECREF(value); |
| 2681 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 2682 | if (!value) goto failed; |
| 2683 | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
| 2684 | goto failed; |
| 2685 | Py_DECREF(value); |
| 2686 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2687 | case AsyncFunctionDef_kind: |
| 2688 | result = PyType_GenericNew(AsyncFunctionDef_type, NULL, NULL); |
| 2689 | if (!result) goto failed; |
| 2690 | value = ast2obj_identifier(o->v.AsyncFunctionDef.name); |
| 2691 | if (!value) goto failed; |
| 2692 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2693 | goto failed; |
| 2694 | Py_DECREF(value); |
| 2695 | value = ast2obj_arguments(o->v.AsyncFunctionDef.args); |
| 2696 | if (!value) goto failed; |
| 2697 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 2698 | goto failed; |
| 2699 | Py_DECREF(value); |
| 2700 | value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt); |
| 2701 | if (!value) goto failed; |
| 2702 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2703 | goto failed; |
| 2704 | Py_DECREF(value); |
| 2705 | value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list, |
| 2706 | ast2obj_expr); |
| 2707 | if (!value) goto failed; |
| 2708 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2709 | goto failed; |
| 2710 | Py_DECREF(value); |
| 2711 | value = ast2obj_expr(o->v.AsyncFunctionDef.returns); |
| 2712 | if (!value) goto failed; |
| 2713 | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
| 2714 | goto failed; |
| 2715 | Py_DECREF(value); |
| 2716 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2717 | case ClassDef_kind: |
| 2718 | result = PyType_GenericNew(ClassDef_type, NULL, NULL); |
| 2719 | if (!result) goto failed; |
| 2720 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 2721 | if (!value) goto failed; |
| 2722 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2723 | goto failed; |
| 2724 | Py_DECREF(value); |
| 2725 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 2726 | if (!value) goto failed; |
| 2727 | if (_PyObject_SetAttrId(result, &PyId_bases, value) == -1) |
| 2728 | goto failed; |
| 2729 | Py_DECREF(value); |
| 2730 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 2731 | if (!value) goto failed; |
| 2732 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
| 2733 | goto failed; |
| 2734 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2735 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 2736 | if (!value) goto failed; |
| 2737 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2738 | goto failed; |
| 2739 | Py_DECREF(value); |
| 2740 | value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr); |
| 2741 | if (!value) goto failed; |
| 2742 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2743 | goto failed; |
| 2744 | Py_DECREF(value); |
| 2745 | break; |
| 2746 | case Return_kind: |
| 2747 | result = PyType_GenericNew(Return_type, NULL, NULL); |
| 2748 | if (!result) goto failed; |
| 2749 | value = ast2obj_expr(o->v.Return.value); |
| 2750 | if (!value) goto failed; |
| 2751 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2752 | goto failed; |
| 2753 | Py_DECREF(value); |
| 2754 | break; |
| 2755 | case Delete_kind: |
| 2756 | result = PyType_GenericNew(Delete_type, NULL, NULL); |
| 2757 | if (!result) goto failed; |
| 2758 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 2759 | if (!value) goto failed; |
| 2760 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
| 2761 | goto failed; |
| 2762 | Py_DECREF(value); |
| 2763 | break; |
| 2764 | case Assign_kind: |
| 2765 | result = PyType_GenericNew(Assign_type, NULL, NULL); |
| 2766 | if (!result) goto failed; |
| 2767 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 2768 | if (!value) goto failed; |
| 2769 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
| 2770 | goto failed; |
| 2771 | Py_DECREF(value); |
| 2772 | value = ast2obj_expr(o->v.Assign.value); |
| 2773 | if (!value) goto failed; |
| 2774 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2775 | goto failed; |
| 2776 | Py_DECREF(value); |
| 2777 | break; |
| 2778 | case AugAssign_kind: |
| 2779 | result = PyType_GenericNew(AugAssign_type, NULL, NULL); |
| 2780 | if (!result) goto failed; |
| 2781 | value = ast2obj_expr(o->v.AugAssign.target); |
| 2782 | if (!value) goto failed; |
| 2783 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2784 | goto failed; |
| 2785 | Py_DECREF(value); |
| 2786 | value = ast2obj_operator(o->v.AugAssign.op); |
| 2787 | if (!value) goto failed; |
| 2788 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 2789 | goto failed; |
| 2790 | Py_DECREF(value); |
| 2791 | value = ast2obj_expr(o->v.AugAssign.value); |
| 2792 | if (!value) goto failed; |
| 2793 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2794 | goto failed; |
| 2795 | Py_DECREF(value); |
| 2796 | break; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2797 | case AnnAssign_kind: |
| 2798 | result = PyType_GenericNew(AnnAssign_type, NULL, NULL); |
| 2799 | if (!result) goto failed; |
| 2800 | value = ast2obj_expr(o->v.AnnAssign.target); |
| 2801 | if (!value) goto failed; |
| 2802 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2803 | goto failed; |
| 2804 | Py_DECREF(value); |
| 2805 | value = ast2obj_expr(o->v.AnnAssign.annotation); |
| 2806 | if (!value) goto failed; |
| 2807 | if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) |
| 2808 | goto failed; |
| 2809 | Py_DECREF(value); |
| 2810 | value = ast2obj_expr(o->v.AnnAssign.value); |
| 2811 | if (!value) goto failed; |
| 2812 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2813 | goto failed; |
| 2814 | Py_DECREF(value); |
| 2815 | value = ast2obj_int(o->v.AnnAssign.simple); |
| 2816 | if (!value) goto failed; |
| 2817 | if (_PyObject_SetAttrId(result, &PyId_simple, value) == -1) |
| 2818 | goto failed; |
| 2819 | Py_DECREF(value); |
| 2820 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2821 | case For_kind: |
| 2822 | result = PyType_GenericNew(For_type, NULL, NULL); |
| 2823 | if (!result) goto failed; |
| 2824 | value = ast2obj_expr(o->v.For.target); |
| 2825 | if (!value) goto failed; |
| 2826 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2827 | goto failed; |
| 2828 | Py_DECREF(value); |
| 2829 | value = ast2obj_expr(o->v.For.iter); |
| 2830 | if (!value) goto failed; |
| 2831 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 2832 | goto failed; |
| 2833 | Py_DECREF(value); |
| 2834 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 2835 | if (!value) goto failed; |
| 2836 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2837 | goto failed; |
| 2838 | Py_DECREF(value); |
| 2839 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 2840 | if (!value) goto failed; |
| 2841 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2842 | goto failed; |
| 2843 | Py_DECREF(value); |
| 2844 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2845 | case AsyncFor_kind: |
| 2846 | result = PyType_GenericNew(AsyncFor_type, NULL, NULL); |
| 2847 | if (!result) goto failed; |
| 2848 | value = ast2obj_expr(o->v.AsyncFor.target); |
| 2849 | if (!value) goto failed; |
| 2850 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2851 | goto failed; |
| 2852 | Py_DECREF(value); |
| 2853 | value = ast2obj_expr(o->v.AsyncFor.iter); |
| 2854 | if (!value) goto failed; |
| 2855 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 2856 | goto failed; |
| 2857 | Py_DECREF(value); |
| 2858 | value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt); |
| 2859 | if (!value) goto failed; |
| 2860 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2861 | goto failed; |
| 2862 | Py_DECREF(value); |
| 2863 | value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt); |
| 2864 | if (!value) goto failed; |
| 2865 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2866 | goto failed; |
| 2867 | Py_DECREF(value); |
| 2868 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2869 | case While_kind: |
| 2870 | result = PyType_GenericNew(While_type, NULL, NULL); |
| 2871 | if (!result) goto failed; |
| 2872 | value = ast2obj_expr(o->v.While.test); |
| 2873 | if (!value) goto failed; |
| 2874 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 2875 | goto failed; |
| 2876 | Py_DECREF(value); |
| 2877 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 2878 | if (!value) goto failed; |
| 2879 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2880 | goto failed; |
| 2881 | Py_DECREF(value); |
| 2882 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 2883 | if (!value) goto failed; |
| 2884 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2885 | goto failed; |
| 2886 | Py_DECREF(value); |
| 2887 | break; |
| 2888 | case If_kind: |
| 2889 | result = PyType_GenericNew(If_type, NULL, NULL); |
| 2890 | if (!result) goto failed; |
| 2891 | value = ast2obj_expr(o->v.If.test); |
| 2892 | if (!value) goto failed; |
| 2893 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 2894 | goto failed; |
| 2895 | Py_DECREF(value); |
| 2896 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 2897 | if (!value) goto failed; |
| 2898 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2899 | goto failed; |
| 2900 | Py_DECREF(value); |
| 2901 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 2902 | if (!value) goto failed; |
| 2903 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2904 | goto failed; |
| 2905 | Py_DECREF(value); |
| 2906 | break; |
| 2907 | case With_kind: |
| 2908 | result = PyType_GenericNew(With_type, NULL, NULL); |
| 2909 | if (!result) goto failed; |
| 2910 | value = ast2obj_list(o->v.With.items, ast2obj_withitem); |
| 2911 | if (!value) goto failed; |
| 2912 | if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) |
| 2913 | goto failed; |
| 2914 | Py_DECREF(value); |
| 2915 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 2916 | if (!value) goto failed; |
| 2917 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2918 | goto failed; |
| 2919 | Py_DECREF(value); |
| 2920 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2921 | case AsyncWith_kind: |
| 2922 | result = PyType_GenericNew(AsyncWith_type, NULL, NULL); |
| 2923 | if (!result) goto failed; |
| 2924 | value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem); |
| 2925 | if (!value) goto failed; |
| 2926 | if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) |
| 2927 | goto failed; |
| 2928 | Py_DECREF(value); |
| 2929 | value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt); |
| 2930 | if (!value) goto failed; |
| 2931 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2932 | goto failed; |
| 2933 | Py_DECREF(value); |
| 2934 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2935 | case Raise_kind: |
| 2936 | result = PyType_GenericNew(Raise_type, NULL, NULL); |
| 2937 | if (!result) goto failed; |
| 2938 | value = ast2obj_expr(o->v.Raise.exc); |
| 2939 | if (!value) goto failed; |
| 2940 | if (_PyObject_SetAttrId(result, &PyId_exc, value) == -1) |
| 2941 | goto failed; |
| 2942 | Py_DECREF(value); |
| 2943 | value = ast2obj_expr(o->v.Raise.cause); |
| 2944 | if (!value) goto failed; |
| 2945 | if (_PyObject_SetAttrId(result, &PyId_cause, value) == -1) |
| 2946 | goto failed; |
| 2947 | Py_DECREF(value); |
| 2948 | break; |
| 2949 | case Try_kind: |
| 2950 | result = PyType_GenericNew(Try_type, NULL, NULL); |
| 2951 | if (!result) goto failed; |
| 2952 | value = ast2obj_list(o->v.Try.body, ast2obj_stmt); |
| 2953 | if (!value) goto failed; |
| 2954 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2955 | goto failed; |
| 2956 | Py_DECREF(value); |
| 2957 | value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); |
| 2958 | if (!value) goto failed; |
| 2959 | if (_PyObject_SetAttrId(result, &PyId_handlers, value) == -1) |
| 2960 | goto failed; |
| 2961 | Py_DECREF(value); |
| 2962 | value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); |
| 2963 | if (!value) goto failed; |
| 2964 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2965 | goto failed; |
| 2966 | Py_DECREF(value); |
| 2967 | value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); |
| 2968 | if (!value) goto failed; |
| 2969 | if (_PyObject_SetAttrId(result, &PyId_finalbody, value) == -1) |
| 2970 | goto failed; |
| 2971 | Py_DECREF(value); |
| 2972 | break; |
| 2973 | case Assert_kind: |
| 2974 | result = PyType_GenericNew(Assert_type, NULL, NULL); |
| 2975 | if (!result) goto failed; |
| 2976 | value = ast2obj_expr(o->v.Assert.test); |
| 2977 | if (!value) goto failed; |
| 2978 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 2979 | goto failed; |
| 2980 | Py_DECREF(value); |
| 2981 | value = ast2obj_expr(o->v.Assert.msg); |
| 2982 | if (!value) goto failed; |
| 2983 | if (_PyObject_SetAttrId(result, &PyId_msg, value) == -1) |
| 2984 | goto failed; |
| 2985 | Py_DECREF(value); |
| 2986 | break; |
| 2987 | case Import_kind: |
| 2988 | result = PyType_GenericNew(Import_type, NULL, NULL); |
| 2989 | if (!result) goto failed; |
| 2990 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 2991 | if (!value) goto failed; |
| 2992 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 2993 | goto failed; |
| 2994 | Py_DECREF(value); |
| 2995 | break; |
| 2996 | case ImportFrom_kind: |
| 2997 | result = PyType_GenericNew(ImportFrom_type, NULL, NULL); |
| 2998 | if (!result) goto failed; |
| 2999 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 3000 | if (!value) goto failed; |
| 3001 | if (_PyObject_SetAttrId(result, &PyId_module, value) == -1) |
| 3002 | goto failed; |
| 3003 | Py_DECREF(value); |
| 3004 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 3005 | if (!value) goto failed; |
| 3006 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 3007 | goto failed; |
| 3008 | Py_DECREF(value); |
| 3009 | value = ast2obj_int(o->v.ImportFrom.level); |
| 3010 | if (!value) goto failed; |
| 3011 | if (_PyObject_SetAttrId(result, &PyId_level, value) == -1) |
| 3012 | goto failed; |
| 3013 | Py_DECREF(value); |
| 3014 | break; |
| 3015 | case Global_kind: |
| 3016 | result = PyType_GenericNew(Global_type, NULL, NULL); |
| 3017 | if (!result) goto failed; |
| 3018 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 3019 | if (!value) goto failed; |
| 3020 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 3021 | goto failed; |
| 3022 | Py_DECREF(value); |
| 3023 | break; |
| 3024 | case Nonlocal_kind: |
| 3025 | result = PyType_GenericNew(Nonlocal_type, NULL, NULL); |
| 3026 | if (!result) goto failed; |
| 3027 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 3028 | if (!value) goto failed; |
| 3029 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 3030 | goto failed; |
| 3031 | Py_DECREF(value); |
| 3032 | break; |
| 3033 | case Expr_kind: |
| 3034 | result = PyType_GenericNew(Expr_type, NULL, NULL); |
| 3035 | if (!result) goto failed; |
| 3036 | value = ast2obj_expr(o->v.Expr.value); |
| 3037 | if (!value) goto failed; |
| 3038 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3039 | goto failed; |
| 3040 | Py_DECREF(value); |
| 3041 | break; |
| 3042 | case Pass_kind: |
| 3043 | result = PyType_GenericNew(Pass_type, NULL, NULL); |
| 3044 | if (!result) goto failed; |
| 3045 | break; |
| 3046 | case Break_kind: |
| 3047 | result = PyType_GenericNew(Break_type, NULL, NULL); |
| 3048 | if (!result) goto failed; |
| 3049 | break; |
| 3050 | case Continue_kind: |
| 3051 | result = PyType_GenericNew(Continue_type, NULL, NULL); |
| 3052 | if (!result) goto failed; |
| 3053 | break; |
| 3054 | } |
| 3055 | value = ast2obj_int(o->lineno); |
| 3056 | if (!value) goto failed; |
| 3057 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3058 | goto failed; |
| 3059 | Py_DECREF(value); |
| 3060 | value = ast2obj_int(o->col_offset); |
| 3061 | if (!value) goto failed; |
| 3062 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3063 | goto failed; |
| 3064 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3065 | value = ast2obj_int(o->end_lineno); |
| 3066 | if (!value) goto failed; |
| 3067 | if (_PyObject_SetAttrId(result, &PyId_end_lineno, value) < 0) |
| 3068 | goto failed; |
| 3069 | Py_DECREF(value); |
| 3070 | value = ast2obj_int(o->end_col_offset); |
| 3071 | if (!value) goto failed; |
| 3072 | if (_PyObject_SetAttrId(result, &PyId_end_col_offset, value) < 0) |
| 3073 | goto failed; |
| 3074 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3075 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3076 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3077 | Py_XDECREF(value); |
| 3078 | Py_XDECREF(result); |
| 3079 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3080 | } |
| 3081 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3082 | PyObject* |
| 3083 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3084 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3085 | expr_ty o = (expr_ty)_o; |
| 3086 | PyObject *result = NULL, *value = NULL; |
| 3087 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3088 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3089 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3090 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3091 | switch (o->kind) { |
| 3092 | case BoolOp_kind: |
| 3093 | result = PyType_GenericNew(BoolOp_type, NULL, NULL); |
| 3094 | if (!result) goto failed; |
| 3095 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 3096 | if (!value) goto failed; |
| 3097 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 3098 | goto failed; |
| 3099 | Py_DECREF(value); |
| 3100 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 3101 | if (!value) goto failed; |
| 3102 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 3103 | goto failed; |
| 3104 | Py_DECREF(value); |
| 3105 | break; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 3106 | case NamedExpr_kind: |
| 3107 | result = PyType_GenericNew(NamedExpr_type, NULL, NULL); |
| 3108 | if (!result) goto failed; |
| 3109 | value = ast2obj_expr(o->v.NamedExpr.target); |
| 3110 | if (!value) goto failed; |
| 3111 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 3112 | goto failed; |
| 3113 | Py_DECREF(value); |
| 3114 | value = ast2obj_expr(o->v.NamedExpr.value); |
| 3115 | if (!value) goto failed; |
| 3116 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3117 | goto failed; |
| 3118 | Py_DECREF(value); |
| 3119 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3120 | case BinOp_kind: |
| 3121 | result = PyType_GenericNew(BinOp_type, NULL, NULL); |
| 3122 | if (!result) goto failed; |
| 3123 | value = ast2obj_expr(o->v.BinOp.left); |
| 3124 | if (!value) goto failed; |
| 3125 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
| 3126 | goto failed; |
| 3127 | Py_DECREF(value); |
| 3128 | value = ast2obj_operator(o->v.BinOp.op); |
| 3129 | if (!value) goto failed; |
| 3130 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 3131 | goto failed; |
| 3132 | Py_DECREF(value); |
| 3133 | value = ast2obj_expr(o->v.BinOp.right); |
| 3134 | if (!value) goto failed; |
| 3135 | if (_PyObject_SetAttrId(result, &PyId_right, value) == -1) |
| 3136 | goto failed; |
| 3137 | Py_DECREF(value); |
| 3138 | break; |
| 3139 | case UnaryOp_kind: |
| 3140 | result = PyType_GenericNew(UnaryOp_type, NULL, NULL); |
| 3141 | if (!result) goto failed; |
| 3142 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 3143 | if (!value) goto failed; |
| 3144 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 3145 | goto failed; |
| 3146 | Py_DECREF(value); |
| 3147 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 3148 | if (!value) goto failed; |
| 3149 | if (_PyObject_SetAttrId(result, &PyId_operand, value) == -1) |
| 3150 | goto failed; |
| 3151 | Py_DECREF(value); |
| 3152 | break; |
| 3153 | case Lambda_kind: |
| 3154 | result = PyType_GenericNew(Lambda_type, NULL, NULL); |
| 3155 | if (!result) goto failed; |
| 3156 | value = ast2obj_arguments(o->v.Lambda.args); |
| 3157 | if (!value) goto failed; |
| 3158 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3159 | goto failed; |
| 3160 | Py_DECREF(value); |
| 3161 | value = ast2obj_expr(o->v.Lambda.body); |
| 3162 | if (!value) goto failed; |
| 3163 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3164 | goto failed; |
| 3165 | Py_DECREF(value); |
| 3166 | break; |
| 3167 | case IfExp_kind: |
| 3168 | result = PyType_GenericNew(IfExp_type, NULL, NULL); |
| 3169 | if (!result) goto failed; |
| 3170 | value = ast2obj_expr(o->v.IfExp.test); |
| 3171 | if (!value) goto failed; |
| 3172 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 3173 | goto failed; |
| 3174 | Py_DECREF(value); |
| 3175 | value = ast2obj_expr(o->v.IfExp.body); |
| 3176 | if (!value) goto failed; |
| 3177 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3178 | goto failed; |
| 3179 | Py_DECREF(value); |
| 3180 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 3181 | if (!value) goto failed; |
| 3182 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 3183 | goto failed; |
| 3184 | Py_DECREF(value); |
| 3185 | break; |
| 3186 | case Dict_kind: |
| 3187 | result = PyType_GenericNew(Dict_type, NULL, NULL); |
| 3188 | if (!result) goto failed; |
| 3189 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 3190 | if (!value) goto failed; |
| 3191 | if (_PyObject_SetAttrId(result, &PyId_keys, value) == -1) |
| 3192 | goto failed; |
| 3193 | Py_DECREF(value); |
| 3194 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 3195 | if (!value) goto failed; |
| 3196 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 3197 | goto failed; |
| 3198 | Py_DECREF(value); |
| 3199 | break; |
| 3200 | case Set_kind: |
| 3201 | result = PyType_GenericNew(Set_type, NULL, NULL); |
| 3202 | if (!result) goto failed; |
| 3203 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 3204 | if (!value) goto failed; |
| 3205 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3206 | goto failed; |
| 3207 | Py_DECREF(value); |
| 3208 | break; |
| 3209 | case ListComp_kind: |
| 3210 | result = PyType_GenericNew(ListComp_type, NULL, NULL); |
| 3211 | if (!result) goto failed; |
| 3212 | value = ast2obj_expr(o->v.ListComp.elt); |
| 3213 | if (!value) goto failed; |
| 3214 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 3215 | goto failed; |
| 3216 | Py_DECREF(value); |
| 3217 | value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension); |
| 3218 | if (!value) goto failed; |
| 3219 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3220 | goto failed; |
| 3221 | Py_DECREF(value); |
| 3222 | break; |
| 3223 | case SetComp_kind: |
| 3224 | result = PyType_GenericNew(SetComp_type, NULL, NULL); |
| 3225 | if (!result) goto failed; |
| 3226 | value = ast2obj_expr(o->v.SetComp.elt); |
| 3227 | if (!value) goto failed; |
| 3228 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 3229 | goto failed; |
| 3230 | Py_DECREF(value); |
| 3231 | value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension); |
| 3232 | if (!value) goto failed; |
| 3233 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3234 | goto failed; |
| 3235 | Py_DECREF(value); |
| 3236 | break; |
| 3237 | case DictComp_kind: |
| 3238 | result = PyType_GenericNew(DictComp_type, NULL, NULL); |
| 3239 | if (!result) goto failed; |
| 3240 | value = ast2obj_expr(o->v.DictComp.key); |
| 3241 | if (!value) goto failed; |
| 3242 | if (_PyObject_SetAttrId(result, &PyId_key, value) == -1) |
| 3243 | goto failed; |
| 3244 | Py_DECREF(value); |
| 3245 | value = ast2obj_expr(o->v.DictComp.value); |
| 3246 | if (!value) goto failed; |
| 3247 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3248 | goto failed; |
| 3249 | Py_DECREF(value); |
| 3250 | value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension); |
| 3251 | if (!value) goto failed; |
| 3252 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3253 | goto failed; |
| 3254 | Py_DECREF(value); |
| 3255 | break; |
| 3256 | case GeneratorExp_kind: |
| 3257 | result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); |
| 3258 | if (!result) goto failed; |
| 3259 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 3260 | if (!value) goto failed; |
| 3261 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 3262 | goto failed; |
| 3263 | Py_DECREF(value); |
| 3264 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 3265 | ast2obj_comprehension); |
| 3266 | if (!value) goto failed; |
| 3267 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3268 | goto failed; |
| 3269 | Py_DECREF(value); |
| 3270 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3271 | case Await_kind: |
| 3272 | result = PyType_GenericNew(Await_type, NULL, NULL); |
| 3273 | if (!result) goto failed; |
| 3274 | value = ast2obj_expr(o->v.Await.value); |
| 3275 | if (!value) goto failed; |
| 3276 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3277 | goto failed; |
| 3278 | Py_DECREF(value); |
| 3279 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3280 | case Yield_kind: |
| 3281 | result = PyType_GenericNew(Yield_type, NULL, NULL); |
| 3282 | if (!result) goto failed; |
| 3283 | value = ast2obj_expr(o->v.Yield.value); |
| 3284 | if (!value) goto failed; |
| 3285 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3286 | goto failed; |
| 3287 | Py_DECREF(value); |
| 3288 | break; |
| 3289 | case YieldFrom_kind: |
| 3290 | result = PyType_GenericNew(YieldFrom_type, NULL, NULL); |
| 3291 | if (!result) goto failed; |
| 3292 | value = ast2obj_expr(o->v.YieldFrom.value); |
| 3293 | if (!value) goto failed; |
| 3294 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3295 | goto failed; |
| 3296 | Py_DECREF(value); |
| 3297 | break; |
| 3298 | case Compare_kind: |
| 3299 | result = PyType_GenericNew(Compare_type, NULL, NULL); |
| 3300 | if (!result) goto failed; |
| 3301 | value = ast2obj_expr(o->v.Compare.left); |
| 3302 | if (!value) goto failed; |
| 3303 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
| 3304 | goto failed; |
| 3305 | Py_DECREF(value); |
| 3306 | { |
| 3307 | Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 3308 | value = PyList_New(n); |
| 3309 | if (!value) goto failed; |
| 3310 | for(i = 0; i < n; i++) |
| 3311 | 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] | 3312 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 3313 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3314 | if (_PyObject_SetAttrId(result, &PyId_ops, value) == -1) |
| 3315 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3316 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3317 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3318 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3319 | if (_PyObject_SetAttrId(result, &PyId_comparators, value) == -1) |
| 3320 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3321 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3322 | break; |
| 3323 | case Call_kind: |
| 3324 | result = PyType_GenericNew(Call_type, NULL, NULL); |
| 3325 | if (!result) goto failed; |
| 3326 | value = ast2obj_expr(o->v.Call.func); |
| 3327 | if (!value) goto failed; |
| 3328 | if (_PyObject_SetAttrId(result, &PyId_func, value) == -1) |
| 3329 | goto failed; |
| 3330 | Py_DECREF(value); |
| 3331 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 3332 | if (!value) goto failed; |
| 3333 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3334 | goto failed; |
| 3335 | Py_DECREF(value); |
| 3336 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 3337 | if (!value) goto failed; |
| 3338 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
| 3339 | goto failed; |
| 3340 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3341 | break; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3342 | case FormattedValue_kind: |
| 3343 | result = PyType_GenericNew(FormattedValue_type, NULL, NULL); |
| 3344 | if (!result) goto failed; |
| 3345 | value = ast2obj_expr(o->v.FormattedValue.value); |
| 3346 | if (!value) goto failed; |
| 3347 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3348 | goto failed; |
| 3349 | Py_DECREF(value); |
| 3350 | value = ast2obj_int(o->v.FormattedValue.conversion); |
| 3351 | if (!value) goto failed; |
| 3352 | if (_PyObject_SetAttrId(result, &PyId_conversion, value) == -1) |
| 3353 | goto failed; |
| 3354 | Py_DECREF(value); |
| 3355 | value = ast2obj_expr(o->v.FormattedValue.format_spec); |
| 3356 | if (!value) goto failed; |
| 3357 | if (_PyObject_SetAttrId(result, &PyId_format_spec, value) == -1) |
| 3358 | goto failed; |
| 3359 | Py_DECREF(value); |
| 3360 | break; |
| 3361 | case JoinedStr_kind: |
| 3362 | result = PyType_GenericNew(JoinedStr_type, NULL, NULL); |
| 3363 | if (!result) goto failed; |
| 3364 | value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr); |
| 3365 | if (!value) goto failed; |
| 3366 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 3367 | goto failed; |
| 3368 | Py_DECREF(value); |
| 3369 | break; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3370 | case Constant_kind: |
| 3371 | result = PyType_GenericNew(Constant_type, NULL, NULL); |
| 3372 | if (!result) goto failed; |
| 3373 | value = ast2obj_constant(o->v.Constant.value); |
| 3374 | if (!value) goto failed; |
| 3375 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3376 | goto failed; |
| 3377 | Py_DECREF(value); |
| 3378 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3379 | case Attribute_kind: |
| 3380 | result = PyType_GenericNew(Attribute_type, NULL, NULL); |
| 3381 | if (!result) goto failed; |
| 3382 | value = ast2obj_expr(o->v.Attribute.value); |
| 3383 | if (!value) goto failed; |
| 3384 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3385 | goto failed; |
| 3386 | Py_DECREF(value); |
| 3387 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 3388 | if (!value) goto failed; |
| 3389 | if (_PyObject_SetAttrId(result, &PyId_attr, value) == -1) |
| 3390 | goto failed; |
| 3391 | Py_DECREF(value); |
| 3392 | value = ast2obj_expr_context(o->v.Attribute.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 Subscript_kind: |
| 3399 | result = PyType_GenericNew(Subscript_type, NULL, NULL); |
| 3400 | if (!result) goto failed; |
| 3401 | value = ast2obj_expr(o->v.Subscript.value); |
| 3402 | if (!value) goto failed; |
| 3403 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3404 | goto failed; |
| 3405 | Py_DECREF(value); |
| 3406 | value = ast2obj_slice(o->v.Subscript.slice); |
| 3407 | if (!value) goto failed; |
| 3408 | if (_PyObject_SetAttrId(result, &PyId_slice, value) == -1) |
| 3409 | goto failed; |
| 3410 | Py_DECREF(value); |
| 3411 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 3412 | if (!value) goto failed; |
| 3413 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3414 | goto failed; |
| 3415 | Py_DECREF(value); |
| 3416 | break; |
| 3417 | case Starred_kind: |
| 3418 | result = PyType_GenericNew(Starred_type, NULL, NULL); |
| 3419 | if (!result) goto failed; |
| 3420 | value = ast2obj_expr(o->v.Starred.value); |
| 3421 | if (!value) goto failed; |
| 3422 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3423 | goto failed; |
| 3424 | Py_DECREF(value); |
| 3425 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 3426 | if (!value) goto failed; |
| 3427 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3428 | goto failed; |
| 3429 | Py_DECREF(value); |
| 3430 | break; |
| 3431 | case Name_kind: |
| 3432 | result = PyType_GenericNew(Name_type, NULL, NULL); |
| 3433 | if (!result) goto failed; |
| 3434 | value = ast2obj_identifier(o->v.Name.id); |
| 3435 | if (!value) goto failed; |
| 3436 | if (_PyObject_SetAttrId(result, &PyId_id, value) == -1) |
| 3437 | goto failed; |
| 3438 | Py_DECREF(value); |
| 3439 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 3440 | if (!value) goto failed; |
| 3441 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3442 | goto failed; |
| 3443 | Py_DECREF(value); |
| 3444 | break; |
| 3445 | case List_kind: |
| 3446 | result = PyType_GenericNew(List_type, NULL, NULL); |
| 3447 | if (!result) goto failed; |
| 3448 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 3449 | if (!value) goto failed; |
| 3450 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3451 | goto failed; |
| 3452 | Py_DECREF(value); |
| 3453 | value = ast2obj_expr_context(o->v.List.ctx); |
| 3454 | if (!value) goto failed; |
| 3455 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3456 | goto failed; |
| 3457 | Py_DECREF(value); |
| 3458 | break; |
| 3459 | case Tuple_kind: |
| 3460 | result = PyType_GenericNew(Tuple_type, NULL, NULL); |
| 3461 | if (!result) goto failed; |
| 3462 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 3463 | if (!value) goto failed; |
| 3464 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3465 | goto failed; |
| 3466 | Py_DECREF(value); |
| 3467 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 3468 | if (!value) goto failed; |
| 3469 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3470 | goto failed; |
| 3471 | Py_DECREF(value); |
| 3472 | break; |
| 3473 | } |
| 3474 | value = ast2obj_int(o->lineno); |
| 3475 | if (!value) goto failed; |
| 3476 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3477 | goto failed; |
| 3478 | Py_DECREF(value); |
| 3479 | value = ast2obj_int(o->col_offset); |
| 3480 | if (!value) goto failed; |
| 3481 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3482 | goto failed; |
| 3483 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3484 | value = ast2obj_int(o->end_lineno); |
| 3485 | if (!value) goto failed; |
| 3486 | if (_PyObject_SetAttrId(result, &PyId_end_lineno, value) < 0) |
| 3487 | goto failed; |
| 3488 | Py_DECREF(value); |
| 3489 | value = ast2obj_int(o->end_col_offset); |
| 3490 | if (!value) goto failed; |
| 3491 | if (_PyObject_SetAttrId(result, &PyId_end_col_offset, value) < 0) |
| 3492 | goto failed; |
| 3493 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3494 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3495 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3496 | Py_XDECREF(value); |
| 3497 | Py_XDECREF(result); |
| 3498 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3499 | } |
| 3500 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3501 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3502 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3503 | switch(o) { |
| 3504 | case Load: |
| 3505 | Py_INCREF(Load_singleton); |
| 3506 | return Load_singleton; |
| 3507 | case Store: |
| 3508 | Py_INCREF(Store_singleton); |
| 3509 | return Store_singleton; |
| 3510 | case Del: |
| 3511 | Py_INCREF(Del_singleton); |
| 3512 | return Del_singleton; |
| 3513 | case AugLoad: |
| 3514 | Py_INCREF(AugLoad_singleton); |
| 3515 | return AugLoad_singleton; |
| 3516 | case AugStore: |
| 3517 | Py_INCREF(AugStore_singleton); |
| 3518 | return AugStore_singleton; |
| 3519 | case Param: |
| 3520 | Py_INCREF(Param_singleton); |
| 3521 | return Param_singleton; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 3522 | case NamedStore: |
| 3523 | Py_INCREF(NamedStore_singleton); |
| 3524 | return NamedStore_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3525 | default: |
| 3526 | /* should never happen, but just in case ... */ |
| 3527 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 3528 | return NULL; |
| 3529 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3530 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3531 | PyObject* |
| 3532 | ast2obj_slice(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3533 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3534 | slice_ty o = (slice_ty)_o; |
| 3535 | PyObject *result = NULL, *value = NULL; |
| 3536 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3537 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3538 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3539 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3540 | switch (o->kind) { |
| 3541 | case Slice_kind: |
| 3542 | result = PyType_GenericNew(Slice_type, NULL, NULL); |
| 3543 | if (!result) goto failed; |
| 3544 | value = ast2obj_expr(o->v.Slice.lower); |
| 3545 | if (!value) goto failed; |
| 3546 | if (_PyObject_SetAttrId(result, &PyId_lower, value) == -1) |
| 3547 | goto failed; |
| 3548 | Py_DECREF(value); |
| 3549 | value = ast2obj_expr(o->v.Slice.upper); |
| 3550 | if (!value) goto failed; |
| 3551 | if (_PyObject_SetAttrId(result, &PyId_upper, value) == -1) |
| 3552 | goto failed; |
| 3553 | Py_DECREF(value); |
| 3554 | value = ast2obj_expr(o->v.Slice.step); |
| 3555 | if (!value) goto failed; |
| 3556 | if (_PyObject_SetAttrId(result, &PyId_step, value) == -1) |
| 3557 | goto failed; |
| 3558 | Py_DECREF(value); |
| 3559 | break; |
| 3560 | case ExtSlice_kind: |
| 3561 | result = PyType_GenericNew(ExtSlice_type, NULL, NULL); |
| 3562 | if (!result) goto failed; |
| 3563 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 3564 | if (!value) goto failed; |
| 3565 | if (_PyObject_SetAttrId(result, &PyId_dims, value) == -1) |
| 3566 | goto failed; |
| 3567 | Py_DECREF(value); |
| 3568 | break; |
| 3569 | case Index_kind: |
| 3570 | result = PyType_GenericNew(Index_type, NULL, NULL); |
| 3571 | if (!result) goto failed; |
| 3572 | value = ast2obj_expr(o->v.Index.value); |
| 3573 | if (!value) goto failed; |
| 3574 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3575 | goto failed; |
| 3576 | Py_DECREF(value); |
| 3577 | break; |
| 3578 | } |
| 3579 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3580 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3581 | Py_XDECREF(value); |
| 3582 | Py_XDECREF(result); |
| 3583 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3584 | } |
| 3585 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3586 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3587 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3588 | switch(o) { |
| 3589 | case And: |
| 3590 | Py_INCREF(And_singleton); |
| 3591 | return And_singleton; |
| 3592 | case Or: |
| 3593 | Py_INCREF(Or_singleton); |
| 3594 | return Or_singleton; |
| 3595 | default: |
| 3596 | /* should never happen, but just in case ... */ |
| 3597 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 3598 | return NULL; |
| 3599 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3600 | } |
| 3601 | PyObject* ast2obj_operator(operator_ty o) |
| 3602 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3603 | switch(o) { |
| 3604 | case Add: |
| 3605 | Py_INCREF(Add_singleton); |
| 3606 | return Add_singleton; |
| 3607 | case Sub: |
| 3608 | Py_INCREF(Sub_singleton); |
| 3609 | return Sub_singleton; |
| 3610 | case Mult: |
| 3611 | Py_INCREF(Mult_singleton); |
| 3612 | return Mult_singleton; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 3613 | case MatMult: |
| 3614 | Py_INCREF(MatMult_singleton); |
| 3615 | return MatMult_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3616 | case Div: |
| 3617 | Py_INCREF(Div_singleton); |
| 3618 | return Div_singleton; |
| 3619 | case Mod: |
| 3620 | Py_INCREF(Mod_singleton); |
| 3621 | return Mod_singleton; |
| 3622 | case Pow: |
| 3623 | Py_INCREF(Pow_singleton); |
| 3624 | return Pow_singleton; |
| 3625 | case LShift: |
| 3626 | Py_INCREF(LShift_singleton); |
| 3627 | return LShift_singleton; |
| 3628 | case RShift: |
| 3629 | Py_INCREF(RShift_singleton); |
| 3630 | return RShift_singleton; |
| 3631 | case BitOr: |
| 3632 | Py_INCREF(BitOr_singleton); |
| 3633 | return BitOr_singleton; |
| 3634 | case BitXor: |
| 3635 | Py_INCREF(BitXor_singleton); |
| 3636 | return BitXor_singleton; |
| 3637 | case BitAnd: |
| 3638 | Py_INCREF(BitAnd_singleton); |
| 3639 | return BitAnd_singleton; |
| 3640 | case FloorDiv: |
| 3641 | Py_INCREF(FloorDiv_singleton); |
| 3642 | return FloorDiv_singleton; |
| 3643 | default: |
| 3644 | /* should never happen, but just in case ... */ |
| 3645 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 3646 | return NULL; |
| 3647 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3648 | } |
| 3649 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 3650 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3651 | switch(o) { |
| 3652 | case Invert: |
| 3653 | Py_INCREF(Invert_singleton); |
| 3654 | return Invert_singleton; |
| 3655 | case Not: |
| 3656 | Py_INCREF(Not_singleton); |
| 3657 | return Not_singleton; |
| 3658 | case UAdd: |
| 3659 | Py_INCREF(UAdd_singleton); |
| 3660 | return UAdd_singleton; |
| 3661 | case USub: |
| 3662 | Py_INCREF(USub_singleton); |
| 3663 | return USub_singleton; |
| 3664 | default: |
| 3665 | /* should never happen, but just in case ... */ |
| 3666 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 3667 | return NULL; |
| 3668 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3669 | } |
| 3670 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 3671 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3672 | switch(o) { |
| 3673 | case Eq: |
| 3674 | Py_INCREF(Eq_singleton); |
| 3675 | return Eq_singleton; |
| 3676 | case NotEq: |
| 3677 | Py_INCREF(NotEq_singleton); |
| 3678 | return NotEq_singleton; |
| 3679 | case Lt: |
| 3680 | Py_INCREF(Lt_singleton); |
| 3681 | return Lt_singleton; |
| 3682 | case LtE: |
| 3683 | Py_INCREF(LtE_singleton); |
| 3684 | return LtE_singleton; |
| 3685 | case Gt: |
| 3686 | Py_INCREF(Gt_singleton); |
| 3687 | return Gt_singleton; |
| 3688 | case GtE: |
| 3689 | Py_INCREF(GtE_singleton); |
| 3690 | return GtE_singleton; |
| 3691 | case Is: |
| 3692 | Py_INCREF(Is_singleton); |
| 3693 | return Is_singleton; |
| 3694 | case IsNot: |
| 3695 | Py_INCREF(IsNot_singleton); |
| 3696 | return IsNot_singleton; |
| 3697 | case In: |
| 3698 | Py_INCREF(In_singleton); |
| 3699 | return In_singleton; |
| 3700 | case NotIn: |
| 3701 | Py_INCREF(NotIn_singleton); |
| 3702 | return NotIn_singleton; |
| 3703 | default: |
| 3704 | /* should never happen, but just in case ... */ |
| 3705 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 3706 | return NULL; |
| 3707 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3708 | } |
| 3709 | PyObject* |
| 3710 | ast2obj_comprehension(void* _o) |
| 3711 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3712 | comprehension_ty o = (comprehension_ty)_o; |
| 3713 | PyObject *result = NULL, *value = NULL; |
| 3714 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3715 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3716 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3717 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3718 | result = PyType_GenericNew(comprehension_type, NULL, NULL); |
| 3719 | if (!result) return NULL; |
| 3720 | value = ast2obj_expr(o->target); |
| 3721 | if (!value) goto failed; |
| 3722 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 3723 | goto failed; |
| 3724 | Py_DECREF(value); |
| 3725 | value = ast2obj_expr(o->iter); |
| 3726 | if (!value) goto failed; |
| 3727 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 3728 | goto failed; |
| 3729 | Py_DECREF(value); |
| 3730 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 3731 | if (!value) goto failed; |
| 3732 | if (_PyObject_SetAttrId(result, &PyId_ifs, value) == -1) |
| 3733 | goto failed; |
| 3734 | Py_DECREF(value); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 3735 | value = ast2obj_int(o->is_async); |
| 3736 | if (!value) goto failed; |
| 3737 | if (_PyObject_SetAttrId(result, &PyId_is_async, value) == -1) |
| 3738 | goto failed; |
| 3739 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3740 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3741 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3742 | Py_XDECREF(value); |
| 3743 | Py_XDECREF(result); |
| 3744 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3745 | } |
| 3746 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3747 | PyObject* |
| 3748 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3749 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3750 | excepthandler_ty o = (excepthandler_ty)_o; |
| 3751 | PyObject *result = NULL, *value = NULL; |
| 3752 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3753 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3754 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3755 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3756 | switch (o->kind) { |
| 3757 | case ExceptHandler_kind: |
| 3758 | result = PyType_GenericNew(ExceptHandler_type, NULL, NULL); |
| 3759 | if (!result) goto failed; |
| 3760 | value = ast2obj_expr(o->v.ExceptHandler.type); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3761 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3762 | if (_PyObject_SetAttrId(result, &PyId_type, value) == -1) |
| 3763 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3764 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3765 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3766 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3767 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 3768 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3769 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3770 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 3771 | if (!value) goto failed; |
| 3772 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3773 | goto failed; |
| 3774 | Py_DECREF(value); |
| 3775 | break; |
| 3776 | } |
| 3777 | value = ast2obj_int(o->lineno); |
| 3778 | if (!value) goto failed; |
| 3779 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3780 | goto failed; |
| 3781 | Py_DECREF(value); |
| 3782 | value = ast2obj_int(o->col_offset); |
| 3783 | if (!value) goto failed; |
| 3784 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3785 | goto failed; |
| 3786 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3787 | value = ast2obj_int(o->end_lineno); |
| 3788 | if (!value) goto failed; |
| 3789 | if (_PyObject_SetAttrId(result, &PyId_end_lineno, value) < 0) |
| 3790 | goto failed; |
| 3791 | Py_DECREF(value); |
| 3792 | value = ast2obj_int(o->end_col_offset); |
| 3793 | if (!value) goto failed; |
| 3794 | if (_PyObject_SetAttrId(result, &PyId_end_col_offset, value) < 0) |
| 3795 | goto failed; |
| 3796 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3797 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3798 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3799 | Py_XDECREF(value); |
| 3800 | Py_XDECREF(result); |
| 3801 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3802 | } |
| 3803 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3804 | PyObject* |
| 3805 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3806 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3807 | arguments_ty o = (arguments_ty)_o; |
| 3808 | PyObject *result = NULL, *value = NULL; |
| 3809 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3810 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3811 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3812 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3813 | result = PyType_GenericNew(arguments_type, NULL, NULL); |
| 3814 | if (!result) return NULL; |
| 3815 | value = ast2obj_list(o->args, ast2obj_arg); |
| 3816 | if (!value) goto failed; |
| 3817 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3818 | goto failed; |
| 3819 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3820 | value = ast2obj_arg(o->vararg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3821 | if (!value) goto failed; |
| 3822 | if (_PyObject_SetAttrId(result, &PyId_vararg, value) == -1) |
| 3823 | goto failed; |
| 3824 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3825 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
| 3826 | if (!value) goto failed; |
| 3827 | if (_PyObject_SetAttrId(result, &PyId_kwonlyargs, value) == -1) |
| 3828 | goto failed; |
| 3829 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3830 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3831 | if (!value) goto failed; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3832 | if (_PyObject_SetAttrId(result, &PyId_kw_defaults, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3833 | goto failed; |
| 3834 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3835 | value = ast2obj_arg(o->kwarg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3836 | if (!value) goto failed; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3837 | if (_PyObject_SetAttrId(result, &PyId_kwarg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3838 | goto failed; |
| 3839 | Py_DECREF(value); |
| 3840 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 3841 | if (!value) goto failed; |
| 3842 | if (_PyObject_SetAttrId(result, &PyId_defaults, value) == -1) |
| 3843 | goto failed; |
| 3844 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3845 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3846 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3847 | Py_XDECREF(value); |
| 3848 | Py_XDECREF(result); |
| 3849 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3850 | } |
| 3851 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3852 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3853 | ast2obj_arg(void* _o) |
| 3854 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3855 | arg_ty o = (arg_ty)_o; |
| 3856 | PyObject *result = NULL, *value = NULL; |
| 3857 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3858 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3859 | } |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3860 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3861 | result = PyType_GenericNew(arg_type, NULL, NULL); |
| 3862 | if (!result) return NULL; |
| 3863 | value = ast2obj_identifier(o->arg); |
| 3864 | if (!value) goto failed; |
| 3865 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
| 3866 | goto failed; |
| 3867 | Py_DECREF(value); |
| 3868 | value = ast2obj_expr(o->annotation); |
| 3869 | if (!value) goto failed; |
| 3870 | if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) |
| 3871 | goto failed; |
| 3872 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3873 | value = ast2obj_int(o->lineno); |
| 3874 | if (!value) goto failed; |
| 3875 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3876 | goto failed; |
| 3877 | Py_DECREF(value); |
| 3878 | value = ast2obj_int(o->col_offset); |
| 3879 | if (!value) goto failed; |
| 3880 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3881 | goto failed; |
| 3882 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3883 | value = ast2obj_int(o->end_lineno); |
| 3884 | if (!value) goto failed; |
| 3885 | if (_PyObject_SetAttrId(result, &PyId_end_lineno, value) < 0) |
| 3886 | goto failed; |
| 3887 | Py_DECREF(value); |
| 3888 | value = ast2obj_int(o->end_col_offset); |
| 3889 | if (!value) goto failed; |
| 3890 | if (_PyObject_SetAttrId(result, &PyId_end_col_offset, value) < 0) |
| 3891 | goto failed; |
| 3892 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3893 | return result; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3894 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3895 | Py_XDECREF(value); |
| 3896 | Py_XDECREF(result); |
| 3897 | return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3898 | } |
| 3899 | |
| 3900 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3901 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3902 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3903 | keyword_ty o = (keyword_ty)_o; |
| 3904 | PyObject *result = NULL, *value = NULL; |
| 3905 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3906 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3907 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3908 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3909 | result = PyType_GenericNew(keyword_type, NULL, NULL); |
| 3910 | if (!result) return NULL; |
| 3911 | value = ast2obj_identifier(o->arg); |
| 3912 | if (!value) goto failed; |
| 3913 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
| 3914 | goto failed; |
| 3915 | Py_DECREF(value); |
| 3916 | value = ast2obj_expr(o->value); |
| 3917 | if (!value) goto failed; |
| 3918 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3919 | goto failed; |
| 3920 | Py_DECREF(value); |
| 3921 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3922 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3923 | Py_XDECREF(value); |
| 3924 | Py_XDECREF(result); |
| 3925 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3926 | } |
| 3927 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3928 | PyObject* |
| 3929 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3930 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3931 | alias_ty o = (alias_ty)_o; |
| 3932 | PyObject *result = NULL, *value = NULL; |
| 3933 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3934 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3935 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3936 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3937 | result = PyType_GenericNew(alias_type, NULL, NULL); |
| 3938 | if (!result) return NULL; |
| 3939 | value = ast2obj_identifier(o->name); |
| 3940 | if (!value) goto failed; |
| 3941 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 3942 | goto failed; |
| 3943 | Py_DECREF(value); |
| 3944 | value = ast2obj_identifier(o->asname); |
| 3945 | if (!value) goto failed; |
| 3946 | if (_PyObject_SetAttrId(result, &PyId_asname, value) == -1) |
| 3947 | goto failed; |
| 3948 | Py_DECREF(value); |
| 3949 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3950 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3951 | Py_XDECREF(value); |
| 3952 | Py_XDECREF(result); |
| 3953 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3954 | } |
| 3955 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3956 | PyObject* |
| 3957 | ast2obj_withitem(void* _o) |
| 3958 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3959 | withitem_ty o = (withitem_ty)_o; |
| 3960 | PyObject *result = NULL, *value = NULL; |
| 3961 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3962 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3963 | } |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3964 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3965 | result = PyType_GenericNew(withitem_type, NULL, NULL); |
| 3966 | if (!result) return NULL; |
| 3967 | value = ast2obj_expr(o->context_expr); |
| 3968 | if (!value) goto failed; |
| 3969 | if (_PyObject_SetAttrId(result, &PyId_context_expr, value) == -1) |
| 3970 | goto failed; |
| 3971 | Py_DECREF(value); |
| 3972 | value = ast2obj_expr(o->optional_vars); |
| 3973 | if (!value) goto failed; |
| 3974 | if (_PyObject_SetAttrId(result, &PyId_optional_vars, value) == -1) |
| 3975 | goto failed; |
| 3976 | Py_DECREF(value); |
| 3977 | return result; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3978 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3979 | Py_XDECREF(value); |
| 3980 | Py_XDECREF(result); |
| 3981 | return NULL; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3982 | } |
| 3983 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3984 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3985 | int |
| 3986 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 3987 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3988 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3989 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3990 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3991 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3992 | if (obj == Py_None) { |
| 3993 | *out = NULL; |
| 3994 | return 0; |
| 3995 | } |
| 3996 | isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type); |
| 3997 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3998 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3999 | } |
| 4000 | if (isinstance) { |
| 4001 | asdl_seq* body; |
| 4002 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4003 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 4004 | return 1; |
| 4005 | } |
| 4006 | if (tmp == NULL) { |
| 4007 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 4008 | return 1; |
| 4009 | } |
| 4010 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4011 | int res; |
| 4012 | Py_ssize_t len; |
| 4013 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4014 | if (!PyList_Check(tmp)) { |
| 4015 | PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4016 | goto failed; |
| 4017 | } |
| 4018 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4019 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4020 | if (body == NULL) goto failed; |
| 4021 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4022 | stmt_ty val; |
| 4023 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4024 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4025 | if (len != PyList_GET_SIZE(tmp)) { |
| 4026 | PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration"); |
| 4027 | goto failed; |
| 4028 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4029 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4030 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4031 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4032 | } |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 4033 | *out = Module(body, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4034 | if (*out == NULL) goto failed; |
| 4035 | return 0; |
| 4036 | } |
| 4037 | isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type); |
| 4038 | if (isinstance == -1) { |
| 4039 | return 1; |
| 4040 | } |
| 4041 | if (isinstance) { |
| 4042 | asdl_seq* body; |
| 4043 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4044 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 4045 | return 1; |
| 4046 | } |
| 4047 | if (tmp == NULL) { |
| 4048 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 4049 | return 1; |
| 4050 | } |
| 4051 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4052 | int res; |
| 4053 | Py_ssize_t len; |
| 4054 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4055 | if (!PyList_Check(tmp)) { |
| 4056 | PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4057 | goto failed; |
| 4058 | } |
| 4059 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4060 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4061 | if (body == NULL) goto failed; |
| 4062 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4063 | stmt_ty val; |
| 4064 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4065 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4066 | if (len != PyList_GET_SIZE(tmp)) { |
| 4067 | PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration"); |
| 4068 | goto failed; |
| 4069 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4070 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4071 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4072 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4073 | } |
| 4074 | *out = Interactive(body, arena); |
| 4075 | if (*out == NULL) goto failed; |
| 4076 | return 0; |
| 4077 | } |
| 4078 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type); |
| 4079 | if (isinstance == -1) { |
| 4080 | return 1; |
| 4081 | } |
| 4082 | if (isinstance) { |
| 4083 | expr_ty body; |
| 4084 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4085 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 4086 | return 1; |
| 4087 | } |
| 4088 | if (tmp == NULL) { |
| 4089 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 4090 | return 1; |
| 4091 | } |
| 4092 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4093 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4094 | res = obj2ast_expr(tmp, &body, arena); |
| 4095 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4096 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4097 | } |
| 4098 | *out = Expression(body, arena); |
| 4099 | if (*out == NULL) goto failed; |
| 4100 | return 0; |
| 4101 | } |
| 4102 | isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type); |
| 4103 | if (isinstance == -1) { |
| 4104 | return 1; |
| 4105 | } |
| 4106 | if (isinstance) { |
| 4107 | asdl_seq* body; |
| 4108 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4109 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 4110 | return 1; |
| 4111 | } |
| 4112 | if (tmp == NULL) { |
| 4113 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite"); |
| 4114 | return 1; |
| 4115 | } |
| 4116 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4117 | int res; |
| 4118 | Py_ssize_t len; |
| 4119 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4120 | if (!PyList_Check(tmp)) { |
| 4121 | PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4122 | goto failed; |
| 4123 | } |
| 4124 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4125 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4126 | if (body == NULL) goto failed; |
| 4127 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4128 | stmt_ty val; |
| 4129 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4130 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4131 | if (len != PyList_GET_SIZE(tmp)) { |
| 4132 | PyErr_SetString(PyExc_RuntimeError, "Suite field \"body\" changed size during iteration"); |
| 4133 | goto failed; |
| 4134 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4135 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4136 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4137 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4138 | } |
| 4139 | *out = Suite(body, arena); |
| 4140 | if (*out == NULL) goto failed; |
| 4141 | return 0; |
| 4142 | } |
| 4143 | |
| 4144 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
| 4145 | failed: |
| 4146 | Py_XDECREF(tmp); |
| 4147 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4148 | } |
| 4149 | |
| 4150 | int |
| 4151 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 4152 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4153 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4154 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4155 | PyObject *tmp = NULL; |
| 4156 | int lineno; |
| 4157 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4158 | int end_lineno; |
| 4159 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4160 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4161 | if (obj == Py_None) { |
| 4162 | *out = NULL; |
| 4163 | return 0; |
| 4164 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4165 | if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) { |
| 4166 | return 1; |
| 4167 | } |
| 4168 | if (tmp == NULL) { |
| 4169 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 4170 | return 1; |
| 4171 | } |
| 4172 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4173 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4174 | res = obj2ast_int(tmp, &lineno, arena); |
| 4175 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4176 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4177 | } |
| 4178 | if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4179 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4180 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4181 | if (tmp == NULL) { |
| 4182 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 4183 | return 1; |
| 4184 | } |
| 4185 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4186 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4187 | res = obj2ast_int(tmp, &col_offset, arena); |
| 4188 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4189 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4190 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4191 | if (_PyObject_LookupAttrId(obj, &PyId_end_lineno, &tmp) < 0) { |
| 4192 | return 1; |
| 4193 | } |
| 4194 | if (tmp == NULL || tmp == Py_None) { |
| 4195 | Py_CLEAR(tmp); |
| 4196 | end_lineno = 0; |
| 4197 | } |
| 4198 | else { |
| 4199 | int res; |
| 4200 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 4201 | if (res != 0) goto failed; |
| 4202 | Py_CLEAR(tmp); |
| 4203 | } |
| 4204 | if (_PyObject_LookupAttrId(obj, &PyId_end_col_offset, &tmp) < 0) { |
| 4205 | return 1; |
| 4206 | } |
| 4207 | if (tmp == NULL || tmp == Py_None) { |
| 4208 | Py_CLEAR(tmp); |
| 4209 | end_col_offset = 0; |
| 4210 | } |
| 4211 | else { |
| 4212 | int res; |
| 4213 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 4214 | if (res != 0) goto failed; |
| 4215 | Py_CLEAR(tmp); |
| 4216 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4217 | isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type); |
| 4218 | if (isinstance == -1) { |
| 4219 | return 1; |
| 4220 | } |
| 4221 | if (isinstance) { |
| 4222 | identifier name; |
| 4223 | arguments_ty args; |
| 4224 | asdl_seq* body; |
| 4225 | asdl_seq* decorator_list; |
| 4226 | expr_ty returns; |
| 4227 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4228 | if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) { |
| 4229 | return 1; |
| 4230 | } |
| 4231 | if (tmp == NULL) { |
| 4232 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 4233 | return 1; |
| 4234 | } |
| 4235 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4236 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4237 | res = obj2ast_identifier(tmp, &name, arena); |
| 4238 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4239 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4240 | } |
| 4241 | if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4242 | return 1; |
| 4243 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4244 | if (tmp == NULL) { |
| 4245 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 4246 | return 1; |
| 4247 | } |
| 4248 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4249 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4250 | res = obj2ast_arguments(tmp, &args, arena); |
| 4251 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4252 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4253 | } |
| 4254 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4255 | return 1; |
| 4256 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4257 | if (tmp == NULL) { |
| 4258 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 4259 | return 1; |
| 4260 | } |
| 4261 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4262 | int res; |
| 4263 | Py_ssize_t len; |
| 4264 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4265 | if (!PyList_Check(tmp)) { |
| 4266 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4267 | goto failed; |
| 4268 | } |
| 4269 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4270 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4271 | if (body == NULL) goto failed; |
| 4272 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4273 | stmt_ty val; |
| 4274 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4275 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4276 | if (len != PyList_GET_SIZE(tmp)) { |
| 4277 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration"); |
| 4278 | goto failed; |
| 4279 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4280 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4281 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4282 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4283 | } |
| 4284 | if (_PyObject_LookupAttrId(obj, &PyId_decorator_list, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4285 | return 1; |
| 4286 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4287 | if (tmp == NULL) { |
| 4288 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 4289 | return 1; |
| 4290 | } |
| 4291 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4292 | int res; |
| 4293 | Py_ssize_t len; |
| 4294 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4295 | if (!PyList_Check(tmp)) { |
| 4296 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4297 | goto failed; |
| 4298 | } |
| 4299 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4300 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4301 | if (decorator_list == NULL) goto failed; |
| 4302 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4303 | expr_ty val; |
| 4304 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4305 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4306 | if (len != PyList_GET_SIZE(tmp)) { |
| 4307 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration"); |
| 4308 | goto failed; |
| 4309 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4310 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4311 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4312 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4313 | } |
| 4314 | if (_PyObject_LookupAttrId(obj, &PyId_returns, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4315 | return 1; |
| 4316 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4317 | if (tmp == NULL || tmp == Py_None) { |
| 4318 | Py_CLEAR(tmp); |
| 4319 | returns = NULL; |
| 4320 | } |
| 4321 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4322 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4323 | res = obj2ast_expr(tmp, &returns, arena); |
| 4324 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4325 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4326 | } |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 4327 | *out = FunctionDef(name, args, body, decorator_list, returns, lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4328 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4329 | if (*out == NULL) goto failed; |
| 4330 | return 0; |
| 4331 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4332 | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncFunctionDef_type); |
| 4333 | if (isinstance == -1) { |
| 4334 | return 1; |
| 4335 | } |
| 4336 | if (isinstance) { |
| 4337 | identifier name; |
| 4338 | arguments_ty args; |
| 4339 | asdl_seq* body; |
| 4340 | asdl_seq* decorator_list; |
| 4341 | expr_ty returns; |
| 4342 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4343 | if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) { |
| 4344 | return 1; |
| 4345 | } |
| 4346 | if (tmp == NULL) { |
| 4347 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef"); |
| 4348 | return 1; |
| 4349 | } |
| 4350 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4351 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4352 | res = obj2ast_identifier(tmp, &name, arena); |
| 4353 | if (res != 0) goto failed; |
| 4354 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4355 | } |
| 4356 | if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4357 | return 1; |
| 4358 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4359 | if (tmp == NULL) { |
| 4360 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef"); |
| 4361 | return 1; |
| 4362 | } |
| 4363 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4364 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4365 | res = obj2ast_arguments(tmp, &args, arena); |
| 4366 | if (res != 0) goto failed; |
| 4367 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4368 | } |
| 4369 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4370 | return 1; |
| 4371 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4372 | if (tmp == NULL) { |
| 4373 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef"); |
| 4374 | return 1; |
| 4375 | } |
| 4376 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4377 | int res; |
| 4378 | Py_ssize_t len; |
| 4379 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4380 | if (!PyList_Check(tmp)) { |
| 4381 | PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4382 | goto failed; |
| 4383 | } |
| 4384 | len = PyList_GET_SIZE(tmp); |
| 4385 | body = _Py_asdl_seq_new(len, arena); |
| 4386 | if (body == NULL) goto failed; |
| 4387 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4388 | stmt_ty val; |
| 4389 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4390 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4391 | if (len != PyList_GET_SIZE(tmp)) { |
| 4392 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration"); |
| 4393 | goto failed; |
| 4394 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4395 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4396 | } |
| 4397 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4398 | } |
| 4399 | if (_PyObject_LookupAttrId(obj, &PyId_decorator_list, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4400 | return 1; |
| 4401 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4402 | if (tmp == NULL) { |
| 4403 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef"); |
| 4404 | return 1; |
| 4405 | } |
| 4406 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4407 | int res; |
| 4408 | Py_ssize_t len; |
| 4409 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4410 | if (!PyList_Check(tmp)) { |
| 4411 | PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4412 | goto failed; |
| 4413 | } |
| 4414 | len = PyList_GET_SIZE(tmp); |
| 4415 | decorator_list = _Py_asdl_seq_new(len, arena); |
| 4416 | if (decorator_list == NULL) goto failed; |
| 4417 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4418 | expr_ty val; |
| 4419 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4420 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4421 | if (len != PyList_GET_SIZE(tmp)) { |
| 4422 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration"); |
| 4423 | goto failed; |
| 4424 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4425 | asdl_seq_SET(decorator_list, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4426 | } |
| 4427 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4428 | } |
| 4429 | if (_PyObject_LookupAttrId(obj, &PyId_returns, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4430 | return 1; |
| 4431 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4432 | if (tmp == NULL || tmp == Py_None) { |
| 4433 | Py_CLEAR(tmp); |
| 4434 | returns = NULL; |
| 4435 | } |
| 4436 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4437 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4438 | res = obj2ast_expr(tmp, &returns, arena); |
| 4439 | if (res != 0) goto failed; |
| 4440 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4441 | } |
| 4442 | *out = AsyncFunctionDef(name, args, body, decorator_list, returns, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4443 | lineno, col_offset, end_lineno, end_col_offset, |
| 4444 | arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4445 | if (*out == NULL) goto failed; |
| 4446 | return 0; |
| 4447 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4448 | isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type); |
| 4449 | if (isinstance == -1) { |
| 4450 | return 1; |
| 4451 | } |
| 4452 | if (isinstance) { |
| 4453 | identifier name; |
| 4454 | asdl_seq* bases; |
| 4455 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4456 | asdl_seq* body; |
| 4457 | asdl_seq* decorator_list; |
| 4458 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4459 | if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) { |
| 4460 | return 1; |
| 4461 | } |
| 4462 | if (tmp == NULL) { |
| 4463 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 4464 | return 1; |
| 4465 | } |
| 4466 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4467 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4468 | res = obj2ast_identifier(tmp, &name, arena); |
| 4469 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4470 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4471 | } |
| 4472 | if (_PyObject_LookupAttrId(obj, &PyId_bases, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4473 | return 1; |
| 4474 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4475 | if (tmp == NULL) { |
| 4476 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 4477 | return 1; |
| 4478 | } |
| 4479 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4480 | int res; |
| 4481 | Py_ssize_t len; |
| 4482 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4483 | if (!PyList_Check(tmp)) { |
| 4484 | PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4485 | goto failed; |
| 4486 | } |
| 4487 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4488 | bases = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4489 | if (bases == NULL) goto failed; |
| 4490 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4491 | expr_ty val; |
| 4492 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4493 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4494 | if (len != PyList_GET_SIZE(tmp)) { |
| 4495 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration"); |
| 4496 | goto failed; |
| 4497 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4498 | asdl_seq_SET(bases, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4499 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4500 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4501 | } |
| 4502 | if (_PyObject_LookupAttrId(obj, &PyId_keywords, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4503 | return 1; |
| 4504 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4505 | if (tmp == NULL) { |
| 4506 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 4507 | return 1; |
| 4508 | } |
| 4509 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4510 | int res; |
| 4511 | Py_ssize_t len; |
| 4512 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4513 | if (!PyList_Check(tmp)) { |
| 4514 | PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4515 | goto failed; |
| 4516 | } |
| 4517 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4518 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4519 | if (keywords == NULL) goto failed; |
| 4520 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4521 | keyword_ty val; |
| 4522 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4523 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4524 | if (len != PyList_GET_SIZE(tmp)) { |
| 4525 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration"); |
| 4526 | goto failed; |
| 4527 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4528 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4529 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4530 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4531 | } |
| 4532 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4533 | return 1; |
| 4534 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4535 | if (tmp == NULL) { |
| 4536 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 4537 | return 1; |
| 4538 | } |
| 4539 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4540 | int res; |
| 4541 | Py_ssize_t len; |
| 4542 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4543 | if (!PyList_Check(tmp)) { |
| 4544 | PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4545 | goto failed; |
| 4546 | } |
| 4547 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4548 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4549 | if (body == NULL) goto failed; |
| 4550 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4551 | stmt_ty val; |
| 4552 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4553 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4554 | if (len != PyList_GET_SIZE(tmp)) { |
| 4555 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration"); |
| 4556 | goto failed; |
| 4557 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4558 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4559 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4560 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4561 | } |
| 4562 | if (_PyObject_LookupAttrId(obj, &PyId_decorator_list, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4563 | return 1; |
| 4564 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4565 | if (tmp == NULL) { |
| 4566 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 4567 | return 1; |
| 4568 | } |
| 4569 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4570 | int res; |
| 4571 | Py_ssize_t len; |
| 4572 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4573 | if (!PyList_Check(tmp)) { |
| 4574 | PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4575 | goto failed; |
| 4576 | } |
| 4577 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4578 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4579 | if (decorator_list == NULL) goto failed; |
| 4580 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4581 | expr_ty val; |
| 4582 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4583 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4584 | if (len != PyList_GET_SIZE(tmp)) { |
| 4585 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration"); |
| 4586 | goto failed; |
| 4587 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4588 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4589 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4590 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4591 | } |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 4592 | *out = ClassDef(name, bases, keywords, body, decorator_list, lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4593 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4594 | if (*out == NULL) goto failed; |
| 4595 | return 0; |
| 4596 | } |
| 4597 | isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type); |
| 4598 | if (isinstance == -1) { |
| 4599 | return 1; |
| 4600 | } |
| 4601 | if (isinstance) { |
| 4602 | expr_ty value; |
| 4603 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4604 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 4605 | return 1; |
| 4606 | } |
| 4607 | if (tmp == NULL || tmp == Py_None) { |
| 4608 | Py_CLEAR(tmp); |
| 4609 | value = NULL; |
| 4610 | } |
| 4611 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4612 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4613 | res = obj2ast_expr(tmp, &value, arena); |
| 4614 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4615 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4616 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4617 | *out = Return(value, lineno, col_offset, end_lineno, end_col_offset, |
| 4618 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4619 | if (*out == NULL) goto failed; |
| 4620 | return 0; |
| 4621 | } |
| 4622 | isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type); |
| 4623 | if (isinstance == -1) { |
| 4624 | return 1; |
| 4625 | } |
| 4626 | if (isinstance) { |
| 4627 | asdl_seq* targets; |
| 4628 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4629 | if (_PyObject_LookupAttrId(obj, &PyId_targets, &tmp) < 0) { |
| 4630 | return 1; |
| 4631 | } |
| 4632 | if (tmp == NULL) { |
| 4633 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 4634 | return 1; |
| 4635 | } |
| 4636 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4637 | int res; |
| 4638 | Py_ssize_t len; |
| 4639 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4640 | if (!PyList_Check(tmp)) { |
| 4641 | PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4642 | goto failed; |
| 4643 | } |
| 4644 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4645 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4646 | if (targets == NULL) goto failed; |
| 4647 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4648 | expr_ty val; |
| 4649 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4650 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4651 | if (len != PyList_GET_SIZE(tmp)) { |
| 4652 | PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration"); |
| 4653 | goto failed; |
| 4654 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4655 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4656 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4657 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4658 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4659 | *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset, |
| 4660 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4661 | if (*out == NULL) goto failed; |
| 4662 | return 0; |
| 4663 | } |
| 4664 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type); |
| 4665 | if (isinstance == -1) { |
| 4666 | return 1; |
| 4667 | } |
| 4668 | if (isinstance) { |
| 4669 | asdl_seq* targets; |
| 4670 | expr_ty value; |
| 4671 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4672 | if (_PyObject_LookupAttrId(obj, &PyId_targets, &tmp) < 0) { |
| 4673 | return 1; |
| 4674 | } |
| 4675 | if (tmp == NULL) { |
| 4676 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 4677 | return 1; |
| 4678 | } |
| 4679 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4680 | int res; |
| 4681 | Py_ssize_t len; |
| 4682 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4683 | if (!PyList_Check(tmp)) { |
| 4684 | PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4685 | goto failed; |
| 4686 | } |
| 4687 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4688 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4689 | if (targets == NULL) goto failed; |
| 4690 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4691 | expr_ty val; |
| 4692 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4693 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4694 | if (len != PyList_GET_SIZE(tmp)) { |
| 4695 | PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration"); |
| 4696 | goto failed; |
| 4697 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4698 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4699 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4700 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4701 | } |
| 4702 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4703 | return 1; |
| 4704 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4705 | if (tmp == NULL) { |
| 4706 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 4707 | return 1; |
| 4708 | } |
| 4709 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4710 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4711 | res = obj2ast_expr(tmp, &value, arena); |
| 4712 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4713 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4714 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4715 | *out = Assign(targets, value, lineno, col_offset, end_lineno, |
| 4716 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4717 | if (*out == NULL) goto failed; |
| 4718 | return 0; |
| 4719 | } |
| 4720 | isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type); |
| 4721 | if (isinstance == -1) { |
| 4722 | return 1; |
| 4723 | } |
| 4724 | if (isinstance) { |
| 4725 | expr_ty target; |
| 4726 | operator_ty op; |
| 4727 | expr_ty value; |
| 4728 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4729 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 4730 | return 1; |
| 4731 | } |
| 4732 | if (tmp == NULL) { |
| 4733 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 4734 | return 1; |
| 4735 | } |
| 4736 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4737 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4738 | res = obj2ast_expr(tmp, &target, arena); |
| 4739 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4740 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4741 | } |
| 4742 | if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4743 | return 1; |
| 4744 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4745 | if (tmp == NULL) { |
| 4746 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 4747 | return 1; |
| 4748 | } |
| 4749 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4750 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4751 | res = obj2ast_operator(tmp, &op, arena); |
| 4752 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4753 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4754 | } |
| 4755 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4756 | return 1; |
| 4757 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4758 | if (tmp == NULL) { |
| 4759 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 4760 | return 1; |
| 4761 | } |
| 4762 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4763 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4764 | res = obj2ast_expr(tmp, &value, arena); |
| 4765 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4766 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4767 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4768 | *out = AugAssign(target, op, value, lineno, col_offset, end_lineno, |
| 4769 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4770 | if (*out == NULL) goto failed; |
| 4771 | return 0; |
| 4772 | } |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4773 | isinstance = PyObject_IsInstance(obj, (PyObject*)AnnAssign_type); |
| 4774 | if (isinstance == -1) { |
| 4775 | return 1; |
| 4776 | } |
| 4777 | if (isinstance) { |
| 4778 | expr_ty target; |
| 4779 | expr_ty annotation; |
| 4780 | expr_ty value; |
| 4781 | int simple; |
| 4782 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4783 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 4784 | return 1; |
| 4785 | } |
| 4786 | if (tmp == NULL) { |
| 4787 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign"); |
| 4788 | return 1; |
| 4789 | } |
| 4790 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4791 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4792 | res = obj2ast_expr(tmp, &target, arena); |
| 4793 | if (res != 0) goto failed; |
| 4794 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4795 | } |
| 4796 | if (_PyObject_LookupAttrId(obj, &PyId_annotation, &tmp) < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4797 | return 1; |
| 4798 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4799 | if (tmp == NULL) { |
| 4800 | PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign"); |
| 4801 | return 1; |
| 4802 | } |
| 4803 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4804 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4805 | res = obj2ast_expr(tmp, &annotation, arena); |
| 4806 | if (res != 0) goto failed; |
| 4807 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4808 | } |
| 4809 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4810 | return 1; |
| 4811 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4812 | if (tmp == NULL || tmp == Py_None) { |
| 4813 | Py_CLEAR(tmp); |
| 4814 | value = NULL; |
| 4815 | } |
| 4816 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4817 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4818 | res = obj2ast_expr(tmp, &value, arena); |
| 4819 | if (res != 0) goto failed; |
| 4820 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4821 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4822 | if (_PyObject_LookupAttrId(obj, &PyId_simple, &tmp) < 0) { |
| 4823 | return 1; |
| 4824 | } |
| 4825 | if (tmp == NULL) { |
| 4826 | PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign"); |
| 4827 | return 1; |
| 4828 | } |
| 4829 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4830 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4831 | res = obj2ast_int(tmp, &simple, arena); |
| 4832 | if (res != 0) goto failed; |
| 4833 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4834 | } |
| 4835 | *out = AnnAssign(target, annotation, value, simple, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4836 | end_lineno, end_col_offset, arena); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4837 | if (*out == NULL) goto failed; |
| 4838 | return 0; |
| 4839 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4840 | isinstance = PyObject_IsInstance(obj, (PyObject*)For_type); |
| 4841 | if (isinstance == -1) { |
| 4842 | return 1; |
| 4843 | } |
| 4844 | if (isinstance) { |
| 4845 | expr_ty target; |
| 4846 | expr_ty iter; |
| 4847 | asdl_seq* body; |
| 4848 | asdl_seq* orelse; |
| 4849 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4850 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 4851 | return 1; |
| 4852 | } |
| 4853 | if (tmp == NULL) { |
| 4854 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 4855 | return 1; |
| 4856 | } |
| 4857 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4858 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4859 | res = obj2ast_expr(tmp, &target, arena); |
| 4860 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4861 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4862 | } |
| 4863 | if (_PyObject_LookupAttrId(obj, &PyId_iter, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4864 | return 1; |
| 4865 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4866 | if (tmp == NULL) { |
| 4867 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 4868 | return 1; |
| 4869 | } |
| 4870 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4871 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4872 | res = obj2ast_expr(tmp, &iter, arena); |
| 4873 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4874 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4875 | } |
| 4876 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4877 | return 1; |
| 4878 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4879 | if (tmp == NULL) { |
| 4880 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 4881 | return 1; |
| 4882 | } |
| 4883 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4884 | int res; |
| 4885 | Py_ssize_t len; |
| 4886 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4887 | if (!PyList_Check(tmp)) { |
| 4888 | PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4889 | goto failed; |
| 4890 | } |
| 4891 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4892 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4893 | if (body == NULL) goto failed; |
| 4894 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4895 | stmt_ty val; |
| 4896 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4897 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4898 | if (len != PyList_GET_SIZE(tmp)) { |
| 4899 | PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration"); |
| 4900 | goto failed; |
| 4901 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4902 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4903 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4904 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4905 | } |
| 4906 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4907 | return 1; |
| 4908 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4909 | if (tmp == NULL) { |
| 4910 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 4911 | return 1; |
| 4912 | } |
| 4913 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4914 | int res; |
| 4915 | Py_ssize_t len; |
| 4916 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4917 | if (!PyList_Check(tmp)) { |
| 4918 | PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4919 | goto failed; |
| 4920 | } |
| 4921 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4922 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4923 | if (orelse == NULL) goto failed; |
| 4924 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4925 | stmt_ty val; |
| 4926 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4927 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4928 | if (len != PyList_GET_SIZE(tmp)) { |
| 4929 | PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration"); |
| 4930 | goto failed; |
| 4931 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4932 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4933 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4934 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4935 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4936 | *out = For(target, iter, body, orelse, lineno, col_offset, end_lineno, |
| 4937 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4938 | if (*out == NULL) goto failed; |
| 4939 | return 0; |
| 4940 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4941 | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncFor_type); |
| 4942 | if (isinstance == -1) { |
| 4943 | return 1; |
| 4944 | } |
| 4945 | if (isinstance) { |
| 4946 | expr_ty target; |
| 4947 | expr_ty iter; |
| 4948 | asdl_seq* body; |
| 4949 | asdl_seq* orelse; |
| 4950 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4951 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 4952 | return 1; |
| 4953 | } |
| 4954 | if (tmp == NULL) { |
| 4955 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor"); |
| 4956 | return 1; |
| 4957 | } |
| 4958 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4959 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4960 | res = obj2ast_expr(tmp, &target, arena); |
| 4961 | if (res != 0) goto failed; |
| 4962 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4963 | } |
| 4964 | if (_PyObject_LookupAttrId(obj, &PyId_iter, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4965 | return 1; |
| 4966 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4967 | if (tmp == NULL) { |
| 4968 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor"); |
| 4969 | return 1; |
| 4970 | } |
| 4971 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4972 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4973 | res = obj2ast_expr(tmp, &iter, arena); |
| 4974 | if (res != 0) goto failed; |
| 4975 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4976 | } |
| 4977 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4978 | return 1; |
| 4979 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4980 | if (tmp == NULL) { |
| 4981 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor"); |
| 4982 | return 1; |
| 4983 | } |
| 4984 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4985 | int res; |
| 4986 | Py_ssize_t len; |
| 4987 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4988 | if (!PyList_Check(tmp)) { |
| 4989 | PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4990 | goto failed; |
| 4991 | } |
| 4992 | len = PyList_GET_SIZE(tmp); |
| 4993 | body = _Py_asdl_seq_new(len, arena); |
| 4994 | if (body == NULL) goto failed; |
| 4995 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4996 | stmt_ty val; |
| 4997 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4998 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4999 | if (len != PyList_GET_SIZE(tmp)) { |
| 5000 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration"); |
| 5001 | goto failed; |
| 5002 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5003 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5004 | } |
| 5005 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5006 | } |
| 5007 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5008 | return 1; |
| 5009 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5010 | if (tmp == NULL) { |
| 5011 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor"); |
| 5012 | return 1; |
| 5013 | } |
| 5014 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5015 | int res; |
| 5016 | Py_ssize_t len; |
| 5017 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5018 | if (!PyList_Check(tmp)) { |
| 5019 | PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5020 | goto failed; |
| 5021 | } |
| 5022 | len = PyList_GET_SIZE(tmp); |
| 5023 | orelse = _Py_asdl_seq_new(len, arena); |
| 5024 | if (orelse == NULL) goto failed; |
| 5025 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5026 | stmt_ty val; |
| 5027 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5028 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5029 | if (len != PyList_GET_SIZE(tmp)) { |
| 5030 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration"); |
| 5031 | goto failed; |
| 5032 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5033 | asdl_seq_SET(orelse, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5034 | } |
| 5035 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5036 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5037 | *out = AsyncFor(target, iter, body, orelse, lineno, col_offset, |
| 5038 | end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5039 | if (*out == NULL) goto failed; |
| 5040 | return 0; |
| 5041 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5042 | isinstance = PyObject_IsInstance(obj, (PyObject*)While_type); |
| 5043 | if (isinstance == -1) { |
| 5044 | return 1; |
| 5045 | } |
| 5046 | if (isinstance) { |
| 5047 | expr_ty test; |
| 5048 | asdl_seq* body; |
| 5049 | asdl_seq* orelse; |
| 5050 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5051 | if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) { |
| 5052 | return 1; |
| 5053 | } |
| 5054 | if (tmp == NULL) { |
| 5055 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 5056 | return 1; |
| 5057 | } |
| 5058 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5059 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5060 | res = obj2ast_expr(tmp, &test, arena); |
| 5061 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5062 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5063 | } |
| 5064 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5065 | return 1; |
| 5066 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5067 | if (tmp == NULL) { |
| 5068 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 5069 | return 1; |
| 5070 | } |
| 5071 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5072 | int res; |
| 5073 | Py_ssize_t len; |
| 5074 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5075 | if (!PyList_Check(tmp)) { |
| 5076 | PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5077 | goto failed; |
| 5078 | } |
| 5079 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5080 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5081 | if (body == NULL) goto failed; |
| 5082 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5083 | stmt_ty val; |
| 5084 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5085 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5086 | if (len != PyList_GET_SIZE(tmp)) { |
| 5087 | PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration"); |
| 5088 | goto failed; |
| 5089 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5090 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5091 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5092 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5093 | } |
| 5094 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5095 | return 1; |
| 5096 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5097 | if (tmp == NULL) { |
| 5098 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 5099 | return 1; |
| 5100 | } |
| 5101 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5102 | int res; |
| 5103 | Py_ssize_t len; |
| 5104 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5105 | if (!PyList_Check(tmp)) { |
| 5106 | PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5107 | goto failed; |
| 5108 | } |
| 5109 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5110 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5111 | if (orelse == NULL) goto failed; |
| 5112 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5113 | stmt_ty val; |
| 5114 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5115 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5116 | if (len != PyList_GET_SIZE(tmp)) { |
| 5117 | PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration"); |
| 5118 | goto failed; |
| 5119 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5120 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5121 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5122 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5123 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5124 | *out = While(test, body, orelse, lineno, col_offset, end_lineno, |
| 5125 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5126 | if (*out == NULL) goto failed; |
| 5127 | return 0; |
| 5128 | } |
| 5129 | isinstance = PyObject_IsInstance(obj, (PyObject*)If_type); |
| 5130 | if (isinstance == -1) { |
| 5131 | return 1; |
| 5132 | } |
| 5133 | if (isinstance) { |
| 5134 | expr_ty test; |
| 5135 | asdl_seq* body; |
| 5136 | asdl_seq* orelse; |
| 5137 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5138 | if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) { |
| 5139 | return 1; |
| 5140 | } |
| 5141 | if (tmp == NULL) { |
| 5142 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 5143 | return 1; |
| 5144 | } |
| 5145 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5146 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5147 | res = obj2ast_expr(tmp, &test, arena); |
| 5148 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5149 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5150 | } |
| 5151 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5152 | return 1; |
| 5153 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5154 | if (tmp == NULL) { |
| 5155 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 5156 | return 1; |
| 5157 | } |
| 5158 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5159 | int res; |
| 5160 | Py_ssize_t len; |
| 5161 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5162 | if (!PyList_Check(tmp)) { |
| 5163 | PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5164 | goto failed; |
| 5165 | } |
| 5166 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5167 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5168 | if (body == NULL) goto failed; |
| 5169 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5170 | stmt_ty val; |
| 5171 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5172 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5173 | if (len != PyList_GET_SIZE(tmp)) { |
| 5174 | PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration"); |
| 5175 | goto failed; |
| 5176 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5177 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5178 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5179 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5180 | } |
| 5181 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5182 | return 1; |
| 5183 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5184 | if (tmp == NULL) { |
| 5185 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 5186 | return 1; |
| 5187 | } |
| 5188 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5189 | int res; |
| 5190 | Py_ssize_t len; |
| 5191 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5192 | if (!PyList_Check(tmp)) { |
| 5193 | PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5194 | goto failed; |
| 5195 | } |
| 5196 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5197 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5198 | if (orelse == NULL) goto failed; |
| 5199 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5200 | stmt_ty val; |
| 5201 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5202 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5203 | if (len != PyList_GET_SIZE(tmp)) { |
| 5204 | PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration"); |
| 5205 | goto failed; |
| 5206 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5207 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5208 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5209 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5210 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5211 | *out = If(test, body, orelse, lineno, col_offset, end_lineno, |
| 5212 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5213 | if (*out == NULL) goto failed; |
| 5214 | return 0; |
| 5215 | } |
| 5216 | isinstance = PyObject_IsInstance(obj, (PyObject*)With_type); |
| 5217 | if (isinstance == -1) { |
| 5218 | return 1; |
| 5219 | } |
| 5220 | if (isinstance) { |
| 5221 | asdl_seq* items; |
| 5222 | asdl_seq* body; |
| 5223 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5224 | if (_PyObject_LookupAttrId(obj, &PyId_items, &tmp) < 0) { |
| 5225 | return 1; |
| 5226 | } |
| 5227 | if (tmp == NULL) { |
| 5228 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); |
| 5229 | return 1; |
| 5230 | } |
| 5231 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5232 | int res; |
| 5233 | Py_ssize_t len; |
| 5234 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5235 | if (!PyList_Check(tmp)) { |
| 5236 | PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5237 | goto failed; |
| 5238 | } |
| 5239 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5240 | items = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5241 | if (items == NULL) goto failed; |
| 5242 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5243 | withitem_ty val; |
| 5244 | res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5245 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5246 | if (len != PyList_GET_SIZE(tmp)) { |
| 5247 | PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration"); |
| 5248 | goto failed; |
| 5249 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5250 | asdl_seq_SET(items, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5251 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5252 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5253 | } |
| 5254 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5255 | return 1; |
| 5256 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5257 | if (tmp == NULL) { |
| 5258 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 5259 | return 1; |
| 5260 | } |
| 5261 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5262 | int res; |
| 5263 | Py_ssize_t len; |
| 5264 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5265 | if (!PyList_Check(tmp)) { |
| 5266 | PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5267 | goto failed; |
| 5268 | } |
| 5269 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5270 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5271 | if (body == NULL) goto failed; |
| 5272 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5273 | stmt_ty val; |
| 5274 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5275 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5276 | if (len != PyList_GET_SIZE(tmp)) { |
| 5277 | PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration"); |
| 5278 | goto failed; |
| 5279 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5280 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5281 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5282 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5283 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5284 | *out = With(items, body, lineno, col_offset, end_lineno, |
| 5285 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5286 | if (*out == NULL) goto failed; |
| 5287 | return 0; |
| 5288 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5289 | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncWith_type); |
| 5290 | if (isinstance == -1) { |
| 5291 | return 1; |
| 5292 | } |
| 5293 | if (isinstance) { |
| 5294 | asdl_seq* items; |
| 5295 | asdl_seq* body; |
| 5296 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5297 | if (_PyObject_LookupAttrId(obj, &PyId_items, &tmp) < 0) { |
| 5298 | return 1; |
| 5299 | } |
| 5300 | if (tmp == NULL) { |
| 5301 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith"); |
| 5302 | return 1; |
| 5303 | } |
| 5304 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5305 | int res; |
| 5306 | Py_ssize_t len; |
| 5307 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5308 | if (!PyList_Check(tmp)) { |
| 5309 | PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5310 | goto failed; |
| 5311 | } |
| 5312 | len = PyList_GET_SIZE(tmp); |
| 5313 | items = _Py_asdl_seq_new(len, arena); |
| 5314 | if (items == NULL) goto failed; |
| 5315 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5316 | withitem_ty val; |
| 5317 | res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5318 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5319 | if (len != PyList_GET_SIZE(tmp)) { |
| 5320 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration"); |
| 5321 | goto failed; |
| 5322 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5323 | asdl_seq_SET(items, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5324 | } |
| 5325 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5326 | } |
| 5327 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5328 | return 1; |
| 5329 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5330 | if (tmp == NULL) { |
| 5331 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith"); |
| 5332 | return 1; |
| 5333 | } |
| 5334 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5335 | int res; |
| 5336 | Py_ssize_t len; |
| 5337 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5338 | if (!PyList_Check(tmp)) { |
| 5339 | PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5340 | goto failed; |
| 5341 | } |
| 5342 | len = PyList_GET_SIZE(tmp); |
| 5343 | body = _Py_asdl_seq_new(len, arena); |
| 5344 | if (body == NULL) goto failed; |
| 5345 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5346 | stmt_ty val; |
| 5347 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5348 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5349 | if (len != PyList_GET_SIZE(tmp)) { |
| 5350 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration"); |
| 5351 | goto failed; |
| 5352 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5353 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5354 | } |
| 5355 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5356 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5357 | *out = AsyncWith(items, body, lineno, col_offset, end_lineno, |
| 5358 | end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5359 | if (*out == NULL) goto failed; |
| 5360 | return 0; |
| 5361 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5362 | isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type); |
| 5363 | if (isinstance == -1) { |
| 5364 | return 1; |
| 5365 | } |
| 5366 | if (isinstance) { |
| 5367 | expr_ty exc; |
| 5368 | expr_ty cause; |
| 5369 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5370 | if (_PyObject_LookupAttrId(obj, &PyId_exc, &tmp) < 0) { |
| 5371 | return 1; |
| 5372 | } |
| 5373 | if (tmp == NULL || tmp == Py_None) { |
| 5374 | Py_CLEAR(tmp); |
| 5375 | exc = NULL; |
| 5376 | } |
| 5377 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5378 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5379 | res = obj2ast_expr(tmp, &exc, arena); |
| 5380 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5381 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5382 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5383 | if (_PyObject_LookupAttrId(obj, &PyId_cause, &tmp) < 0) { |
| 5384 | return 1; |
| 5385 | } |
| 5386 | if (tmp == NULL || tmp == Py_None) { |
| 5387 | Py_CLEAR(tmp); |
| 5388 | cause = NULL; |
| 5389 | } |
| 5390 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5391 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5392 | res = obj2ast_expr(tmp, &cause, arena); |
| 5393 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5394 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5395 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5396 | *out = Raise(exc, cause, lineno, col_offset, end_lineno, |
| 5397 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5398 | if (*out == NULL) goto failed; |
| 5399 | return 0; |
| 5400 | } |
| 5401 | isinstance = PyObject_IsInstance(obj, (PyObject*)Try_type); |
| 5402 | if (isinstance == -1) { |
| 5403 | return 1; |
| 5404 | } |
| 5405 | if (isinstance) { |
| 5406 | asdl_seq* body; |
| 5407 | asdl_seq* handlers; |
| 5408 | asdl_seq* orelse; |
| 5409 | asdl_seq* finalbody; |
| 5410 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5411 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 5412 | return 1; |
| 5413 | } |
| 5414 | if (tmp == NULL) { |
| 5415 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); |
| 5416 | return 1; |
| 5417 | } |
| 5418 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5419 | int res; |
| 5420 | Py_ssize_t len; |
| 5421 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5422 | if (!PyList_Check(tmp)) { |
| 5423 | PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5424 | goto failed; |
| 5425 | } |
| 5426 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5427 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5428 | if (body == NULL) goto failed; |
| 5429 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5430 | stmt_ty val; |
| 5431 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5432 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5433 | if (len != PyList_GET_SIZE(tmp)) { |
| 5434 | PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration"); |
| 5435 | goto failed; |
| 5436 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5437 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5438 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5439 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5440 | } |
| 5441 | if (_PyObject_LookupAttrId(obj, &PyId_handlers, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5442 | return 1; |
| 5443 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5444 | if (tmp == NULL) { |
| 5445 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); |
| 5446 | return 1; |
| 5447 | } |
| 5448 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5449 | int res; |
| 5450 | Py_ssize_t len; |
| 5451 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5452 | if (!PyList_Check(tmp)) { |
| 5453 | PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5454 | goto failed; |
| 5455 | } |
| 5456 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5457 | handlers = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5458 | if (handlers == NULL) goto failed; |
| 5459 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5460 | excepthandler_ty val; |
| 5461 | res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5462 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5463 | if (len != PyList_GET_SIZE(tmp)) { |
| 5464 | PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration"); |
| 5465 | goto failed; |
| 5466 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5467 | asdl_seq_SET(handlers, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5468 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5469 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5470 | } |
| 5471 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5472 | return 1; |
| 5473 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5474 | if (tmp == NULL) { |
| 5475 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); |
| 5476 | return 1; |
| 5477 | } |
| 5478 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5479 | int res; |
| 5480 | Py_ssize_t len; |
| 5481 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5482 | if (!PyList_Check(tmp)) { |
| 5483 | PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5484 | goto failed; |
| 5485 | } |
| 5486 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5487 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5488 | if (orelse == NULL) goto failed; |
| 5489 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5490 | stmt_ty val; |
| 5491 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5492 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5493 | if (len != PyList_GET_SIZE(tmp)) { |
| 5494 | PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration"); |
| 5495 | goto failed; |
| 5496 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5497 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5498 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5499 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5500 | } |
| 5501 | if (_PyObject_LookupAttrId(obj, &PyId_finalbody, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5502 | return 1; |
| 5503 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5504 | if (tmp == NULL) { |
| 5505 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); |
| 5506 | return 1; |
| 5507 | } |
| 5508 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5509 | int res; |
| 5510 | Py_ssize_t len; |
| 5511 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5512 | if (!PyList_Check(tmp)) { |
| 5513 | PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5514 | goto failed; |
| 5515 | } |
| 5516 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5517 | finalbody = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5518 | if (finalbody == NULL) goto failed; |
| 5519 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5520 | stmt_ty val; |
| 5521 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5522 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5523 | if (len != PyList_GET_SIZE(tmp)) { |
| 5524 | PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration"); |
| 5525 | goto failed; |
| 5526 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5527 | asdl_seq_SET(finalbody, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5528 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5529 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5530 | } |
| 5531 | *out = Try(body, handlers, orelse, finalbody, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5532 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5533 | if (*out == NULL) goto failed; |
| 5534 | return 0; |
| 5535 | } |
| 5536 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type); |
| 5537 | if (isinstance == -1) { |
| 5538 | return 1; |
| 5539 | } |
| 5540 | if (isinstance) { |
| 5541 | expr_ty test; |
| 5542 | expr_ty msg; |
| 5543 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5544 | if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) { |
| 5545 | return 1; |
| 5546 | } |
| 5547 | if (tmp == NULL) { |
| 5548 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 5549 | return 1; |
| 5550 | } |
| 5551 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5552 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5553 | res = obj2ast_expr(tmp, &test, arena); |
| 5554 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5555 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5556 | } |
| 5557 | if (_PyObject_LookupAttrId(obj, &PyId_msg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5558 | return 1; |
| 5559 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5560 | if (tmp == NULL || tmp == Py_None) { |
| 5561 | Py_CLEAR(tmp); |
| 5562 | msg = NULL; |
| 5563 | } |
| 5564 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5565 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5566 | res = obj2ast_expr(tmp, &msg, arena); |
| 5567 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5568 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5569 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5570 | *out = Assert(test, msg, lineno, col_offset, end_lineno, |
| 5571 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5572 | if (*out == NULL) goto failed; |
| 5573 | return 0; |
| 5574 | } |
| 5575 | isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type); |
| 5576 | if (isinstance == -1) { |
| 5577 | return 1; |
| 5578 | } |
| 5579 | if (isinstance) { |
| 5580 | asdl_seq* names; |
| 5581 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5582 | if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) { |
| 5583 | return 1; |
| 5584 | } |
| 5585 | if (tmp == NULL) { |
| 5586 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 5587 | return 1; |
| 5588 | } |
| 5589 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5590 | int res; |
| 5591 | Py_ssize_t len; |
| 5592 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5593 | if (!PyList_Check(tmp)) { |
| 5594 | PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5595 | goto failed; |
| 5596 | } |
| 5597 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5598 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5599 | if (names == NULL) goto failed; |
| 5600 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5601 | alias_ty val; |
| 5602 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5603 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5604 | if (len != PyList_GET_SIZE(tmp)) { |
| 5605 | PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration"); |
| 5606 | goto failed; |
| 5607 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5608 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5609 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5610 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5611 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5612 | *out = Import(names, lineno, col_offset, end_lineno, end_col_offset, |
| 5613 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5614 | if (*out == NULL) goto failed; |
| 5615 | return 0; |
| 5616 | } |
| 5617 | isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type); |
| 5618 | if (isinstance == -1) { |
| 5619 | return 1; |
| 5620 | } |
| 5621 | if (isinstance) { |
| 5622 | identifier module; |
| 5623 | asdl_seq* names; |
| 5624 | int level; |
| 5625 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5626 | if (_PyObject_LookupAttrId(obj, &PyId_module, &tmp) < 0) { |
| 5627 | return 1; |
| 5628 | } |
| 5629 | if (tmp == NULL || tmp == Py_None) { |
| 5630 | Py_CLEAR(tmp); |
| 5631 | module = NULL; |
| 5632 | } |
| 5633 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5634 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5635 | res = obj2ast_identifier(tmp, &module, arena); |
| 5636 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5637 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5638 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5639 | if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) { |
| 5640 | return 1; |
| 5641 | } |
| 5642 | if (tmp == NULL) { |
| 5643 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 5644 | return 1; |
| 5645 | } |
| 5646 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5647 | int res; |
| 5648 | Py_ssize_t len; |
| 5649 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5650 | if (!PyList_Check(tmp)) { |
| 5651 | PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5652 | goto failed; |
| 5653 | } |
| 5654 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5655 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5656 | if (names == NULL) goto failed; |
| 5657 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5658 | alias_ty val; |
| 5659 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5660 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5661 | if (len != PyList_GET_SIZE(tmp)) { |
| 5662 | PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration"); |
| 5663 | goto failed; |
| 5664 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5665 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5666 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5667 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5668 | } |
| 5669 | if (_PyObject_LookupAttrId(obj, &PyId_level, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5670 | return 1; |
| 5671 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5672 | if (tmp == NULL || tmp == Py_None) { |
| 5673 | Py_CLEAR(tmp); |
| 5674 | level = 0; |
| 5675 | } |
| 5676 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5677 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5678 | res = obj2ast_int(tmp, &level, arena); |
| 5679 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5680 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5681 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5682 | *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno, |
| 5683 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5684 | if (*out == NULL) goto failed; |
| 5685 | return 0; |
| 5686 | } |
| 5687 | isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type); |
| 5688 | if (isinstance == -1) { |
| 5689 | return 1; |
| 5690 | } |
| 5691 | if (isinstance) { |
| 5692 | asdl_seq* names; |
| 5693 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5694 | if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) { |
| 5695 | return 1; |
| 5696 | } |
| 5697 | if (tmp == NULL) { |
| 5698 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 5699 | return 1; |
| 5700 | } |
| 5701 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5702 | int res; |
| 5703 | Py_ssize_t len; |
| 5704 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5705 | if (!PyList_Check(tmp)) { |
| 5706 | PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5707 | goto failed; |
| 5708 | } |
| 5709 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5710 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5711 | if (names == NULL) goto failed; |
| 5712 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5713 | identifier val; |
| 5714 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5715 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5716 | if (len != PyList_GET_SIZE(tmp)) { |
| 5717 | PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration"); |
| 5718 | goto failed; |
| 5719 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5720 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5721 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5722 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5723 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5724 | *out = Global(names, lineno, col_offset, end_lineno, end_col_offset, |
| 5725 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5726 | if (*out == NULL) goto failed; |
| 5727 | return 0; |
| 5728 | } |
| 5729 | isinstance = PyObject_IsInstance(obj, (PyObject*)Nonlocal_type); |
| 5730 | if (isinstance == -1) { |
| 5731 | return 1; |
| 5732 | } |
| 5733 | if (isinstance) { |
| 5734 | asdl_seq* names; |
| 5735 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5736 | if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) { |
| 5737 | return 1; |
| 5738 | } |
| 5739 | if (tmp == NULL) { |
| 5740 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 5741 | return 1; |
| 5742 | } |
| 5743 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5744 | int res; |
| 5745 | Py_ssize_t len; |
| 5746 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5747 | if (!PyList_Check(tmp)) { |
| 5748 | PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5749 | goto failed; |
| 5750 | } |
| 5751 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5752 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5753 | if (names == NULL) goto failed; |
| 5754 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5755 | identifier val; |
| 5756 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5757 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5758 | if (len != PyList_GET_SIZE(tmp)) { |
| 5759 | PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration"); |
| 5760 | goto failed; |
| 5761 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5762 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5763 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5764 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5765 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5766 | *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset, |
| 5767 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5768 | if (*out == NULL) goto failed; |
| 5769 | return 0; |
| 5770 | } |
| 5771 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type); |
| 5772 | if (isinstance == -1) { |
| 5773 | return 1; |
| 5774 | } |
| 5775 | if (isinstance) { |
| 5776 | expr_ty value; |
| 5777 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5778 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 5779 | return 1; |
| 5780 | } |
| 5781 | if (tmp == NULL) { |
| 5782 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 5783 | return 1; |
| 5784 | } |
| 5785 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5786 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5787 | res = obj2ast_expr(tmp, &value, arena); |
| 5788 | if (res != 0) goto failed; |
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 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5791 | *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset, |
| 5792 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5793 | if (*out == NULL) goto failed; |
| 5794 | return 0; |
| 5795 | } |
| 5796 | isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type); |
| 5797 | if (isinstance == -1) { |
| 5798 | return 1; |
| 5799 | } |
| 5800 | if (isinstance) { |
| 5801 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5802 | *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5803 | if (*out == NULL) goto failed; |
| 5804 | return 0; |
| 5805 | } |
| 5806 | isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type); |
| 5807 | if (isinstance == -1) { |
| 5808 | return 1; |
| 5809 | } |
| 5810 | if (isinstance) { |
| 5811 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5812 | *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5813 | if (*out == NULL) goto failed; |
| 5814 | return 0; |
| 5815 | } |
| 5816 | isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type); |
| 5817 | if (isinstance == -1) { |
| 5818 | return 1; |
| 5819 | } |
| 5820 | if (isinstance) { |
| 5821 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5822 | *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5823 | if (*out == NULL) goto failed; |
| 5824 | return 0; |
| 5825 | } |
| 5826 | |
| 5827 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
| 5828 | failed: |
| 5829 | Py_XDECREF(tmp); |
| 5830 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5831 | } |
| 5832 | |
| 5833 | int |
| 5834 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 5835 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5836 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5837 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5838 | PyObject *tmp = NULL; |
| 5839 | int lineno; |
| 5840 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5841 | int end_lineno; |
| 5842 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5843 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5844 | if (obj == Py_None) { |
| 5845 | *out = NULL; |
| 5846 | return 0; |
| 5847 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5848 | if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) { |
| 5849 | return 1; |
| 5850 | } |
| 5851 | if (tmp == NULL) { |
| 5852 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 5853 | return 1; |
| 5854 | } |
| 5855 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5856 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5857 | res = obj2ast_int(tmp, &lineno, arena); |
| 5858 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5859 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5860 | } |
| 5861 | if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5862 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5863 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5864 | if (tmp == NULL) { |
| 5865 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 5866 | return 1; |
| 5867 | } |
| 5868 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5869 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5870 | res = obj2ast_int(tmp, &col_offset, arena); |
| 5871 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5872 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5873 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5874 | if (_PyObject_LookupAttrId(obj, &PyId_end_lineno, &tmp) < 0) { |
| 5875 | return 1; |
| 5876 | } |
| 5877 | if (tmp == NULL || tmp == Py_None) { |
| 5878 | Py_CLEAR(tmp); |
| 5879 | end_lineno = 0; |
| 5880 | } |
| 5881 | else { |
| 5882 | int res; |
| 5883 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 5884 | if (res != 0) goto failed; |
| 5885 | Py_CLEAR(tmp); |
| 5886 | } |
| 5887 | if (_PyObject_LookupAttrId(obj, &PyId_end_col_offset, &tmp) < 0) { |
| 5888 | return 1; |
| 5889 | } |
| 5890 | if (tmp == NULL || tmp == Py_None) { |
| 5891 | Py_CLEAR(tmp); |
| 5892 | end_col_offset = 0; |
| 5893 | } |
| 5894 | else { |
| 5895 | int res; |
| 5896 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 5897 | if (res != 0) goto failed; |
| 5898 | Py_CLEAR(tmp); |
| 5899 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5900 | isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type); |
| 5901 | if (isinstance == -1) { |
| 5902 | return 1; |
| 5903 | } |
| 5904 | if (isinstance) { |
| 5905 | boolop_ty op; |
| 5906 | asdl_seq* values; |
| 5907 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5908 | if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) { |
| 5909 | return 1; |
| 5910 | } |
| 5911 | if (tmp == NULL) { |
| 5912 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 5913 | return 1; |
| 5914 | } |
| 5915 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5916 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5917 | res = obj2ast_boolop(tmp, &op, arena); |
| 5918 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5919 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5920 | } |
| 5921 | if (_PyObject_LookupAttrId(obj, &PyId_values, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5922 | return 1; |
| 5923 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5924 | if (tmp == NULL) { |
| 5925 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 5926 | return 1; |
| 5927 | } |
| 5928 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5929 | int res; |
| 5930 | Py_ssize_t len; |
| 5931 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5932 | if (!PyList_Check(tmp)) { |
| 5933 | PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5934 | goto failed; |
| 5935 | } |
| 5936 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5937 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5938 | if (values == NULL) goto failed; |
| 5939 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5940 | expr_ty val; |
| 5941 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5942 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5943 | if (len != PyList_GET_SIZE(tmp)) { |
| 5944 | PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration"); |
| 5945 | goto failed; |
| 5946 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5947 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5948 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5949 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5950 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5951 | *out = BoolOp(op, values, lineno, col_offset, end_lineno, |
| 5952 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5953 | if (*out == NULL) goto failed; |
| 5954 | return 0; |
| 5955 | } |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 5956 | isinstance = PyObject_IsInstance(obj, (PyObject*)NamedExpr_type); |
| 5957 | if (isinstance == -1) { |
| 5958 | return 1; |
| 5959 | } |
| 5960 | if (isinstance) { |
| 5961 | expr_ty target; |
| 5962 | expr_ty value; |
| 5963 | |
| 5964 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 5965 | return 1; |
| 5966 | } |
| 5967 | if (tmp == NULL) { |
| 5968 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr"); |
| 5969 | return 1; |
| 5970 | } |
| 5971 | else { |
| 5972 | int res; |
| 5973 | res = obj2ast_expr(tmp, &target, arena); |
| 5974 | if (res != 0) goto failed; |
| 5975 | Py_CLEAR(tmp); |
| 5976 | } |
| 5977 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 5978 | return 1; |
| 5979 | } |
| 5980 | if (tmp == NULL) { |
| 5981 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr"); |
| 5982 | return 1; |
| 5983 | } |
| 5984 | else { |
| 5985 | int res; |
| 5986 | res = obj2ast_expr(tmp, &value, arena); |
| 5987 | if (res != 0) goto failed; |
| 5988 | Py_CLEAR(tmp); |
| 5989 | } |
| 5990 | *out = NamedExpr(target, value, lineno, col_offset, end_lineno, |
| 5991 | end_col_offset, arena); |
| 5992 | if (*out == NULL) goto failed; |
| 5993 | return 0; |
| 5994 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5995 | isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type); |
| 5996 | if (isinstance == -1) { |
| 5997 | return 1; |
| 5998 | } |
| 5999 | if (isinstance) { |
| 6000 | expr_ty left; |
| 6001 | operator_ty op; |
| 6002 | expr_ty right; |
| 6003 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6004 | if (_PyObject_LookupAttrId(obj, &PyId_left, &tmp) < 0) { |
| 6005 | return 1; |
| 6006 | } |
| 6007 | if (tmp == NULL) { |
| 6008 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 6009 | return 1; |
| 6010 | } |
| 6011 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6012 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6013 | res = obj2ast_expr(tmp, &left, arena); |
| 6014 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6015 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6016 | } |
| 6017 | if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6018 | return 1; |
| 6019 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6020 | if (tmp == NULL) { |
| 6021 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 6022 | return 1; |
| 6023 | } |
| 6024 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6025 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6026 | res = obj2ast_operator(tmp, &op, arena); |
| 6027 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6028 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6029 | } |
| 6030 | if (_PyObject_LookupAttrId(obj, &PyId_right, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6031 | return 1; |
| 6032 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6033 | if (tmp == NULL) { |
| 6034 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 6035 | return 1; |
| 6036 | } |
| 6037 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6038 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6039 | res = obj2ast_expr(tmp, &right, arena); |
| 6040 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6041 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6042 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6043 | *out = BinOp(left, op, right, lineno, col_offset, end_lineno, |
| 6044 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6045 | if (*out == NULL) goto failed; |
| 6046 | return 0; |
| 6047 | } |
| 6048 | isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type); |
| 6049 | if (isinstance == -1) { |
| 6050 | return 1; |
| 6051 | } |
| 6052 | if (isinstance) { |
| 6053 | unaryop_ty op; |
| 6054 | expr_ty operand; |
| 6055 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6056 | if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) { |
| 6057 | return 1; |
| 6058 | } |
| 6059 | if (tmp == NULL) { |
| 6060 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 6061 | return 1; |
| 6062 | } |
| 6063 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6064 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6065 | res = obj2ast_unaryop(tmp, &op, arena); |
| 6066 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6067 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6068 | } |
| 6069 | if (_PyObject_LookupAttrId(obj, &PyId_operand, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6070 | return 1; |
| 6071 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6072 | if (tmp == NULL) { |
| 6073 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 6074 | return 1; |
| 6075 | } |
| 6076 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6077 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6078 | res = obj2ast_expr(tmp, &operand, arena); |
| 6079 | if (res != 0) goto failed; |
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 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6082 | *out = UnaryOp(op, operand, lineno, col_offset, end_lineno, |
| 6083 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6084 | if (*out == NULL) goto failed; |
| 6085 | return 0; |
| 6086 | } |
| 6087 | isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type); |
| 6088 | if (isinstance == -1) { |
| 6089 | return 1; |
| 6090 | } |
| 6091 | if (isinstance) { |
| 6092 | arguments_ty args; |
| 6093 | expr_ty body; |
| 6094 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6095 | if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) { |
| 6096 | return 1; |
| 6097 | } |
| 6098 | if (tmp == NULL) { |
| 6099 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 6100 | return 1; |
| 6101 | } |
| 6102 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6103 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6104 | res = obj2ast_arguments(tmp, &args, arena); |
| 6105 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6106 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6107 | } |
| 6108 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6109 | return 1; |
| 6110 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6111 | if (tmp == NULL) { |
| 6112 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 6113 | return 1; |
| 6114 | } |
| 6115 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6116 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6117 | res = obj2ast_expr(tmp, &body, arena); |
| 6118 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6119 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6120 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6121 | *out = Lambda(args, body, lineno, col_offset, end_lineno, |
| 6122 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6123 | if (*out == NULL) goto failed; |
| 6124 | return 0; |
| 6125 | } |
| 6126 | isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type); |
| 6127 | if (isinstance == -1) { |
| 6128 | return 1; |
| 6129 | } |
| 6130 | if (isinstance) { |
| 6131 | expr_ty test; |
| 6132 | expr_ty body; |
| 6133 | expr_ty orelse; |
| 6134 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6135 | if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) { |
| 6136 | return 1; |
| 6137 | } |
| 6138 | if (tmp == NULL) { |
| 6139 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 6140 | return 1; |
| 6141 | } |
| 6142 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6143 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6144 | res = obj2ast_expr(tmp, &test, arena); |
| 6145 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6146 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6147 | } |
| 6148 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6149 | return 1; |
| 6150 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6151 | if (tmp == NULL) { |
| 6152 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 6153 | return 1; |
| 6154 | } |
| 6155 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6156 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6157 | res = obj2ast_expr(tmp, &body, arena); |
| 6158 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6159 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6160 | } |
| 6161 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6162 | return 1; |
| 6163 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6164 | if (tmp == NULL) { |
| 6165 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 6166 | return 1; |
| 6167 | } |
| 6168 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6169 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6170 | res = obj2ast_expr(tmp, &orelse, arena); |
| 6171 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6172 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6173 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6174 | *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno, |
| 6175 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6176 | if (*out == NULL) goto failed; |
| 6177 | return 0; |
| 6178 | } |
| 6179 | isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type); |
| 6180 | if (isinstance == -1) { |
| 6181 | return 1; |
| 6182 | } |
| 6183 | if (isinstance) { |
| 6184 | asdl_seq* keys; |
| 6185 | asdl_seq* values; |
| 6186 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6187 | if (_PyObject_LookupAttrId(obj, &PyId_keys, &tmp) < 0) { |
| 6188 | return 1; |
| 6189 | } |
| 6190 | if (tmp == NULL) { |
| 6191 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 6192 | return 1; |
| 6193 | } |
| 6194 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6195 | int res; |
| 6196 | Py_ssize_t len; |
| 6197 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6198 | if (!PyList_Check(tmp)) { |
| 6199 | PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6200 | goto failed; |
| 6201 | } |
| 6202 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6203 | keys = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6204 | if (keys == NULL) goto failed; |
| 6205 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6206 | expr_ty val; |
| 6207 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6208 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6209 | if (len != PyList_GET_SIZE(tmp)) { |
| 6210 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration"); |
| 6211 | goto failed; |
| 6212 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6213 | asdl_seq_SET(keys, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6214 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6215 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6216 | } |
| 6217 | if (_PyObject_LookupAttrId(obj, &PyId_values, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6218 | return 1; |
| 6219 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6220 | if (tmp == NULL) { |
| 6221 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 6222 | return 1; |
| 6223 | } |
| 6224 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6225 | int res; |
| 6226 | Py_ssize_t len; |
| 6227 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6228 | if (!PyList_Check(tmp)) { |
| 6229 | PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6230 | goto failed; |
| 6231 | } |
| 6232 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6233 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6234 | if (values == NULL) goto failed; |
| 6235 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6236 | expr_ty val; |
| 6237 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6238 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6239 | if (len != PyList_GET_SIZE(tmp)) { |
| 6240 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration"); |
| 6241 | goto failed; |
| 6242 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6243 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6244 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6245 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6246 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6247 | *out = Dict(keys, values, lineno, col_offset, end_lineno, |
| 6248 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6249 | if (*out == NULL) goto failed; |
| 6250 | return 0; |
| 6251 | } |
| 6252 | isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type); |
| 6253 | if (isinstance == -1) { |
| 6254 | return 1; |
| 6255 | } |
| 6256 | if (isinstance) { |
| 6257 | asdl_seq* elts; |
| 6258 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6259 | if (_PyObject_LookupAttrId(obj, &PyId_elts, &tmp) < 0) { |
| 6260 | return 1; |
| 6261 | } |
| 6262 | if (tmp == NULL) { |
| 6263 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 6264 | return 1; |
| 6265 | } |
| 6266 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6267 | int res; |
| 6268 | Py_ssize_t len; |
| 6269 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6270 | if (!PyList_Check(tmp)) { |
| 6271 | PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6272 | goto failed; |
| 6273 | } |
| 6274 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6275 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6276 | if (elts == NULL) goto failed; |
| 6277 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6278 | expr_ty val; |
| 6279 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6280 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6281 | if (len != PyList_GET_SIZE(tmp)) { |
| 6282 | PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration"); |
| 6283 | goto failed; |
| 6284 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6285 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6286 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6287 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6288 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6289 | *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6290 | if (*out == NULL) goto failed; |
| 6291 | return 0; |
| 6292 | } |
| 6293 | isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type); |
| 6294 | if (isinstance == -1) { |
| 6295 | return 1; |
| 6296 | } |
| 6297 | if (isinstance) { |
| 6298 | expr_ty elt; |
| 6299 | asdl_seq* generators; |
| 6300 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6301 | if (_PyObject_LookupAttrId(obj, &PyId_elt, &tmp) < 0) { |
| 6302 | return 1; |
| 6303 | } |
| 6304 | if (tmp == NULL) { |
| 6305 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 6306 | return 1; |
| 6307 | } |
| 6308 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6309 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6310 | res = obj2ast_expr(tmp, &elt, arena); |
| 6311 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6312 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6313 | } |
| 6314 | if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6315 | return 1; |
| 6316 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6317 | if (tmp == NULL) { |
| 6318 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 6319 | return 1; |
| 6320 | } |
| 6321 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6322 | int res; |
| 6323 | Py_ssize_t len; |
| 6324 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6325 | if (!PyList_Check(tmp)) { |
| 6326 | PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6327 | goto failed; |
| 6328 | } |
| 6329 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6330 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6331 | if (generators == NULL) goto failed; |
| 6332 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6333 | comprehension_ty val; |
| 6334 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6335 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6336 | if (len != PyList_GET_SIZE(tmp)) { |
| 6337 | PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration"); |
| 6338 | goto failed; |
| 6339 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6340 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6341 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6342 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6343 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6344 | *out = ListComp(elt, generators, lineno, col_offset, end_lineno, |
| 6345 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6346 | if (*out == NULL) goto failed; |
| 6347 | return 0; |
| 6348 | } |
| 6349 | isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type); |
| 6350 | if (isinstance == -1) { |
| 6351 | return 1; |
| 6352 | } |
| 6353 | if (isinstance) { |
| 6354 | expr_ty elt; |
| 6355 | asdl_seq* generators; |
| 6356 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6357 | if (_PyObject_LookupAttrId(obj, &PyId_elt, &tmp) < 0) { |
| 6358 | return 1; |
| 6359 | } |
| 6360 | if (tmp == NULL) { |
| 6361 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 6362 | return 1; |
| 6363 | } |
| 6364 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6365 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6366 | res = obj2ast_expr(tmp, &elt, arena); |
| 6367 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6368 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6369 | } |
| 6370 | if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6371 | return 1; |
| 6372 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6373 | if (tmp == NULL) { |
| 6374 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 6375 | return 1; |
| 6376 | } |
| 6377 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6378 | int res; |
| 6379 | Py_ssize_t len; |
| 6380 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6381 | if (!PyList_Check(tmp)) { |
| 6382 | PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6383 | goto failed; |
| 6384 | } |
| 6385 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6386 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6387 | if (generators == NULL) goto failed; |
| 6388 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6389 | comprehension_ty val; |
| 6390 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6391 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6392 | if (len != PyList_GET_SIZE(tmp)) { |
| 6393 | PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration"); |
| 6394 | goto failed; |
| 6395 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6396 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6397 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6398 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6399 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6400 | *out = SetComp(elt, generators, lineno, col_offset, end_lineno, |
| 6401 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6402 | if (*out == NULL) goto failed; |
| 6403 | return 0; |
| 6404 | } |
| 6405 | isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type); |
| 6406 | if (isinstance == -1) { |
| 6407 | return 1; |
| 6408 | } |
| 6409 | if (isinstance) { |
| 6410 | expr_ty key; |
| 6411 | expr_ty value; |
| 6412 | asdl_seq* generators; |
| 6413 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6414 | if (_PyObject_LookupAttrId(obj, &PyId_key, &tmp) < 0) { |
| 6415 | return 1; |
| 6416 | } |
| 6417 | if (tmp == NULL) { |
| 6418 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 6419 | return 1; |
| 6420 | } |
| 6421 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6422 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6423 | res = obj2ast_expr(tmp, &key, arena); |
| 6424 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6425 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6426 | } |
| 6427 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6428 | return 1; |
| 6429 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6430 | if (tmp == NULL) { |
| 6431 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 6432 | return 1; |
| 6433 | } |
| 6434 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6435 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6436 | res = obj2ast_expr(tmp, &value, arena); |
| 6437 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6438 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6439 | } |
| 6440 | if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6441 | return 1; |
| 6442 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6443 | if (tmp == NULL) { |
| 6444 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 6445 | return 1; |
| 6446 | } |
| 6447 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6448 | int res; |
| 6449 | Py_ssize_t len; |
| 6450 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6451 | if (!PyList_Check(tmp)) { |
| 6452 | PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6453 | goto failed; |
| 6454 | } |
| 6455 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6456 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6457 | if (generators == NULL) goto failed; |
| 6458 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6459 | comprehension_ty val; |
| 6460 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6461 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6462 | if (len != PyList_GET_SIZE(tmp)) { |
| 6463 | PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration"); |
| 6464 | goto failed; |
| 6465 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6466 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6467 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6468 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6469 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6470 | *out = DictComp(key, value, generators, lineno, col_offset, end_lineno, |
| 6471 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6472 | if (*out == NULL) goto failed; |
| 6473 | return 0; |
| 6474 | } |
| 6475 | isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type); |
| 6476 | if (isinstance == -1) { |
| 6477 | return 1; |
| 6478 | } |
| 6479 | if (isinstance) { |
| 6480 | expr_ty elt; |
| 6481 | asdl_seq* generators; |
| 6482 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6483 | if (_PyObject_LookupAttrId(obj, &PyId_elt, &tmp) < 0) { |
| 6484 | return 1; |
| 6485 | } |
| 6486 | if (tmp == NULL) { |
| 6487 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 6488 | return 1; |
| 6489 | } |
| 6490 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6491 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6492 | res = obj2ast_expr(tmp, &elt, arena); |
| 6493 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6494 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6495 | } |
| 6496 | if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6497 | return 1; |
| 6498 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6499 | if (tmp == NULL) { |
| 6500 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 6501 | return 1; |
| 6502 | } |
| 6503 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6504 | int res; |
| 6505 | Py_ssize_t len; |
| 6506 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6507 | if (!PyList_Check(tmp)) { |
| 6508 | PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6509 | goto failed; |
| 6510 | } |
| 6511 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6512 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6513 | if (generators == NULL) goto failed; |
| 6514 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6515 | comprehension_ty val; |
| 6516 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6517 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6518 | if (len != PyList_GET_SIZE(tmp)) { |
| 6519 | PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration"); |
| 6520 | goto failed; |
| 6521 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6522 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6523 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6524 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6525 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6526 | *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno, |
| 6527 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6528 | if (*out == NULL) goto failed; |
| 6529 | return 0; |
| 6530 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6531 | isinstance = PyObject_IsInstance(obj, (PyObject*)Await_type); |
| 6532 | if (isinstance == -1) { |
| 6533 | return 1; |
| 6534 | } |
| 6535 | if (isinstance) { |
| 6536 | expr_ty value; |
| 6537 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6538 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6539 | return 1; |
| 6540 | } |
| 6541 | if (tmp == NULL) { |
| 6542 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await"); |
| 6543 | return 1; |
| 6544 | } |
| 6545 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6546 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6547 | res = obj2ast_expr(tmp, &value, arena); |
| 6548 | if (res != 0) goto failed; |
| 6549 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6550 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6551 | *out = Await(value, lineno, col_offset, end_lineno, end_col_offset, |
| 6552 | arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6553 | if (*out == NULL) goto failed; |
| 6554 | return 0; |
| 6555 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6556 | isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); |
| 6557 | if (isinstance == -1) { |
| 6558 | return 1; |
| 6559 | } |
| 6560 | if (isinstance) { |
| 6561 | expr_ty value; |
| 6562 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6563 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6564 | return 1; |
| 6565 | } |
| 6566 | if (tmp == NULL || tmp == Py_None) { |
| 6567 | Py_CLEAR(tmp); |
| 6568 | value = NULL; |
| 6569 | } |
| 6570 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6571 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6572 | res = obj2ast_expr(tmp, &value, arena); |
| 6573 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6574 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6575 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6576 | *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset, |
| 6577 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6578 | if (*out == NULL) goto failed; |
| 6579 | return 0; |
| 6580 | } |
| 6581 | isinstance = PyObject_IsInstance(obj, (PyObject*)YieldFrom_type); |
| 6582 | if (isinstance == -1) { |
| 6583 | return 1; |
| 6584 | } |
| 6585 | if (isinstance) { |
| 6586 | expr_ty value; |
| 6587 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6588 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6589 | return 1; |
| 6590 | } |
| 6591 | if (tmp == NULL) { |
| 6592 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom"); |
| 6593 | return 1; |
| 6594 | } |
| 6595 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6596 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6597 | res = obj2ast_expr(tmp, &value, arena); |
| 6598 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6599 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6600 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6601 | *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset, |
| 6602 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6603 | if (*out == NULL) goto failed; |
| 6604 | return 0; |
| 6605 | } |
| 6606 | isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); |
| 6607 | if (isinstance == -1) { |
| 6608 | return 1; |
| 6609 | } |
| 6610 | if (isinstance) { |
| 6611 | expr_ty left; |
| 6612 | asdl_int_seq* ops; |
| 6613 | asdl_seq* comparators; |
| 6614 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6615 | if (_PyObject_LookupAttrId(obj, &PyId_left, &tmp) < 0) { |
| 6616 | return 1; |
| 6617 | } |
| 6618 | if (tmp == NULL) { |
| 6619 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 6620 | return 1; |
| 6621 | } |
| 6622 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6623 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6624 | res = obj2ast_expr(tmp, &left, arena); |
| 6625 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6626 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6627 | } |
| 6628 | if (_PyObject_LookupAttrId(obj, &PyId_ops, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6629 | return 1; |
| 6630 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6631 | if (tmp == NULL) { |
| 6632 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 6633 | return 1; |
| 6634 | } |
| 6635 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6636 | int res; |
| 6637 | Py_ssize_t len; |
| 6638 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6639 | if (!PyList_Check(tmp)) { |
| 6640 | PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6641 | goto failed; |
| 6642 | } |
| 6643 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6644 | ops = _Py_asdl_int_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6645 | if (ops == NULL) goto failed; |
| 6646 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6647 | cmpop_ty val; |
| 6648 | res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6649 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6650 | if (len != PyList_GET_SIZE(tmp)) { |
| 6651 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration"); |
| 6652 | goto failed; |
| 6653 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6654 | asdl_seq_SET(ops, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6655 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6656 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6657 | } |
| 6658 | if (_PyObject_LookupAttrId(obj, &PyId_comparators, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6659 | return 1; |
| 6660 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6661 | if (tmp == NULL) { |
| 6662 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 6663 | return 1; |
| 6664 | } |
| 6665 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6666 | int res; |
| 6667 | Py_ssize_t len; |
| 6668 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6669 | if (!PyList_Check(tmp)) { |
| 6670 | PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6671 | goto failed; |
| 6672 | } |
| 6673 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6674 | comparators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6675 | if (comparators == NULL) goto failed; |
| 6676 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6677 | expr_ty val; |
| 6678 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6679 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6680 | if (len != PyList_GET_SIZE(tmp)) { |
| 6681 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration"); |
| 6682 | goto failed; |
| 6683 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6684 | asdl_seq_SET(comparators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6685 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6686 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6687 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6688 | *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno, |
| 6689 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6690 | if (*out == NULL) goto failed; |
| 6691 | return 0; |
| 6692 | } |
| 6693 | isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type); |
| 6694 | if (isinstance == -1) { |
| 6695 | return 1; |
| 6696 | } |
| 6697 | if (isinstance) { |
| 6698 | expr_ty func; |
| 6699 | asdl_seq* args; |
| 6700 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6701 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6702 | if (_PyObject_LookupAttrId(obj, &PyId_func, &tmp) < 0) { |
| 6703 | return 1; |
| 6704 | } |
| 6705 | if (tmp == NULL) { |
| 6706 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 6707 | return 1; |
| 6708 | } |
| 6709 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6710 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6711 | res = obj2ast_expr(tmp, &func, arena); |
| 6712 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6713 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6714 | } |
| 6715 | if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6716 | return 1; |
| 6717 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6718 | if (tmp == NULL) { |
| 6719 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 6720 | return 1; |
| 6721 | } |
| 6722 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6723 | int res; |
| 6724 | Py_ssize_t len; |
| 6725 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6726 | if (!PyList_Check(tmp)) { |
| 6727 | PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6728 | goto failed; |
| 6729 | } |
| 6730 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6731 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6732 | if (args == NULL) goto failed; |
| 6733 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6734 | expr_ty val; |
| 6735 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6736 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6737 | if (len != PyList_GET_SIZE(tmp)) { |
| 6738 | PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration"); |
| 6739 | goto failed; |
| 6740 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6741 | asdl_seq_SET(args, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6742 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6743 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6744 | } |
| 6745 | if (_PyObject_LookupAttrId(obj, &PyId_keywords, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6746 | return 1; |
| 6747 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6748 | if (tmp == NULL) { |
| 6749 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 6750 | return 1; |
| 6751 | } |
| 6752 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6753 | int res; |
| 6754 | Py_ssize_t len; |
| 6755 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6756 | if (!PyList_Check(tmp)) { |
| 6757 | PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6758 | goto failed; |
| 6759 | } |
| 6760 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6761 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6762 | if (keywords == NULL) goto failed; |
| 6763 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6764 | keyword_ty val; |
| 6765 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6766 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6767 | if (len != PyList_GET_SIZE(tmp)) { |
| 6768 | PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration"); |
| 6769 | goto failed; |
| 6770 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6771 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6772 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6773 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6774 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6775 | *out = Call(func, args, keywords, lineno, col_offset, end_lineno, |
| 6776 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6777 | if (*out == NULL) goto failed; |
| 6778 | return 0; |
| 6779 | } |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6780 | isinstance = PyObject_IsInstance(obj, (PyObject*)FormattedValue_type); |
| 6781 | if (isinstance == -1) { |
| 6782 | return 1; |
| 6783 | } |
| 6784 | if (isinstance) { |
| 6785 | expr_ty value; |
| 6786 | int conversion; |
| 6787 | expr_ty format_spec; |
| 6788 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6789 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6790 | return 1; |
| 6791 | } |
| 6792 | if (tmp == NULL) { |
| 6793 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue"); |
| 6794 | return 1; |
| 6795 | } |
| 6796 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6797 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6798 | res = obj2ast_expr(tmp, &value, arena); |
| 6799 | if (res != 0) goto failed; |
| 6800 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6801 | } |
| 6802 | if (_PyObject_LookupAttrId(obj, &PyId_conversion, &tmp) < 0) { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6803 | return 1; |
| 6804 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6805 | if (tmp == NULL || tmp == Py_None) { |
| 6806 | Py_CLEAR(tmp); |
| 6807 | conversion = 0; |
| 6808 | } |
| 6809 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6810 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6811 | res = obj2ast_int(tmp, &conversion, arena); |
| 6812 | if (res != 0) goto failed; |
| 6813 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6814 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6815 | if (_PyObject_LookupAttrId(obj, &PyId_format_spec, &tmp) < 0) { |
| 6816 | return 1; |
| 6817 | } |
| 6818 | if (tmp == NULL || tmp == Py_None) { |
| 6819 | Py_CLEAR(tmp); |
| 6820 | format_spec = NULL; |
| 6821 | } |
| 6822 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6823 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6824 | res = obj2ast_expr(tmp, &format_spec, arena); |
| 6825 | if (res != 0) goto failed; |
| 6826 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6827 | } |
| 6828 | *out = FormattedValue(value, conversion, format_spec, lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6829 | col_offset, end_lineno, end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6830 | if (*out == NULL) goto failed; |
| 6831 | return 0; |
| 6832 | } |
| 6833 | isinstance = PyObject_IsInstance(obj, (PyObject*)JoinedStr_type); |
| 6834 | if (isinstance == -1) { |
| 6835 | return 1; |
| 6836 | } |
| 6837 | if (isinstance) { |
| 6838 | asdl_seq* values; |
| 6839 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6840 | if (_PyObject_LookupAttrId(obj, &PyId_values, &tmp) < 0) { |
| 6841 | return 1; |
| 6842 | } |
| 6843 | if (tmp == NULL) { |
| 6844 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr"); |
| 6845 | return 1; |
| 6846 | } |
| 6847 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6848 | int res; |
| 6849 | Py_ssize_t len; |
| 6850 | Py_ssize_t i; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6851 | if (!PyList_Check(tmp)) { |
| 6852 | PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6853 | goto failed; |
| 6854 | } |
| 6855 | len = PyList_GET_SIZE(tmp); |
| 6856 | values = _Py_asdl_seq_new(len, arena); |
| 6857 | if (values == NULL) goto failed; |
| 6858 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6859 | expr_ty val; |
| 6860 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6861 | if (res != 0) goto failed; |
Serhiy Storchaka | 5e80855 | 2016-10-07 21:55:49 +0300 | [diff] [blame] | 6862 | if (len != PyList_GET_SIZE(tmp)) { |
| 6863 | PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration"); |
| 6864 | goto failed; |
| 6865 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6866 | asdl_seq_SET(values, i, val); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6867 | } |
| 6868 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6869 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6870 | *out = JoinedStr(values, lineno, col_offset, end_lineno, |
| 6871 | end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6872 | if (*out == NULL) goto failed; |
| 6873 | return 0; |
| 6874 | } |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 6875 | isinstance = PyObject_IsInstance(obj, (PyObject*)Constant_type); |
| 6876 | if (isinstance == -1) { |
| 6877 | return 1; |
| 6878 | } |
| 6879 | if (isinstance) { |
| 6880 | constant value; |
| 6881 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6882 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6883 | return 1; |
| 6884 | } |
| 6885 | if (tmp == NULL) { |
| 6886 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant"); |
| 6887 | return 1; |
| 6888 | } |
| 6889 | else { |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 6890 | int res; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 6891 | res = obj2ast_constant(tmp, &value, arena); |
| 6892 | if (res != 0) goto failed; |
| 6893 | Py_CLEAR(tmp); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 6894 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6895 | *out = Constant(value, lineno, col_offset, end_lineno, end_col_offset, |
| 6896 | arena); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 6897 | if (*out == NULL) goto failed; |
| 6898 | return 0; |
| 6899 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6900 | isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type); |
| 6901 | if (isinstance == -1) { |
| 6902 | return 1; |
| 6903 | } |
| 6904 | if (isinstance) { |
| 6905 | expr_ty value; |
| 6906 | identifier attr; |
| 6907 | expr_context_ty ctx; |
| 6908 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6909 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6910 | return 1; |
| 6911 | } |
| 6912 | if (tmp == NULL) { |
| 6913 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 6914 | return 1; |
| 6915 | } |
| 6916 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6917 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6918 | res = obj2ast_expr(tmp, &value, arena); |
| 6919 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6920 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6921 | } |
| 6922 | if (_PyObject_LookupAttrId(obj, &PyId_attr, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6923 | return 1; |
| 6924 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6925 | if (tmp == NULL) { |
| 6926 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 6927 | return 1; |
| 6928 | } |
| 6929 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6930 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6931 | res = obj2ast_identifier(tmp, &attr, arena); |
| 6932 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6933 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6934 | } |
| 6935 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6936 | return 1; |
| 6937 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6938 | if (tmp == NULL) { |
| 6939 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 6940 | return 1; |
| 6941 | } |
| 6942 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6943 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6944 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 6945 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6946 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6947 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6948 | *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno, |
| 6949 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6950 | if (*out == NULL) goto failed; |
| 6951 | return 0; |
| 6952 | } |
| 6953 | isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type); |
| 6954 | if (isinstance == -1) { |
| 6955 | return 1; |
| 6956 | } |
| 6957 | if (isinstance) { |
| 6958 | expr_ty value; |
| 6959 | slice_ty slice; |
| 6960 | expr_context_ty ctx; |
| 6961 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6962 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6963 | return 1; |
| 6964 | } |
| 6965 | if (tmp == NULL) { |
| 6966 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 6967 | return 1; |
| 6968 | } |
| 6969 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6970 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6971 | res = obj2ast_expr(tmp, &value, arena); |
| 6972 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6973 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6974 | } |
| 6975 | if (_PyObject_LookupAttrId(obj, &PyId_slice, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6976 | return 1; |
| 6977 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6978 | if (tmp == NULL) { |
| 6979 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 6980 | return 1; |
| 6981 | } |
| 6982 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6983 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6984 | res = obj2ast_slice(tmp, &slice, arena); |
| 6985 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6986 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6987 | } |
| 6988 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6989 | return 1; |
| 6990 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6991 | if (tmp == NULL) { |
| 6992 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 6993 | return 1; |
| 6994 | } |
| 6995 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6996 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6997 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 6998 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6999 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7000 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7001 | *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno, |
| 7002 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7003 | if (*out == NULL) goto failed; |
| 7004 | return 0; |
| 7005 | } |
| 7006 | isinstance = PyObject_IsInstance(obj, (PyObject*)Starred_type); |
| 7007 | if (isinstance == -1) { |
| 7008 | return 1; |
| 7009 | } |
| 7010 | if (isinstance) { |
| 7011 | expr_ty value; |
| 7012 | expr_context_ty ctx; |
| 7013 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7014 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 7015 | return 1; |
| 7016 | } |
| 7017 | if (tmp == NULL) { |
| 7018 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 7019 | return 1; |
| 7020 | } |
| 7021 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7022 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7023 | res = obj2ast_expr(tmp, &value, arena); |
| 7024 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7025 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7026 | } |
| 7027 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7028 | return 1; |
| 7029 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7030 | if (tmp == NULL) { |
| 7031 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 7032 | return 1; |
| 7033 | } |
| 7034 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7035 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7036 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 7037 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7038 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7039 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7040 | *out = Starred(value, ctx, lineno, col_offset, end_lineno, |
| 7041 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7042 | if (*out == NULL) goto failed; |
| 7043 | return 0; |
| 7044 | } |
| 7045 | isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type); |
| 7046 | if (isinstance == -1) { |
| 7047 | return 1; |
| 7048 | } |
| 7049 | if (isinstance) { |
| 7050 | identifier id; |
| 7051 | expr_context_ty ctx; |
| 7052 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7053 | if (_PyObject_LookupAttrId(obj, &PyId_id, &tmp) < 0) { |
| 7054 | return 1; |
| 7055 | } |
| 7056 | if (tmp == NULL) { |
| 7057 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 7058 | return 1; |
| 7059 | } |
| 7060 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7061 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7062 | res = obj2ast_identifier(tmp, &id, arena); |
| 7063 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7064 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7065 | } |
| 7066 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7067 | return 1; |
| 7068 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7069 | if (tmp == NULL) { |
| 7070 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 7071 | return 1; |
| 7072 | } |
| 7073 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7074 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7075 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 7076 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7077 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7078 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7079 | *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 7080 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7081 | if (*out == NULL) goto failed; |
| 7082 | return 0; |
| 7083 | } |
| 7084 | isinstance = PyObject_IsInstance(obj, (PyObject*)List_type); |
| 7085 | if (isinstance == -1) { |
| 7086 | return 1; |
| 7087 | } |
| 7088 | if (isinstance) { |
| 7089 | asdl_seq* elts; |
| 7090 | expr_context_ty ctx; |
| 7091 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7092 | if (_PyObject_LookupAttrId(obj, &PyId_elts, &tmp) < 0) { |
| 7093 | return 1; |
| 7094 | } |
| 7095 | if (tmp == NULL) { |
| 7096 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 7097 | return 1; |
| 7098 | } |
| 7099 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7100 | int res; |
| 7101 | Py_ssize_t len; |
| 7102 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7103 | if (!PyList_Check(tmp)) { |
| 7104 | PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7105 | goto failed; |
| 7106 | } |
| 7107 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7108 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7109 | if (elts == NULL) goto failed; |
| 7110 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7111 | expr_ty val; |
| 7112 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7113 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7114 | if (len != PyList_GET_SIZE(tmp)) { |
| 7115 | PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration"); |
| 7116 | goto failed; |
| 7117 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7118 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7119 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7120 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7121 | } |
| 7122 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7123 | return 1; |
| 7124 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7125 | if (tmp == NULL) { |
| 7126 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 7127 | return 1; |
| 7128 | } |
| 7129 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7130 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7131 | res = obj2ast_expr_context(tmp, &ctx, 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 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7135 | *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 7136 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7137 | if (*out == NULL) goto failed; |
| 7138 | return 0; |
| 7139 | } |
| 7140 | isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type); |
| 7141 | if (isinstance == -1) { |
| 7142 | return 1; |
| 7143 | } |
| 7144 | if (isinstance) { |
| 7145 | asdl_seq* elts; |
| 7146 | expr_context_ty ctx; |
| 7147 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7148 | if (_PyObject_LookupAttrId(obj, &PyId_elts, &tmp) < 0) { |
| 7149 | return 1; |
| 7150 | } |
| 7151 | if (tmp == NULL) { |
| 7152 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 7153 | return 1; |
| 7154 | } |
| 7155 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7156 | int res; |
| 7157 | Py_ssize_t len; |
| 7158 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7159 | if (!PyList_Check(tmp)) { |
| 7160 | PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7161 | goto failed; |
| 7162 | } |
| 7163 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7164 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7165 | if (elts == NULL) goto failed; |
| 7166 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7167 | expr_ty val; |
| 7168 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7169 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7170 | if (len != PyList_GET_SIZE(tmp)) { |
| 7171 | PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration"); |
| 7172 | goto failed; |
| 7173 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7174 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7175 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7176 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7177 | } |
| 7178 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7179 | return 1; |
| 7180 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7181 | if (tmp == NULL) { |
| 7182 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 7183 | return 1; |
| 7184 | } |
| 7185 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7186 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7187 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 7188 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7189 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7190 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7191 | *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 7192 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7193 | if (*out == NULL) goto failed; |
| 7194 | return 0; |
| 7195 | } |
| 7196 | |
| 7197 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
| 7198 | failed: |
| 7199 | Py_XDECREF(tmp); |
| 7200 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7201 | } |
| 7202 | |
| 7203 | int |
| 7204 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 7205 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7206 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7207 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7208 | isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); |
| 7209 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7210 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7211 | } |
| 7212 | if (isinstance) { |
| 7213 | *out = Load; |
| 7214 | return 0; |
| 7215 | } |
| 7216 | isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type); |
| 7217 | if (isinstance == -1) { |
| 7218 | return 1; |
| 7219 | } |
| 7220 | if (isinstance) { |
| 7221 | *out = Store; |
| 7222 | return 0; |
| 7223 | } |
| 7224 | isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type); |
| 7225 | if (isinstance == -1) { |
| 7226 | return 1; |
| 7227 | } |
| 7228 | if (isinstance) { |
| 7229 | *out = Del; |
| 7230 | return 0; |
| 7231 | } |
| 7232 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type); |
| 7233 | if (isinstance == -1) { |
| 7234 | return 1; |
| 7235 | } |
| 7236 | if (isinstance) { |
| 7237 | *out = AugLoad; |
| 7238 | return 0; |
| 7239 | } |
| 7240 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type); |
| 7241 | if (isinstance == -1) { |
| 7242 | return 1; |
| 7243 | } |
| 7244 | if (isinstance) { |
| 7245 | *out = AugStore; |
| 7246 | return 0; |
| 7247 | } |
| 7248 | isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type); |
| 7249 | if (isinstance == -1) { |
| 7250 | return 1; |
| 7251 | } |
| 7252 | if (isinstance) { |
| 7253 | *out = Param; |
| 7254 | return 0; |
| 7255 | } |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7256 | isinstance = PyObject_IsInstance(obj, (PyObject *)NamedStore_type); |
| 7257 | if (isinstance == -1) { |
| 7258 | return 1; |
| 7259 | } |
| 7260 | if (isinstance) { |
| 7261 | *out = NamedStore; |
| 7262 | return 0; |
| 7263 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7264 | |
| 7265 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj); |
| 7266 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7267 | } |
| 7268 | |
| 7269 | int |
| 7270 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
| 7271 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7272 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7273 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7274 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7275 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7276 | if (obj == Py_None) { |
| 7277 | *out = NULL; |
| 7278 | return 0; |
| 7279 | } |
| 7280 | isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type); |
| 7281 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7282 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7283 | } |
| 7284 | if (isinstance) { |
| 7285 | expr_ty lower; |
| 7286 | expr_ty upper; |
| 7287 | expr_ty step; |
| 7288 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7289 | if (_PyObject_LookupAttrId(obj, &PyId_lower, &tmp) < 0) { |
| 7290 | return 1; |
| 7291 | } |
| 7292 | if (tmp == NULL || tmp == Py_None) { |
| 7293 | Py_CLEAR(tmp); |
| 7294 | lower = NULL; |
| 7295 | } |
| 7296 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7297 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7298 | res = obj2ast_expr(tmp, &lower, arena); |
| 7299 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7300 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7301 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7302 | if (_PyObject_LookupAttrId(obj, &PyId_upper, &tmp) < 0) { |
| 7303 | return 1; |
| 7304 | } |
| 7305 | if (tmp == NULL || tmp == Py_None) { |
| 7306 | Py_CLEAR(tmp); |
| 7307 | upper = NULL; |
| 7308 | } |
| 7309 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7310 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7311 | res = obj2ast_expr(tmp, &upper, arena); |
| 7312 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7313 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7314 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7315 | if (_PyObject_LookupAttrId(obj, &PyId_step, &tmp) < 0) { |
| 7316 | return 1; |
| 7317 | } |
| 7318 | if (tmp == NULL || tmp == Py_None) { |
| 7319 | Py_CLEAR(tmp); |
| 7320 | step = NULL; |
| 7321 | } |
| 7322 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7323 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7324 | res = obj2ast_expr(tmp, &step, arena); |
| 7325 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7326 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7327 | } |
| 7328 | *out = Slice(lower, upper, step, arena); |
| 7329 | if (*out == NULL) goto failed; |
| 7330 | return 0; |
| 7331 | } |
| 7332 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type); |
| 7333 | if (isinstance == -1) { |
| 7334 | return 1; |
| 7335 | } |
| 7336 | if (isinstance) { |
| 7337 | asdl_seq* dims; |
| 7338 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7339 | if (_PyObject_LookupAttrId(obj, &PyId_dims, &tmp) < 0) { |
| 7340 | return 1; |
| 7341 | } |
| 7342 | if (tmp == NULL) { |
| 7343 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
| 7344 | return 1; |
| 7345 | } |
| 7346 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7347 | int res; |
| 7348 | Py_ssize_t len; |
| 7349 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7350 | if (!PyList_Check(tmp)) { |
| 7351 | PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7352 | goto failed; |
| 7353 | } |
| 7354 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7355 | dims = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7356 | if (dims == NULL) goto failed; |
| 7357 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7358 | slice_ty val; |
| 7359 | res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7360 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7361 | if (len != PyList_GET_SIZE(tmp)) { |
| 7362 | PyErr_SetString(PyExc_RuntimeError, "ExtSlice field \"dims\" changed size during iteration"); |
| 7363 | goto failed; |
| 7364 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7365 | asdl_seq_SET(dims, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7366 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7367 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7368 | } |
| 7369 | *out = ExtSlice(dims, arena); |
| 7370 | if (*out == NULL) goto failed; |
| 7371 | return 0; |
| 7372 | } |
| 7373 | isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type); |
| 7374 | if (isinstance == -1) { |
| 7375 | return 1; |
| 7376 | } |
| 7377 | if (isinstance) { |
| 7378 | expr_ty value; |
| 7379 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7380 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 7381 | return 1; |
| 7382 | } |
| 7383 | if (tmp == NULL) { |
| 7384 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
| 7385 | return 1; |
| 7386 | } |
| 7387 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7388 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7389 | res = obj2ast_expr(tmp, &value, arena); |
| 7390 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7391 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7392 | } |
| 7393 | *out = Index(value, arena); |
| 7394 | if (*out == NULL) goto failed; |
| 7395 | return 0; |
| 7396 | } |
| 7397 | |
| 7398 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj); |
| 7399 | failed: |
| 7400 | Py_XDECREF(tmp); |
| 7401 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7402 | } |
| 7403 | |
| 7404 | int |
| 7405 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 7406 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7407 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7408 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7409 | isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); |
| 7410 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7411 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7412 | } |
| 7413 | if (isinstance) { |
| 7414 | *out = And; |
| 7415 | return 0; |
| 7416 | } |
| 7417 | isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type); |
| 7418 | if (isinstance == -1) { |
| 7419 | return 1; |
| 7420 | } |
| 7421 | if (isinstance) { |
| 7422 | *out = Or; |
| 7423 | return 0; |
| 7424 | } |
| 7425 | |
| 7426 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj); |
| 7427 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7428 | } |
| 7429 | |
| 7430 | int |
| 7431 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 7432 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7433 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7434 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7435 | isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); |
| 7436 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7437 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7438 | } |
| 7439 | if (isinstance) { |
| 7440 | *out = Add; |
| 7441 | return 0; |
| 7442 | } |
| 7443 | isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type); |
| 7444 | if (isinstance == -1) { |
| 7445 | return 1; |
| 7446 | } |
| 7447 | if (isinstance) { |
| 7448 | *out = Sub; |
| 7449 | return 0; |
| 7450 | } |
| 7451 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type); |
| 7452 | if (isinstance == -1) { |
| 7453 | return 1; |
| 7454 | } |
| 7455 | if (isinstance) { |
| 7456 | *out = Mult; |
| 7457 | return 0; |
| 7458 | } |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 7459 | isinstance = PyObject_IsInstance(obj, (PyObject *)MatMult_type); |
| 7460 | if (isinstance == -1) { |
| 7461 | return 1; |
| 7462 | } |
| 7463 | if (isinstance) { |
| 7464 | *out = MatMult; |
| 7465 | return 0; |
| 7466 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7467 | isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type); |
| 7468 | if (isinstance == -1) { |
| 7469 | return 1; |
| 7470 | } |
| 7471 | if (isinstance) { |
| 7472 | *out = Div; |
| 7473 | return 0; |
| 7474 | } |
| 7475 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type); |
| 7476 | if (isinstance == -1) { |
| 7477 | return 1; |
| 7478 | } |
| 7479 | if (isinstance) { |
| 7480 | *out = Mod; |
| 7481 | return 0; |
| 7482 | } |
| 7483 | isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type); |
| 7484 | if (isinstance == -1) { |
| 7485 | return 1; |
| 7486 | } |
| 7487 | if (isinstance) { |
| 7488 | *out = Pow; |
| 7489 | return 0; |
| 7490 | } |
| 7491 | isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type); |
| 7492 | if (isinstance == -1) { |
| 7493 | return 1; |
| 7494 | } |
| 7495 | if (isinstance) { |
| 7496 | *out = LShift; |
| 7497 | return 0; |
| 7498 | } |
| 7499 | isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type); |
| 7500 | if (isinstance == -1) { |
| 7501 | return 1; |
| 7502 | } |
| 7503 | if (isinstance) { |
| 7504 | *out = RShift; |
| 7505 | return 0; |
| 7506 | } |
| 7507 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type); |
| 7508 | if (isinstance == -1) { |
| 7509 | return 1; |
| 7510 | } |
| 7511 | if (isinstance) { |
| 7512 | *out = BitOr; |
| 7513 | return 0; |
| 7514 | } |
| 7515 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type); |
| 7516 | if (isinstance == -1) { |
| 7517 | return 1; |
| 7518 | } |
| 7519 | if (isinstance) { |
| 7520 | *out = BitXor; |
| 7521 | return 0; |
| 7522 | } |
| 7523 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type); |
| 7524 | if (isinstance == -1) { |
| 7525 | return 1; |
| 7526 | } |
| 7527 | if (isinstance) { |
| 7528 | *out = BitAnd; |
| 7529 | return 0; |
| 7530 | } |
| 7531 | isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type); |
| 7532 | if (isinstance == -1) { |
| 7533 | return 1; |
| 7534 | } |
| 7535 | if (isinstance) { |
| 7536 | *out = FloorDiv; |
| 7537 | return 0; |
| 7538 | } |
| 7539 | |
| 7540 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj); |
| 7541 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7542 | } |
| 7543 | |
| 7544 | int |
| 7545 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 7546 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7547 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7548 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7549 | isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); |
| 7550 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7551 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7552 | } |
| 7553 | if (isinstance) { |
| 7554 | *out = Invert; |
| 7555 | return 0; |
| 7556 | } |
| 7557 | isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type); |
| 7558 | if (isinstance == -1) { |
| 7559 | return 1; |
| 7560 | } |
| 7561 | if (isinstance) { |
| 7562 | *out = Not; |
| 7563 | return 0; |
| 7564 | } |
| 7565 | isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type); |
| 7566 | if (isinstance == -1) { |
| 7567 | return 1; |
| 7568 | } |
| 7569 | if (isinstance) { |
| 7570 | *out = UAdd; |
| 7571 | return 0; |
| 7572 | } |
| 7573 | isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type); |
| 7574 | if (isinstance == -1) { |
| 7575 | return 1; |
| 7576 | } |
| 7577 | if (isinstance) { |
| 7578 | *out = USub; |
| 7579 | return 0; |
| 7580 | } |
| 7581 | |
| 7582 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj); |
| 7583 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7584 | } |
| 7585 | |
| 7586 | int |
| 7587 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 7588 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7589 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7590 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7591 | isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); |
| 7592 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7593 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7594 | } |
| 7595 | if (isinstance) { |
| 7596 | *out = Eq; |
| 7597 | return 0; |
| 7598 | } |
| 7599 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type); |
| 7600 | if (isinstance == -1) { |
| 7601 | return 1; |
| 7602 | } |
| 7603 | if (isinstance) { |
| 7604 | *out = NotEq; |
| 7605 | return 0; |
| 7606 | } |
| 7607 | isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type); |
| 7608 | if (isinstance == -1) { |
| 7609 | return 1; |
| 7610 | } |
| 7611 | if (isinstance) { |
| 7612 | *out = Lt; |
| 7613 | return 0; |
| 7614 | } |
| 7615 | isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type); |
| 7616 | if (isinstance == -1) { |
| 7617 | return 1; |
| 7618 | } |
| 7619 | if (isinstance) { |
| 7620 | *out = LtE; |
| 7621 | return 0; |
| 7622 | } |
| 7623 | isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type); |
| 7624 | if (isinstance == -1) { |
| 7625 | return 1; |
| 7626 | } |
| 7627 | if (isinstance) { |
| 7628 | *out = Gt; |
| 7629 | return 0; |
| 7630 | } |
| 7631 | isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type); |
| 7632 | if (isinstance == -1) { |
| 7633 | return 1; |
| 7634 | } |
| 7635 | if (isinstance) { |
| 7636 | *out = GtE; |
| 7637 | return 0; |
| 7638 | } |
| 7639 | isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type); |
| 7640 | if (isinstance == -1) { |
| 7641 | return 1; |
| 7642 | } |
| 7643 | if (isinstance) { |
| 7644 | *out = Is; |
| 7645 | return 0; |
| 7646 | } |
| 7647 | isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type); |
| 7648 | if (isinstance == -1) { |
| 7649 | return 1; |
| 7650 | } |
| 7651 | if (isinstance) { |
| 7652 | *out = IsNot; |
| 7653 | return 0; |
| 7654 | } |
| 7655 | isinstance = PyObject_IsInstance(obj, (PyObject *)In_type); |
| 7656 | if (isinstance == -1) { |
| 7657 | return 1; |
| 7658 | } |
| 7659 | if (isinstance) { |
| 7660 | *out = In; |
| 7661 | return 0; |
| 7662 | } |
| 7663 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type); |
| 7664 | if (isinstance == -1) { |
| 7665 | return 1; |
| 7666 | } |
| 7667 | if (isinstance) { |
| 7668 | *out = NotIn; |
| 7669 | return 0; |
| 7670 | } |
| 7671 | |
| 7672 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj); |
| 7673 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7674 | } |
| 7675 | |
| 7676 | int |
| 7677 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 7678 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7679 | PyObject* tmp = NULL; |
| 7680 | expr_ty target; |
| 7681 | expr_ty iter; |
| 7682 | asdl_seq* ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 7683 | int is_async; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7684 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7685 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 7686 | return 1; |
| 7687 | } |
| 7688 | if (tmp == NULL) { |
| 7689 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 7690 | return 1; |
| 7691 | } |
| 7692 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7693 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7694 | res = obj2ast_expr(tmp, &target, arena); |
| 7695 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7696 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7697 | } |
| 7698 | if (_PyObject_LookupAttrId(obj, &PyId_iter, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7699 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7700 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7701 | if (tmp == NULL) { |
| 7702 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 7703 | return 1; |
| 7704 | } |
| 7705 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7706 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7707 | res = obj2ast_expr(tmp, &iter, arena); |
| 7708 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7709 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7710 | } |
| 7711 | if (_PyObject_LookupAttrId(obj, &PyId_ifs, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7712 | return 1; |
| 7713 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7714 | if (tmp == NULL) { |
| 7715 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 7716 | return 1; |
| 7717 | } |
| 7718 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7719 | int res; |
| 7720 | Py_ssize_t len; |
| 7721 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7722 | if (!PyList_Check(tmp)) { |
| 7723 | PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7724 | goto failed; |
| 7725 | } |
| 7726 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7727 | ifs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7728 | if (ifs == NULL) goto failed; |
| 7729 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7730 | expr_ty val; |
| 7731 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7732 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7733 | if (len != PyList_GET_SIZE(tmp)) { |
| 7734 | PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration"); |
| 7735 | goto failed; |
| 7736 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7737 | asdl_seq_SET(ifs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7738 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7739 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7740 | } |
| 7741 | if (_PyObject_LookupAttrId(obj, &PyId_is_async, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7742 | return 1; |
| 7743 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7744 | if (tmp == NULL) { |
| 7745 | PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension"); |
| 7746 | return 1; |
| 7747 | } |
| 7748 | else { |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 7749 | int res; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 7750 | res = obj2ast_int(tmp, &is_async, arena); |
| 7751 | if (res != 0) goto failed; |
| 7752 | Py_CLEAR(tmp); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 7753 | } |
| 7754 | *out = comprehension(target, iter, ifs, is_async, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7755 | return 0; |
| 7756 | failed: |
| 7757 | Py_XDECREF(tmp); |
| 7758 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7759 | } |
| 7760 | |
| 7761 | int |
| 7762 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 7763 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7764 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 7765 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7766 | PyObject *tmp = NULL; |
| 7767 | int lineno; |
| 7768 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7769 | int end_lineno; |
| 7770 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7771 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7772 | if (obj == Py_None) { |
| 7773 | *out = NULL; |
| 7774 | return 0; |
| 7775 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7776 | if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) { |
| 7777 | return 1; |
| 7778 | } |
| 7779 | if (tmp == NULL) { |
| 7780 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 7781 | return 1; |
| 7782 | } |
| 7783 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7784 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7785 | res = obj2ast_int(tmp, &lineno, arena); |
| 7786 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7787 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7788 | } |
| 7789 | if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7790 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7791 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7792 | if (tmp == NULL) { |
| 7793 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 7794 | return 1; |
| 7795 | } |
| 7796 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7797 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7798 | res = obj2ast_int(tmp, &col_offset, arena); |
| 7799 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7800 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7801 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7802 | if (_PyObject_LookupAttrId(obj, &PyId_end_lineno, &tmp) < 0) { |
| 7803 | return 1; |
| 7804 | } |
| 7805 | if (tmp == NULL || tmp == Py_None) { |
| 7806 | Py_CLEAR(tmp); |
| 7807 | end_lineno = 0; |
| 7808 | } |
| 7809 | else { |
| 7810 | int res; |
| 7811 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 7812 | if (res != 0) goto failed; |
| 7813 | Py_CLEAR(tmp); |
| 7814 | } |
| 7815 | if (_PyObject_LookupAttrId(obj, &PyId_end_col_offset, &tmp) < 0) { |
| 7816 | return 1; |
| 7817 | } |
| 7818 | if (tmp == NULL || tmp == Py_None) { |
| 7819 | Py_CLEAR(tmp); |
| 7820 | end_col_offset = 0; |
| 7821 | } |
| 7822 | else { |
| 7823 | int res; |
| 7824 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 7825 | if (res != 0) goto failed; |
| 7826 | Py_CLEAR(tmp); |
| 7827 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7828 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type); |
| 7829 | if (isinstance == -1) { |
| 7830 | return 1; |
| 7831 | } |
| 7832 | if (isinstance) { |
| 7833 | expr_ty type; |
| 7834 | identifier name; |
| 7835 | asdl_seq* body; |
| 7836 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7837 | if (_PyObject_LookupAttrId(obj, &PyId_type, &tmp) < 0) { |
| 7838 | return 1; |
| 7839 | } |
| 7840 | if (tmp == NULL || tmp == Py_None) { |
| 7841 | Py_CLEAR(tmp); |
| 7842 | type = NULL; |
| 7843 | } |
| 7844 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7845 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7846 | res = obj2ast_expr(tmp, &type, arena); |
| 7847 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7848 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7849 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7850 | if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) { |
| 7851 | return 1; |
| 7852 | } |
| 7853 | if (tmp == NULL || tmp == Py_None) { |
| 7854 | Py_CLEAR(tmp); |
| 7855 | name = NULL; |
| 7856 | } |
| 7857 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7858 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7859 | res = obj2ast_identifier(tmp, &name, arena); |
| 7860 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7861 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7862 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7863 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 7864 | return 1; |
| 7865 | } |
| 7866 | if (tmp == NULL) { |
| 7867 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 7868 | return 1; |
| 7869 | } |
| 7870 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7871 | int res; |
| 7872 | Py_ssize_t len; |
| 7873 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7874 | if (!PyList_Check(tmp)) { |
| 7875 | PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7876 | goto failed; |
| 7877 | } |
| 7878 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7879 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7880 | if (body == NULL) goto failed; |
| 7881 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7882 | stmt_ty val; |
| 7883 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7884 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7885 | if (len != PyList_GET_SIZE(tmp)) { |
| 7886 | PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration"); |
| 7887 | goto failed; |
| 7888 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7889 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7890 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7891 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7892 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7893 | *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno, |
| 7894 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7895 | if (*out == NULL) goto failed; |
| 7896 | return 0; |
| 7897 | } |
| 7898 | |
| 7899 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
| 7900 | failed: |
| 7901 | Py_XDECREF(tmp); |
| 7902 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7903 | } |
| 7904 | |
| 7905 | int |
| 7906 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 7907 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7908 | PyObject* tmp = NULL; |
| 7909 | asdl_seq* args; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7910 | arg_ty vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7911 | asdl_seq* kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7912 | asdl_seq* kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7913 | arg_ty kwarg; |
| 7914 | asdl_seq* defaults; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7915 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7916 | if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) { |
| 7917 | return 1; |
| 7918 | } |
| 7919 | if (tmp == NULL) { |
| 7920 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 7921 | return 1; |
| 7922 | } |
| 7923 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7924 | int res; |
| 7925 | Py_ssize_t len; |
| 7926 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7927 | if (!PyList_Check(tmp)) { |
| 7928 | PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7929 | goto failed; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7930 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7931 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7932 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7933 | if (args == NULL) goto failed; |
| 7934 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7935 | arg_ty val; |
| 7936 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7937 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7938 | if (len != PyList_GET_SIZE(tmp)) { |
| 7939 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration"); |
| 7940 | goto failed; |
| 7941 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7942 | asdl_seq_SET(args, i, val); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7943 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7944 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7945 | } |
| 7946 | if (_PyObject_LookupAttrId(obj, &PyId_vararg, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7947 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7948 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7949 | if (tmp == NULL || tmp == Py_None) { |
| 7950 | Py_CLEAR(tmp); |
| 7951 | vararg = NULL; |
| 7952 | } |
| 7953 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7954 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7955 | res = obj2ast_arg(tmp, &vararg, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7956 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7957 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7958 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7959 | if (_PyObject_LookupAttrId(obj, &PyId_kwonlyargs, &tmp) < 0) { |
| 7960 | return 1; |
| 7961 | } |
| 7962 | if (tmp == NULL) { |
| 7963 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 7964 | return 1; |
| 7965 | } |
| 7966 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7967 | int res; |
| 7968 | Py_ssize_t len; |
| 7969 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7970 | if (!PyList_Check(tmp)) { |
| 7971 | PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7972 | goto failed; |
| 7973 | } |
| 7974 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7975 | kwonlyargs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7976 | if (kwonlyargs == NULL) goto failed; |
| 7977 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7978 | arg_ty val; |
| 7979 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7980 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7981 | if (len != PyList_GET_SIZE(tmp)) { |
| 7982 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration"); |
| 7983 | goto failed; |
| 7984 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7985 | asdl_seq_SET(kwonlyargs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7986 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7987 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7988 | } |
| 7989 | if (_PyObject_LookupAttrId(obj, &PyId_kw_defaults, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7990 | return 1; |
| 7991 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7992 | if (tmp == NULL) { |
| 7993 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 7994 | return 1; |
| 7995 | } |
| 7996 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7997 | int res; |
| 7998 | Py_ssize_t len; |
| 7999 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8000 | if (!PyList_Check(tmp)) { |
| 8001 | PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 8002 | goto failed; |
| 8003 | } |
| 8004 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8005 | kw_defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8006 | if (kw_defaults == NULL) goto failed; |
| 8007 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8008 | expr_ty val; |
| 8009 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8010 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8011 | if (len != PyList_GET_SIZE(tmp)) { |
| 8012 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration"); |
| 8013 | goto failed; |
| 8014 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8015 | asdl_seq_SET(kw_defaults, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8016 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8017 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8018 | } |
| 8019 | if (_PyObject_LookupAttrId(obj, &PyId_kwarg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8020 | return 1; |
| 8021 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8022 | if (tmp == NULL || tmp == Py_None) { |
| 8023 | Py_CLEAR(tmp); |
| 8024 | kwarg = NULL; |
| 8025 | } |
| 8026 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8027 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8028 | res = obj2ast_arg(tmp, &kwarg, arena); |
| 8029 | if (res != 0) goto failed; |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 8030 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8031 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8032 | if (_PyObject_LookupAttrId(obj, &PyId_defaults, &tmp) < 0) { |
| 8033 | return 1; |
| 8034 | } |
| 8035 | if (tmp == NULL) { |
| 8036 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 8037 | return 1; |
| 8038 | } |
| 8039 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8040 | int res; |
| 8041 | Py_ssize_t len; |
| 8042 | Py_ssize_t i; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8043 | if (!PyList_Check(tmp)) { |
| 8044 | PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 8045 | goto failed; |
| 8046 | } |
| 8047 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8048 | defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8049 | if (defaults == NULL) goto failed; |
| 8050 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8051 | expr_ty val; |
| 8052 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8053 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8054 | if (len != PyList_GET_SIZE(tmp)) { |
| 8055 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration"); |
| 8056 | goto failed; |
| 8057 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8058 | asdl_seq_SET(defaults, i, val); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8059 | } |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 8060 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8061 | } |
| 8062 | *out = arguments(args, vararg, kwonlyargs, kw_defaults, kwarg, defaults, |
| 8063 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8064 | return 0; |
| 8065 | failed: |
| 8066 | Py_XDECREF(tmp); |
| 8067 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8068 | } |
| 8069 | |
| 8070 | int |
| 8071 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 8072 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8073 | PyObject* tmp = NULL; |
| 8074 | identifier arg; |
| 8075 | expr_ty annotation; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8076 | int lineno; |
| 8077 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8078 | int end_lineno; |
| 8079 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8080 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8081 | if (_PyObject_LookupAttrId(obj, &PyId_arg, &tmp) < 0) { |
| 8082 | return 1; |
| 8083 | } |
| 8084 | if (tmp == NULL) { |
| 8085 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
| 8086 | return 1; |
| 8087 | } |
| 8088 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8089 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8090 | res = obj2ast_identifier(tmp, &arg, arena); |
| 8091 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8092 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8093 | } |
| 8094 | if (_PyObject_LookupAttrId(obj, &PyId_annotation, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8095 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8096 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8097 | if (tmp == NULL || tmp == Py_None) { |
| 8098 | Py_CLEAR(tmp); |
| 8099 | annotation = NULL; |
| 8100 | } |
| 8101 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8102 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8103 | res = obj2ast_expr(tmp, &annotation, arena); |
| 8104 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8105 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8106 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8107 | if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) { |
| 8108 | return 1; |
| 8109 | } |
| 8110 | if (tmp == NULL) { |
| 8111 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg"); |
| 8112 | return 1; |
| 8113 | } |
| 8114 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8115 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8116 | res = obj2ast_int(tmp, &lineno, arena); |
| 8117 | if (res != 0) goto failed; |
| 8118 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8119 | } |
| 8120 | if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8121 | return 1; |
| 8122 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8123 | if (tmp == NULL) { |
| 8124 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg"); |
| 8125 | return 1; |
| 8126 | } |
| 8127 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8128 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8129 | res = obj2ast_int(tmp, &col_offset, arena); |
| 8130 | if (res != 0) goto failed; |
| 8131 | Py_CLEAR(tmp); |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8132 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8133 | if (_PyObject_LookupAttrId(obj, &PyId_end_lineno, &tmp) < 0) { |
| 8134 | return 1; |
| 8135 | } |
| 8136 | if (tmp == NULL || tmp == Py_None) { |
| 8137 | Py_CLEAR(tmp); |
| 8138 | end_lineno = 0; |
| 8139 | } |
| 8140 | else { |
| 8141 | int res; |
| 8142 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 8143 | if (res != 0) goto failed; |
| 8144 | Py_CLEAR(tmp); |
| 8145 | } |
| 8146 | if (_PyObject_LookupAttrId(obj, &PyId_end_col_offset, &tmp) < 0) { |
| 8147 | return 1; |
| 8148 | } |
| 8149 | if (tmp == NULL || tmp == Py_None) { |
| 8150 | Py_CLEAR(tmp); |
| 8151 | end_col_offset = 0; |
| 8152 | } |
| 8153 | else { |
| 8154 | int res; |
| 8155 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 8156 | if (res != 0) goto failed; |
| 8157 | Py_CLEAR(tmp); |
| 8158 | } |
| 8159 | *out = arg(arg, annotation, lineno, col_offset, end_lineno, end_col_offset, |
| 8160 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8161 | return 0; |
| 8162 | failed: |
| 8163 | Py_XDECREF(tmp); |
| 8164 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8165 | } |
| 8166 | |
| 8167 | int |
| 8168 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 8169 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8170 | PyObject* tmp = NULL; |
| 8171 | identifier arg; |
| 8172 | expr_ty value; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8173 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8174 | if (_PyObject_LookupAttrId(obj, &PyId_arg, &tmp) < 0) { |
| 8175 | return 1; |
| 8176 | } |
| 8177 | if (tmp == NULL || tmp == Py_None) { |
| 8178 | Py_CLEAR(tmp); |
| 8179 | arg = NULL; |
| 8180 | } |
| 8181 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8182 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8183 | res = obj2ast_identifier(tmp, &arg, arena); |
| 8184 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8185 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8186 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8187 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 8188 | return 1; |
| 8189 | } |
| 8190 | if (tmp == NULL) { |
| 8191 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 8192 | return 1; |
| 8193 | } |
| 8194 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8195 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8196 | res = obj2ast_expr(tmp, &value, arena); |
| 8197 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8198 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8199 | } |
| 8200 | *out = keyword(arg, value, arena); |
| 8201 | return 0; |
| 8202 | failed: |
| 8203 | Py_XDECREF(tmp); |
| 8204 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8205 | } |
| 8206 | |
| 8207 | int |
| 8208 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 8209 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8210 | PyObject* tmp = NULL; |
| 8211 | identifier name; |
| 8212 | identifier asname; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8213 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8214 | if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) { |
| 8215 | return 1; |
| 8216 | } |
| 8217 | if (tmp == NULL) { |
| 8218 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 8219 | return 1; |
| 8220 | } |
| 8221 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8222 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8223 | res = obj2ast_identifier(tmp, &name, arena); |
| 8224 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8225 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8226 | } |
| 8227 | if (_PyObject_LookupAttrId(obj, &PyId_asname, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8228 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8229 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8230 | if (tmp == NULL || tmp == Py_None) { |
| 8231 | Py_CLEAR(tmp); |
| 8232 | asname = NULL; |
| 8233 | } |
| 8234 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8235 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8236 | res = obj2ast_identifier(tmp, &asname, arena); |
| 8237 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8238 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8239 | } |
| 8240 | *out = alias(name, asname, arena); |
| 8241 | return 0; |
| 8242 | failed: |
| 8243 | Py_XDECREF(tmp); |
| 8244 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8245 | } |
| 8246 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 8247 | int |
| 8248 | obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) |
| 8249 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8250 | PyObject* tmp = NULL; |
| 8251 | expr_ty context_expr; |
| 8252 | expr_ty optional_vars; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 8253 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8254 | if (_PyObject_LookupAttrId(obj, &PyId_context_expr, &tmp) < 0) { |
| 8255 | return 1; |
| 8256 | } |
| 8257 | if (tmp == NULL) { |
| 8258 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); |
| 8259 | return 1; |
| 8260 | } |
| 8261 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8262 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8263 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 8264 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8265 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8266 | } |
| 8267 | if (_PyObject_LookupAttrId(obj, &PyId_optional_vars, &tmp) < 0) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 8268 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8269 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8270 | if (tmp == NULL || tmp == Py_None) { |
| 8271 | Py_CLEAR(tmp); |
| 8272 | optional_vars = NULL; |
| 8273 | } |
| 8274 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8275 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8276 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 8277 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8278 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8279 | } |
| 8280 | *out = withitem(context_expr, optional_vars, arena); |
| 8281 | return 0; |
| 8282 | failed: |
| 8283 | Py_XDECREF(tmp); |
| 8284 | return 1; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 8285 | } |
| 8286 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8287 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 8288 | static struct PyModuleDef _astmodule = { |
| 8289 | PyModuleDef_HEAD_INIT, "_ast" |
| 8290 | }; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 8291 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 8292 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 8293 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8294 | PyObject *m, *d; |
| 8295 | if (!init_types()) return NULL; |
| 8296 | m = PyModule_Create(&_astmodule); |
| 8297 | if (!m) return NULL; |
| 8298 | d = PyModule_GetDict(m); |
| 8299 | if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return NULL; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8300 | if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8301 | return NULL; |
| 8302 | if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return NULL; |
| 8303 | if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) return |
| 8304 | NULL; |
| 8305 | if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) < |
| 8306 | 0) return NULL; |
| 8307 | if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < 0) |
| 8308 | return NULL; |
| 8309 | if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return |
| 8310 | NULL; |
| 8311 | if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return NULL; |
| 8312 | if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) < |
| 8313 | 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8314 | if (PyDict_SetItemString(d, "AsyncFunctionDef", |
| 8315 | (PyObject*)AsyncFunctionDef_type) < 0) return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8316 | if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) |
| 8317 | return NULL; |
| 8318 | if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) return |
| 8319 | NULL; |
| 8320 | if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) return |
| 8321 | NULL; |
| 8322 | if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) return |
| 8323 | NULL; |
| 8324 | if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < 0) |
| 8325 | return NULL; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 8326 | if (PyDict_SetItemString(d, "AnnAssign", (PyObject*)AnnAssign_type) < 0) |
| 8327 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8328 | if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8329 | if (PyDict_SetItemString(d, "AsyncFor", (PyObject*)AsyncFor_type) < 0) |
| 8330 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8331 | if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return |
| 8332 | NULL; |
| 8333 | if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return NULL; |
| 8334 | if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8335 | if (PyDict_SetItemString(d, "AsyncWith", (PyObject*)AsyncWith_type) < 0) |
| 8336 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8337 | if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return |
| 8338 | NULL; |
| 8339 | if (PyDict_SetItemString(d, "Try", (PyObject*)Try_type) < 0) return NULL; |
| 8340 | if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) return |
| 8341 | NULL; |
| 8342 | if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) return |
| 8343 | NULL; |
| 8344 | if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < 0) |
| 8345 | return NULL; |
| 8346 | if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) return |
| 8347 | NULL; |
| 8348 | if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0) |
| 8349 | return NULL; |
| 8350 | if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return NULL; |
| 8351 | if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return NULL; |
| 8352 | if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return |
| 8353 | NULL; |
| 8354 | if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) |
| 8355 | return NULL; |
| 8356 | if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return NULL; |
| 8357 | if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) return |
| 8358 | NULL; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 8359 | if (PyDict_SetItemString(d, "NamedExpr", (PyObject*)NamedExpr_type) < 0) |
| 8360 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8361 | if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return |
| 8362 | NULL; |
| 8363 | if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) return |
| 8364 | NULL; |
| 8365 | if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) return |
| 8366 | NULL; |
| 8367 | if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return |
| 8368 | NULL; |
| 8369 | if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return NULL; |
| 8370 | if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return NULL; |
| 8371 | if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) |
| 8372 | return NULL; |
| 8373 | if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) return |
| 8374 | NULL; |
| 8375 | if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0) |
| 8376 | return NULL; |
| 8377 | if (PyDict_SetItemString(d, "GeneratorExp", (PyObject*)GeneratorExp_type) < |
| 8378 | 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8379 | if (PyDict_SetItemString(d, "Await", (PyObject*)Await_type) < 0) return |
| 8380 | NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8381 | if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return |
| 8382 | NULL; |
| 8383 | if (PyDict_SetItemString(d, "YieldFrom", (PyObject*)YieldFrom_type) < 0) |
| 8384 | return NULL; |
| 8385 | if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) return |
| 8386 | NULL; |
| 8387 | if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return NULL; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8388 | if (PyDict_SetItemString(d, "FormattedValue", |
| 8389 | (PyObject*)FormattedValue_type) < 0) return NULL; |
| 8390 | if (PyDict_SetItemString(d, "JoinedStr", (PyObject*)JoinedStr_type) < 0) |
| 8391 | return NULL; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8392 | if (PyDict_SetItemString(d, "Constant", (PyObject*)Constant_type) < 0) |
| 8393 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8394 | if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < 0) |
| 8395 | return NULL; |
| 8396 | if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < 0) |
| 8397 | return NULL; |
| 8398 | if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0) return |
| 8399 | NULL; |
| 8400 | if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return NULL; |
| 8401 | if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return NULL; |
| 8402 | if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return |
| 8403 | NULL; |
| 8404 | if (PyDict_SetItemString(d, "expr_context", (PyObject*)expr_context_type) < |
| 8405 | 0) return NULL; |
| 8406 | if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return NULL; |
| 8407 | if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return |
| 8408 | NULL; |
| 8409 | if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return NULL; |
| 8410 | if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) return |
| 8411 | NULL; |
| 8412 | if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) |
| 8413 | return NULL; |
| 8414 | if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return |
| 8415 | NULL; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 8416 | if (PyDict_SetItemString(d, "NamedStore", (PyObject*)NamedStore_type) < 0) |
| 8417 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8418 | if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return |
| 8419 | NULL; |
| 8420 | if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return |
| 8421 | NULL; |
| 8422 | if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) |
| 8423 | return NULL; |
| 8424 | if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return |
| 8425 | NULL; |
| 8426 | if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) return |
| 8427 | NULL; |
| 8428 | if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return NULL; |
| 8429 | if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return NULL; |
| 8430 | if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) |
| 8431 | return NULL; |
| 8432 | if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return NULL; |
| 8433 | if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return NULL; |
| 8434 | if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return NULL; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 8435 | if (PyDict_SetItemString(d, "MatMult", (PyObject*)MatMult_type) < 0) return |
| 8436 | NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8437 | if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return NULL; |
| 8438 | if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return NULL; |
| 8439 | if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return NULL; |
| 8440 | if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) return |
| 8441 | NULL; |
| 8442 | if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) return |
| 8443 | NULL; |
| 8444 | if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return |
| 8445 | NULL; |
| 8446 | if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) return |
| 8447 | NULL; |
| 8448 | if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) return |
| 8449 | NULL; |
| 8450 | if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) |
| 8451 | return NULL; |
| 8452 | if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) return |
| 8453 | NULL; |
| 8454 | if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) return |
| 8455 | NULL; |
| 8456 | if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return NULL; |
| 8457 | if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return NULL; |
| 8458 | if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return NULL; |
| 8459 | if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return |
| 8460 | NULL; |
| 8461 | if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return NULL; |
| 8462 | if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return |
| 8463 | NULL; |
| 8464 | if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return NULL; |
| 8465 | if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return NULL; |
| 8466 | if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return NULL; |
| 8467 | if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return NULL; |
| 8468 | if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return NULL; |
| 8469 | if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return |
| 8470 | NULL; |
| 8471 | if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return NULL; |
| 8472 | if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return |
| 8473 | NULL; |
| 8474 | if (PyDict_SetItemString(d, "comprehension", (PyObject*)comprehension_type) |
| 8475 | < 0) return NULL; |
| 8476 | if (PyDict_SetItemString(d, "excepthandler", (PyObject*)excepthandler_type) |
| 8477 | < 0) return NULL; |
| 8478 | if (PyDict_SetItemString(d, "ExceptHandler", (PyObject*)ExceptHandler_type) |
| 8479 | < 0) return NULL; |
| 8480 | if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < 0) |
| 8481 | return NULL; |
| 8482 | if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return NULL; |
| 8483 | if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) return |
| 8484 | NULL; |
| 8485 | if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return |
| 8486 | NULL; |
| 8487 | if (PyDict_SetItemString(d, "withitem", (PyObject*)withitem_type) < 0) |
| 8488 | return NULL; |
| 8489 | return m; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 8490 | } |
| 8491 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 8492 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 8493 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 8494 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 8495 | if (!init_types()) |
| 8496 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 8497 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 8498 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 8499 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 8500 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 8501 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8502 | { |
| 8503 | mod_ty res; |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 8504 | PyObject *req_type[3]; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 8505 | char *req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 8506 | int isinstance; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 8507 | |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 8508 | req_type[0] = (PyObject*)Module_type; |
| 8509 | req_type[1] = (PyObject*)Expression_type; |
| 8510 | req_type[2] = (PyObject*)Interactive_type; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 8511 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 8512 | assert(0 <= mode && mode <= 2); |
| 8513 | |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 8514 | if (!init_types()) |
| 8515 | return NULL; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 8516 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 8517 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 8518 | if (isinstance == -1) |
| 8519 | return NULL; |
| 8520 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 8521 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
| 8522 | req_name[mode], Py_TYPE(ast)->tp_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8523 | return NULL; |
| 8524 | } |
| 8525 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 8526 | return NULL; |
| 8527 | else |
| 8528 | return res; |
| 8529 | } |
| 8530 | |
| 8531 | int PyAST_Check(PyObject* obj) |
| 8532 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 8533 | if (!init_types()) |
| 8534 | return -1; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 8535 | return PyObject_IsInstance(obj, (PyObject*)&AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8536 | } |
| 8537 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 8538 | |