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 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 206 | static PyTypeObject *BinOp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 207 | _Py_IDENTIFIER(left); |
| 208 | _Py_IDENTIFIER(right); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 209 | static char *BinOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 210 | "left", |
| 211 | "op", |
| 212 | "right", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 213 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 214 | static PyTypeObject *UnaryOp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 215 | _Py_IDENTIFIER(operand); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 216 | static char *UnaryOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 217 | "op", |
| 218 | "operand", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 219 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 220 | static PyTypeObject *Lambda_type; |
| 221 | static char *Lambda_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 222 | "args", |
| 223 | "body", |
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 *IfExp_type; |
| 226 | static char *IfExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 227 | "test", |
| 228 | "body", |
| 229 | "orelse", |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 230 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 231 | static PyTypeObject *Dict_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 232 | _Py_IDENTIFIER(keys); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 233 | static char *Dict_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 234 | "keys", |
| 235 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 236 | }; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 237 | static PyTypeObject *Set_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 238 | _Py_IDENTIFIER(elts); |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 239 | static char *Set_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 240 | "elts", |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 241 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 242 | static PyTypeObject *ListComp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 243 | _Py_IDENTIFIER(elt); |
| 244 | _Py_IDENTIFIER(generators); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 245 | static char *ListComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 246 | "elt", |
| 247 | "generators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 248 | }; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 249 | static PyTypeObject *SetComp_type; |
| 250 | static char *SetComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 251 | "elt", |
| 252 | "generators", |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 253 | }; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 254 | static PyTypeObject *DictComp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 255 | _Py_IDENTIFIER(key); |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 256 | static char *DictComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 257 | "key", |
| 258 | "value", |
| 259 | "generators", |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 260 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 261 | static PyTypeObject *GeneratorExp_type; |
| 262 | static char *GeneratorExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 263 | "elt", |
| 264 | "generators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 265 | }; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 266 | static PyTypeObject *Await_type; |
| 267 | static char *Await_fields[]={ |
| 268 | "value", |
| 269 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 270 | static PyTypeObject *Yield_type; |
| 271 | static char *Yield_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 272 | "value", |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 273 | }; |
| 274 | static PyTypeObject *YieldFrom_type; |
| 275 | static char *YieldFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 276 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 277 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 278 | static PyTypeObject *Compare_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 279 | _Py_IDENTIFIER(ops); |
| 280 | _Py_IDENTIFIER(comparators); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 281 | static char *Compare_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 282 | "left", |
| 283 | "ops", |
| 284 | "comparators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 285 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 286 | static PyTypeObject *Call_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 287 | _Py_IDENTIFIER(func); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 288 | static char *Call_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 289 | "func", |
| 290 | "args", |
| 291 | "keywords", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 292 | }; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 293 | static PyTypeObject *FormattedValue_type; |
| 294 | _Py_IDENTIFIER(conversion); |
| 295 | _Py_IDENTIFIER(format_spec); |
| 296 | static char *FormattedValue_fields[]={ |
| 297 | "value", |
| 298 | "conversion", |
| 299 | "format_spec", |
| 300 | }; |
| 301 | static PyTypeObject *JoinedStr_type; |
| 302 | static char *JoinedStr_fields[]={ |
| 303 | "values", |
| 304 | }; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 305 | static PyTypeObject *Constant_type; |
| 306 | static char *Constant_fields[]={ |
| 307 | "value", |
| 308 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 309 | static PyTypeObject *Attribute_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 310 | _Py_IDENTIFIER(attr); |
| 311 | _Py_IDENTIFIER(ctx); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 312 | static char *Attribute_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 313 | "value", |
| 314 | "attr", |
| 315 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 316 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 317 | static PyTypeObject *Subscript_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 318 | _Py_IDENTIFIER(slice); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 319 | static char *Subscript_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 320 | "value", |
| 321 | "slice", |
| 322 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 323 | }; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 324 | static PyTypeObject *Starred_type; |
| 325 | static char *Starred_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 326 | "value", |
| 327 | "ctx", |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 328 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 329 | static PyTypeObject *Name_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 330 | _Py_IDENTIFIER(id); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 331 | static char *Name_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 332 | "id", |
| 333 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 334 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 335 | static PyTypeObject *List_type; |
| 336 | static char *List_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 337 | "elts", |
| 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 *Tuple_type; |
| 341 | static char *Tuple_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 *expr_context_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 346 | static PyObject *Load_singleton, *Store_singleton, *Del_singleton, |
| 347 | *AugLoad_singleton, *AugStore_singleton, *Param_singleton; |
| 348 | static PyObject* ast2obj_expr_context(expr_context_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 349 | static PyTypeObject *Load_type; |
| 350 | static PyTypeObject *Store_type; |
| 351 | static PyTypeObject *Del_type; |
| 352 | static PyTypeObject *AugLoad_type; |
| 353 | static PyTypeObject *AugStore_type; |
| 354 | static PyTypeObject *Param_type; |
| 355 | static PyTypeObject *slice_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 356 | static PyObject* ast2obj_slice(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 357 | static PyTypeObject *Slice_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 358 | _Py_IDENTIFIER(lower); |
| 359 | _Py_IDENTIFIER(upper); |
| 360 | _Py_IDENTIFIER(step); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 361 | static char *Slice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 362 | "lower", |
| 363 | "upper", |
| 364 | "step", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 365 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 366 | static PyTypeObject *ExtSlice_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 367 | _Py_IDENTIFIER(dims); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 368 | static char *ExtSlice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 369 | "dims", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 370 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 371 | static PyTypeObject *Index_type; |
| 372 | static char *Index_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 373 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 374 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 375 | static PyTypeObject *boolop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 376 | static PyObject *And_singleton, *Or_singleton; |
| 377 | static PyObject* ast2obj_boolop(boolop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 378 | static PyTypeObject *And_type; |
| 379 | static PyTypeObject *Or_type; |
| 380 | static PyTypeObject *operator_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 381 | static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton, |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 382 | *MatMult_singleton, *Div_singleton, *Mod_singleton, *Pow_singleton, |
| 383 | *LShift_singleton, *RShift_singleton, *BitOr_singleton, *BitXor_singleton, |
| 384 | *BitAnd_singleton, *FloorDiv_singleton; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 385 | static PyObject* ast2obj_operator(operator_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 386 | static PyTypeObject *Add_type; |
| 387 | static PyTypeObject *Sub_type; |
| 388 | static PyTypeObject *Mult_type; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 389 | static PyTypeObject *MatMult_type; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 390 | static PyTypeObject *Div_type; |
| 391 | static PyTypeObject *Mod_type; |
| 392 | static PyTypeObject *Pow_type; |
| 393 | static PyTypeObject *LShift_type; |
| 394 | static PyTypeObject *RShift_type; |
| 395 | static PyTypeObject *BitOr_type; |
| 396 | static PyTypeObject *BitXor_type; |
| 397 | static PyTypeObject *BitAnd_type; |
| 398 | static PyTypeObject *FloorDiv_type; |
| 399 | static PyTypeObject *unaryop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 400 | static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton, |
| 401 | *USub_singleton; |
| 402 | static PyObject* ast2obj_unaryop(unaryop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 403 | static PyTypeObject *Invert_type; |
| 404 | static PyTypeObject *Not_type; |
| 405 | static PyTypeObject *UAdd_type; |
| 406 | static PyTypeObject *USub_type; |
| 407 | static PyTypeObject *cmpop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 408 | static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton, |
| 409 | *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton, |
| 410 | *NotIn_singleton; |
| 411 | static PyObject* ast2obj_cmpop(cmpop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 412 | static PyTypeObject *Eq_type; |
| 413 | static PyTypeObject *NotEq_type; |
| 414 | static PyTypeObject *Lt_type; |
| 415 | static PyTypeObject *LtE_type; |
| 416 | static PyTypeObject *Gt_type; |
| 417 | static PyTypeObject *GtE_type; |
| 418 | static PyTypeObject *Is_type; |
| 419 | static PyTypeObject *IsNot_type; |
| 420 | static PyTypeObject *In_type; |
| 421 | static PyTypeObject *NotIn_type; |
| 422 | static PyTypeObject *comprehension_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 423 | static PyObject* ast2obj_comprehension(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 424 | _Py_IDENTIFIER(ifs); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 425 | _Py_IDENTIFIER(is_async); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 426 | static char *comprehension_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 427 | "target", |
| 428 | "iter", |
| 429 | "ifs", |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 430 | "is_async", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 431 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 432 | static PyTypeObject *excepthandler_type; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 433 | static char *excepthandler_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 434 | "lineno", |
| 435 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 436 | "end_lineno", |
| 437 | "end_col_offset", |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 438 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 439 | static PyObject* ast2obj_excepthandler(void*); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 440 | static PyTypeObject *ExceptHandler_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 441 | _Py_IDENTIFIER(type); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 442 | static char *ExceptHandler_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 443 | "type", |
| 444 | "name", |
| 445 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 446 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 447 | static PyTypeObject *arguments_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 448 | static PyObject* ast2obj_arguments(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 449 | _Py_IDENTIFIER(vararg); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 450 | _Py_IDENTIFIER(kwonlyargs); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 451 | _Py_IDENTIFIER(kw_defaults); |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 452 | _Py_IDENTIFIER(kwarg); |
| 453 | _Py_IDENTIFIER(defaults); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 454 | static char *arguments_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 455 | "args", |
| 456 | "vararg", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 457 | "kwonlyargs", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 458 | "kw_defaults", |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 459 | "kwarg", |
| 460 | "defaults", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 461 | }; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 462 | static PyTypeObject *arg_type; |
| 463 | static PyObject* ast2obj_arg(void*); |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 464 | static char *arg_attributes[] = { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 465 | "lineno", |
| 466 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 467 | "end_lineno", |
| 468 | "end_col_offset", |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 469 | }; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 470 | _Py_IDENTIFIER(arg); |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 471 | static char *arg_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 472 | "arg", |
| 473 | "annotation", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 474 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 475 | static PyTypeObject *keyword_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 476 | static PyObject* ast2obj_keyword(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 477 | static char *keyword_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 478 | "arg", |
| 479 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 480 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 481 | static PyTypeObject *alias_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 482 | static PyObject* ast2obj_alias(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 483 | _Py_IDENTIFIER(asname); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 484 | static char *alias_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 485 | "name", |
| 486 | "asname", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 487 | }; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 488 | static PyTypeObject *withitem_type; |
| 489 | static PyObject* ast2obj_withitem(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 490 | _Py_IDENTIFIER(context_expr); |
| 491 | _Py_IDENTIFIER(optional_vars); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 492 | static char *withitem_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 493 | "context_expr", |
| 494 | "optional_vars", |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 495 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 496 | |
| 497 | |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 498 | _Py_IDENTIFIER(_fields); |
| 499 | _Py_IDENTIFIER(_attributes); |
| 500 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 501 | typedef struct { |
Victor Stinner | 45e50de | 2012-03-13 01:17:31 +0100 | [diff] [blame] | 502 | PyObject_HEAD |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 503 | PyObject *dict; |
| 504 | } AST_object; |
| 505 | |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 506 | static void |
| 507 | ast_dealloc(AST_object *self) |
| 508 | { |
INADA Naoki | a6296d3 | 2017-08-24 14:55:17 +0900 | [diff] [blame] | 509 | /* bpo-31095: UnTrack is needed before calling any callbacks */ |
| 510 | PyObject_GC_UnTrack(self); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 511 | Py_CLEAR(self->dict); |
Antoine Pitrou | 5075074 | 2012-07-08 12:43:32 +0200 | [diff] [blame] | 512 | Py_TYPE(self)->tp_free(self); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 513 | } |
| 514 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 515 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 516 | ast_traverse(AST_object *self, visitproc visit, void *arg) |
| 517 | { |
| 518 | Py_VISIT(self->dict); |
| 519 | return 0; |
| 520 | } |
| 521 | |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 522 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 523 | ast_clear(AST_object *self) |
| 524 | { |
| 525 | Py_CLEAR(self->dict); |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 526 | return 0; |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | static int |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 530 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 531 | { |
| 532 | Py_ssize_t i, numfields = 0; |
| 533 | int res = -1; |
| 534 | PyObject *key, *value, *fields; |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 535 | if (_PyObject_LookupAttrId((PyObject*)Py_TYPE(self), &PyId__fields, &fields) < 0) { |
| 536 | goto cleanup; |
| 537 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 538 | if (fields) { |
| 539 | numfields = PySequence_Size(fields); |
| 540 | if (numfields == -1) |
| 541 | goto cleanup; |
| 542 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 543 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 544 | res = 0; /* if no error occurs, this stays 0 to the end */ |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 545 | if (numfields < PyTuple_GET_SIZE(args)) { |
| 546 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most " |
| 547 | "%zd positional argument%s", |
| 548 | Py_TYPE(self)->tp_name, |
| 549 | numfields, numfields == 1 ? "" : "s"); |
| 550 | res = -1; |
| 551 | goto cleanup; |
| 552 | } |
| 553 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
| 554 | /* cannot be reached when fields is NULL */ |
| 555 | PyObject *name = PySequence_GetItem(fields, i); |
| 556 | if (!name) { |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 557 | res = -1; |
| 558 | goto cleanup; |
| 559 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 560 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
| 561 | Py_DECREF(name); |
| 562 | if (res < 0) |
| 563 | goto cleanup; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 564 | } |
| 565 | if (kw) { |
| 566 | i = 0; /* needed by PyDict_Next */ |
| 567 | while (PyDict_Next(kw, &i, &key, &value)) { |
| 568 | res = PyObject_SetAttr(self, key, value); |
| 569 | if (res < 0) |
| 570 | goto cleanup; |
| 571 | } |
| 572 | } |
| 573 | cleanup: |
| 574 | Py_XDECREF(fields); |
| 575 | return res; |
| 576 | } |
| 577 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 578 | /* Pickling support */ |
| 579 | static PyObject * |
| 580 | ast_type_reduce(PyObject *self, PyObject *unused) |
| 581 | { |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 582 | _Py_IDENTIFIER(__dict__); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 583 | PyObject *dict; |
| 584 | if (_PyObject_LookupAttrId(self, &PyId___dict__, &dict) < 0) { |
| 585 | return NULL; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 586 | } |
| 587 | if (dict) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 588 | return Py_BuildValue("O()N", Py_TYPE(self), dict); |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 589 | } |
| 590 | return Py_BuildValue("O()", Py_TYPE(self)); |
| 591 | } |
| 592 | |
| 593 | static PyMethodDef ast_type_methods[] = { |
| 594 | {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, |
| 595 | {NULL} |
| 596 | }; |
| 597 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 598 | static PyGetSetDef ast_type_getsets[] = { |
| 599 | {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict}, |
| 600 | {NULL} |
| 601 | }; |
| 602 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 603 | static PyTypeObject AST_type = { |
| 604 | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 605 | "_ast.AST", |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 606 | sizeof(AST_object), |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 607 | 0, |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 608 | (destructor)ast_dealloc, /* tp_dealloc */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 609 | 0, /* tp_print */ |
| 610 | 0, /* tp_getattr */ |
| 611 | 0, /* tp_setattr */ |
Mark Dickinson | e94c679 | 2009-02-02 20:36:42 +0000 | [diff] [blame] | 612 | 0, /* tp_reserved */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 613 | 0, /* tp_repr */ |
| 614 | 0, /* tp_as_number */ |
| 615 | 0, /* tp_as_sequence */ |
| 616 | 0, /* tp_as_mapping */ |
| 617 | 0, /* tp_hash */ |
| 618 | 0, /* tp_call */ |
| 619 | 0, /* tp_str */ |
| 620 | PyObject_GenericGetAttr, /* tp_getattro */ |
| 621 | PyObject_GenericSetAttr, /* tp_setattro */ |
| 622 | 0, /* tp_as_buffer */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 623 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 624 | 0, /* tp_doc */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 625 | (traverseproc)ast_traverse, /* tp_traverse */ |
| 626 | (inquiry)ast_clear, /* tp_clear */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 627 | 0, /* tp_richcompare */ |
| 628 | 0, /* tp_weaklistoffset */ |
| 629 | 0, /* tp_iter */ |
| 630 | 0, /* tp_iternext */ |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 631 | ast_type_methods, /* tp_methods */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 632 | 0, /* tp_members */ |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 633 | ast_type_getsets, /* tp_getset */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 634 | 0, /* tp_base */ |
| 635 | 0, /* tp_dict */ |
| 636 | 0, /* tp_descr_get */ |
| 637 | 0, /* tp_descr_set */ |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 638 | offsetof(AST_object, dict),/* tp_dictoffset */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 639 | (initproc)ast_type_init, /* tp_init */ |
| 640 | PyType_GenericAlloc, /* tp_alloc */ |
| 641 | PyType_GenericNew, /* tp_new */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 642 | PyObject_GC_Del, /* tp_free */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 643 | }; |
| 644 | |
| 645 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 646 | static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields) |
| 647 | { |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 648 | _Py_IDENTIFIER(__module__); |
| 649 | _Py_IDENTIFIER(_ast); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 650 | PyObject *fnames, *result; |
| 651 | int i; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 652 | fnames = PyTuple_New(num_fields); |
| 653 | if (!fnames) return NULL; |
| 654 | for (i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 655 | PyObject *field = PyUnicode_FromString(fields[i]); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 656 | if (!field) { |
| 657 | Py_DECREF(fnames); |
| 658 | return NULL; |
| 659 | } |
| 660 | PyTuple_SET_ITEM(fnames, i, field); |
| 661 | } |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 662 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOO}", |
| 663 | type, base, |
| 664 | _PyUnicode_FromId(&PyId__fields), fnames, |
| 665 | _PyUnicode_FromId(&PyId___module__), |
| 666 | _PyUnicode_FromId(&PyId__ast)); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 667 | Py_DECREF(fnames); |
| 668 | return (PyTypeObject*)result; |
| 669 | } |
| 670 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 671 | static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) |
| 672 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 673 | int i, result; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 674 | PyObject *s, *l = PyTuple_New(num_fields); |
Benjamin Peterson | 3e5cd1d | 2010-06-27 21:45:24 +0000 | [diff] [blame] | 675 | if (!l) |
| 676 | return 0; |
| 677 | for (i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 678 | s = PyUnicode_FromString(attrs[i]); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 679 | if (!s) { |
| 680 | Py_DECREF(l); |
| 681 | return 0; |
| 682 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 683 | PyTuple_SET_ITEM(l, i, s); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 684 | } |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 685 | result = _PyObject_SetAttrId((PyObject*)type, &PyId__attributes, l) >= 0; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 686 | Py_DECREF(l); |
| 687 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 688 | } |
| 689 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 690 | /* Conversion AST -> Python */ |
| 691 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 692 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 693 | { |
Benjamin Peterson | 77fa937 | 2012-05-15 10:10:27 -0700 | [diff] [blame] | 694 | Py_ssize_t i, n = asdl_seq_LEN(seq); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 695 | PyObject *result = PyList_New(n); |
| 696 | PyObject *value; |
| 697 | if (!result) |
| 698 | return NULL; |
| 699 | for (i = 0; i < n; i++) { |
| 700 | value = func(asdl_seq_GET(seq, i)); |
| 701 | if (!value) { |
| 702 | Py_DECREF(result); |
| 703 | return NULL; |
| 704 | } |
| 705 | PyList_SET_ITEM(result, i, value); |
| 706 | } |
| 707 | return result; |
| 708 | } |
| 709 | |
| 710 | static PyObject* ast2obj_object(void *o) |
| 711 | { |
| 712 | if (!o) |
| 713 | o = Py_None; |
| 714 | Py_INCREF((PyObject*)o); |
| 715 | return (PyObject*)o; |
| 716 | } |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 717 | #define ast2obj_singleton ast2obj_object |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 718 | #define ast2obj_constant ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 719 | #define ast2obj_identifier ast2obj_object |
| 720 | #define ast2obj_string ast2obj_object |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 721 | #define ast2obj_bytes ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 722 | |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 723 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 724 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 725 | return PyLong_FromLong(b); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 726 | } |
| 727 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 728 | /* Conversion Python -> AST */ |
| 729 | |
| 730 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 731 | { |
| 732 | if (obj == Py_None) |
| 733 | obj = NULL; |
Christian Heimes | 70c94e7 | 2013-07-27 00:33:13 +0200 | [diff] [blame] | 734 | if (obj) { |
| 735 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 736 | *out = NULL; |
| 737 | return -1; |
| 738 | } |
| 739 | Py_INCREF(obj); |
| 740 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 741 | *out = obj; |
| 742 | return 0; |
| 743 | } |
| 744 | |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 745 | static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena) |
| 746 | { |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 747 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 748 | *out = NULL; |
| 749 | return -1; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 750 | } |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 751 | Py_INCREF(obj); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 752 | *out = obj; |
| 753 | return 0; |
| 754 | } |
| 755 | |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 756 | static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 757 | { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 758 | if (!PyUnicode_CheckExact(obj) && obj != Py_None) { |
| 759 | PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 760 | return 1; |
| 761 | } |
| 762 | return obj2ast_object(obj, out, arena); |
| 763 | } |
| 764 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 765 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 766 | { |
| 767 | int i; |
| 768 | if (!PyLong_Check(obj)) { |
Amaury Forgeot d'Arc | 5e8f810 | 2011-11-22 21:52:30 +0100 | [diff] [blame] | 769 | PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 770 | return 1; |
| 771 | } |
| 772 | |
Serhiy Storchaka | 56f6e76 | 2015-09-06 21:25:30 +0300 | [diff] [blame] | 773 | i = _PyLong_AsInt(obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 774 | if (i == -1 && PyErr_Occurred()) |
| 775 | return 1; |
| 776 | *out = i; |
| 777 | return 0; |
| 778 | } |
| 779 | |
Benjamin Peterson | 1a6e0d0 | 2008-10-25 15:49:17 +0000 | [diff] [blame] | 780 | static int add_ast_fields(void) |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 781 | { |
| 782 | PyObject *empty_tuple, *d; |
| 783 | if (PyType_Ready(&AST_type) < 0) |
| 784 | return -1; |
| 785 | d = AST_type.tp_dict; |
| 786 | empty_tuple = PyTuple_New(0); |
| 787 | if (!empty_tuple || |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 788 | _PyDict_SetItemId(d, &PyId__fields, empty_tuple) < 0 || |
| 789 | _PyDict_SetItemId(d, &PyId__attributes, empty_tuple) < 0) { |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 790 | Py_XDECREF(empty_tuple); |
| 791 | return -1; |
| 792 | } |
| 793 | Py_DECREF(empty_tuple); |
| 794 | return 0; |
| 795 | } |
| 796 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 797 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 798 | static int init_types(void) |
| 799 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 800 | static int initialized; |
| 801 | if (initialized) return 1; |
| 802 | if (add_ast_fields() < 0) return 0; |
| 803 | mod_type = make_type("mod", &AST_type, NULL, 0); |
| 804 | if (!mod_type) return 0; |
| 805 | if (!add_attributes(mod_type, NULL, 0)) return 0; |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 806 | Module_type = make_type("Module", mod_type, Module_fields, 1); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 807 | if (!Module_type) return 0; |
| 808 | Interactive_type = make_type("Interactive", mod_type, Interactive_fields, |
| 809 | 1); |
| 810 | if (!Interactive_type) return 0; |
| 811 | Expression_type = make_type("Expression", mod_type, Expression_fields, 1); |
| 812 | if (!Expression_type) return 0; |
| 813 | Suite_type = make_type("Suite", mod_type, Suite_fields, 1); |
| 814 | if (!Suite_type) return 0; |
| 815 | stmt_type = make_type("stmt", &AST_type, NULL, 0); |
| 816 | if (!stmt_type) return 0; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 817 | if (!add_attributes(stmt_type, stmt_attributes, 4)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 818 | FunctionDef_type = make_type("FunctionDef", stmt_type, FunctionDef_fields, |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 819 | 5); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 820 | if (!FunctionDef_type) return 0; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 821 | AsyncFunctionDef_type = make_type("AsyncFunctionDef", stmt_type, |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 822 | AsyncFunctionDef_fields, 5); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 823 | if (!AsyncFunctionDef_type) return 0; |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 824 | ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 5); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 825 | if (!ClassDef_type) return 0; |
| 826 | Return_type = make_type("Return", stmt_type, Return_fields, 1); |
| 827 | if (!Return_type) return 0; |
| 828 | Delete_type = make_type("Delete", stmt_type, Delete_fields, 1); |
| 829 | if (!Delete_type) return 0; |
| 830 | Assign_type = make_type("Assign", stmt_type, Assign_fields, 2); |
| 831 | if (!Assign_type) return 0; |
| 832 | AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); |
| 833 | if (!AugAssign_type) return 0; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 834 | AnnAssign_type = make_type("AnnAssign", stmt_type, AnnAssign_fields, 4); |
| 835 | if (!AnnAssign_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 836 | For_type = make_type("For", stmt_type, For_fields, 4); |
| 837 | if (!For_type) return 0; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 838 | AsyncFor_type = make_type("AsyncFor", stmt_type, AsyncFor_fields, 4); |
| 839 | if (!AsyncFor_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 840 | While_type = make_type("While", stmt_type, While_fields, 3); |
| 841 | if (!While_type) return 0; |
| 842 | If_type = make_type("If", stmt_type, If_fields, 3); |
| 843 | if (!If_type) return 0; |
| 844 | With_type = make_type("With", stmt_type, With_fields, 2); |
| 845 | if (!With_type) return 0; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 846 | AsyncWith_type = make_type("AsyncWith", stmt_type, AsyncWith_fields, 2); |
| 847 | if (!AsyncWith_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 848 | Raise_type = make_type("Raise", stmt_type, Raise_fields, 2); |
| 849 | if (!Raise_type) return 0; |
| 850 | Try_type = make_type("Try", stmt_type, Try_fields, 4); |
| 851 | if (!Try_type) return 0; |
| 852 | Assert_type = make_type("Assert", stmt_type, Assert_fields, 2); |
| 853 | if (!Assert_type) return 0; |
| 854 | Import_type = make_type("Import", stmt_type, Import_fields, 1); |
| 855 | if (!Import_type) return 0; |
| 856 | ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, 3); |
| 857 | if (!ImportFrom_type) return 0; |
| 858 | Global_type = make_type("Global", stmt_type, Global_fields, 1); |
| 859 | if (!Global_type) return 0; |
| 860 | Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1); |
| 861 | if (!Nonlocal_type) return 0; |
| 862 | Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); |
| 863 | if (!Expr_type) return 0; |
| 864 | Pass_type = make_type("Pass", stmt_type, NULL, 0); |
| 865 | if (!Pass_type) return 0; |
| 866 | Break_type = make_type("Break", stmt_type, NULL, 0); |
| 867 | if (!Break_type) return 0; |
| 868 | Continue_type = make_type("Continue", stmt_type, NULL, 0); |
| 869 | if (!Continue_type) return 0; |
| 870 | expr_type = make_type("expr", &AST_type, NULL, 0); |
| 871 | if (!expr_type) return 0; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 872 | if (!add_attributes(expr_type, expr_attributes, 4)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 873 | BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2); |
| 874 | if (!BoolOp_type) return 0; |
| 875 | BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3); |
| 876 | if (!BinOp_type) return 0; |
| 877 | UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2); |
| 878 | if (!UnaryOp_type) return 0; |
| 879 | Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2); |
| 880 | if (!Lambda_type) return 0; |
| 881 | IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); |
| 882 | if (!IfExp_type) return 0; |
| 883 | Dict_type = make_type("Dict", expr_type, Dict_fields, 2); |
| 884 | if (!Dict_type) return 0; |
| 885 | Set_type = make_type("Set", expr_type, Set_fields, 1); |
| 886 | if (!Set_type) return 0; |
| 887 | ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); |
| 888 | if (!ListComp_type) return 0; |
| 889 | SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2); |
| 890 | if (!SetComp_type) return 0; |
| 891 | DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3); |
| 892 | if (!DictComp_type) return 0; |
| 893 | GeneratorExp_type = make_type("GeneratorExp", expr_type, |
| 894 | GeneratorExp_fields, 2); |
| 895 | if (!GeneratorExp_type) return 0; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 896 | Await_type = make_type("Await", expr_type, Await_fields, 1); |
| 897 | if (!Await_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 898 | Yield_type = make_type("Yield", expr_type, Yield_fields, 1); |
| 899 | if (!Yield_type) return 0; |
| 900 | YieldFrom_type = make_type("YieldFrom", expr_type, YieldFrom_fields, 1); |
| 901 | if (!YieldFrom_type) return 0; |
| 902 | Compare_type = make_type("Compare", expr_type, Compare_fields, 3); |
| 903 | if (!Compare_type) return 0; |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 904 | Call_type = make_type("Call", expr_type, Call_fields, 3); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 905 | if (!Call_type) return 0; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 906 | FormattedValue_type = make_type("FormattedValue", expr_type, |
| 907 | FormattedValue_fields, 3); |
| 908 | if (!FormattedValue_type) return 0; |
| 909 | JoinedStr_type = make_type("JoinedStr", expr_type, JoinedStr_fields, 1); |
| 910 | if (!JoinedStr_type) return 0; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 911 | Constant_type = make_type("Constant", expr_type, Constant_fields, 1); |
| 912 | if (!Constant_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 913 | Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); |
| 914 | if (!Attribute_type) return 0; |
| 915 | Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); |
| 916 | if (!Subscript_type) return 0; |
| 917 | Starred_type = make_type("Starred", expr_type, Starred_fields, 2); |
| 918 | if (!Starred_type) return 0; |
| 919 | Name_type = make_type("Name", expr_type, Name_fields, 2); |
| 920 | if (!Name_type) return 0; |
| 921 | List_type = make_type("List", expr_type, List_fields, 2); |
| 922 | if (!List_type) return 0; |
| 923 | Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2); |
| 924 | if (!Tuple_type) return 0; |
| 925 | expr_context_type = make_type("expr_context", &AST_type, NULL, 0); |
| 926 | if (!expr_context_type) return 0; |
| 927 | if (!add_attributes(expr_context_type, NULL, 0)) return 0; |
| 928 | Load_type = make_type("Load", expr_context_type, NULL, 0); |
| 929 | if (!Load_type) return 0; |
| 930 | Load_singleton = PyType_GenericNew(Load_type, NULL, NULL); |
| 931 | if (!Load_singleton) return 0; |
| 932 | Store_type = make_type("Store", expr_context_type, NULL, 0); |
| 933 | if (!Store_type) return 0; |
| 934 | Store_singleton = PyType_GenericNew(Store_type, NULL, NULL); |
| 935 | if (!Store_singleton) return 0; |
| 936 | Del_type = make_type("Del", expr_context_type, NULL, 0); |
| 937 | if (!Del_type) return 0; |
| 938 | Del_singleton = PyType_GenericNew(Del_type, NULL, NULL); |
| 939 | if (!Del_singleton) return 0; |
| 940 | AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0); |
| 941 | if (!AugLoad_type) return 0; |
| 942 | AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL); |
| 943 | if (!AugLoad_singleton) return 0; |
| 944 | AugStore_type = make_type("AugStore", expr_context_type, NULL, 0); |
| 945 | if (!AugStore_type) return 0; |
| 946 | AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL); |
| 947 | if (!AugStore_singleton) return 0; |
| 948 | Param_type = make_type("Param", expr_context_type, NULL, 0); |
| 949 | if (!Param_type) return 0; |
| 950 | Param_singleton = PyType_GenericNew(Param_type, NULL, NULL); |
| 951 | if (!Param_singleton) return 0; |
| 952 | slice_type = make_type("slice", &AST_type, NULL, 0); |
| 953 | if (!slice_type) return 0; |
| 954 | if (!add_attributes(slice_type, NULL, 0)) return 0; |
| 955 | Slice_type = make_type("Slice", slice_type, Slice_fields, 3); |
| 956 | if (!Slice_type) return 0; |
| 957 | ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); |
| 958 | if (!ExtSlice_type) return 0; |
| 959 | Index_type = make_type("Index", slice_type, Index_fields, 1); |
| 960 | if (!Index_type) return 0; |
| 961 | boolop_type = make_type("boolop", &AST_type, NULL, 0); |
| 962 | if (!boolop_type) return 0; |
| 963 | if (!add_attributes(boolop_type, NULL, 0)) return 0; |
| 964 | And_type = make_type("And", boolop_type, NULL, 0); |
| 965 | if (!And_type) return 0; |
| 966 | And_singleton = PyType_GenericNew(And_type, NULL, NULL); |
| 967 | if (!And_singleton) return 0; |
| 968 | Or_type = make_type("Or", boolop_type, NULL, 0); |
| 969 | if (!Or_type) return 0; |
| 970 | Or_singleton = PyType_GenericNew(Or_type, NULL, NULL); |
| 971 | if (!Or_singleton) return 0; |
| 972 | operator_type = make_type("operator", &AST_type, NULL, 0); |
| 973 | if (!operator_type) return 0; |
| 974 | if (!add_attributes(operator_type, NULL, 0)) return 0; |
| 975 | Add_type = make_type("Add", operator_type, NULL, 0); |
| 976 | if (!Add_type) return 0; |
| 977 | Add_singleton = PyType_GenericNew(Add_type, NULL, NULL); |
| 978 | if (!Add_singleton) return 0; |
| 979 | Sub_type = make_type("Sub", operator_type, NULL, 0); |
| 980 | if (!Sub_type) return 0; |
| 981 | Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL); |
| 982 | if (!Sub_singleton) return 0; |
| 983 | Mult_type = make_type("Mult", operator_type, NULL, 0); |
| 984 | if (!Mult_type) return 0; |
| 985 | Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL); |
| 986 | if (!Mult_singleton) return 0; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 987 | MatMult_type = make_type("MatMult", operator_type, NULL, 0); |
| 988 | if (!MatMult_type) return 0; |
| 989 | MatMult_singleton = PyType_GenericNew(MatMult_type, NULL, NULL); |
| 990 | if (!MatMult_singleton) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 991 | Div_type = make_type("Div", operator_type, NULL, 0); |
| 992 | if (!Div_type) return 0; |
| 993 | Div_singleton = PyType_GenericNew(Div_type, NULL, NULL); |
| 994 | if (!Div_singleton) return 0; |
| 995 | Mod_type = make_type("Mod", operator_type, NULL, 0); |
| 996 | if (!Mod_type) return 0; |
| 997 | Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL); |
| 998 | if (!Mod_singleton) return 0; |
| 999 | Pow_type = make_type("Pow", operator_type, NULL, 0); |
| 1000 | if (!Pow_type) return 0; |
| 1001 | Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL); |
| 1002 | if (!Pow_singleton) return 0; |
| 1003 | LShift_type = make_type("LShift", operator_type, NULL, 0); |
| 1004 | if (!LShift_type) return 0; |
| 1005 | LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL); |
| 1006 | if (!LShift_singleton) return 0; |
| 1007 | RShift_type = make_type("RShift", operator_type, NULL, 0); |
| 1008 | if (!RShift_type) return 0; |
| 1009 | RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL); |
| 1010 | if (!RShift_singleton) return 0; |
| 1011 | BitOr_type = make_type("BitOr", operator_type, NULL, 0); |
| 1012 | if (!BitOr_type) return 0; |
| 1013 | BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL); |
| 1014 | if (!BitOr_singleton) return 0; |
| 1015 | BitXor_type = make_type("BitXor", operator_type, NULL, 0); |
| 1016 | if (!BitXor_type) return 0; |
| 1017 | BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL); |
| 1018 | if (!BitXor_singleton) return 0; |
| 1019 | BitAnd_type = make_type("BitAnd", operator_type, NULL, 0); |
| 1020 | if (!BitAnd_type) return 0; |
| 1021 | BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL); |
| 1022 | if (!BitAnd_singleton) return 0; |
| 1023 | FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0); |
| 1024 | if (!FloorDiv_type) return 0; |
| 1025 | FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL); |
| 1026 | if (!FloorDiv_singleton) return 0; |
| 1027 | unaryop_type = make_type("unaryop", &AST_type, NULL, 0); |
| 1028 | if (!unaryop_type) return 0; |
| 1029 | if (!add_attributes(unaryop_type, NULL, 0)) return 0; |
| 1030 | Invert_type = make_type("Invert", unaryop_type, NULL, 0); |
| 1031 | if (!Invert_type) return 0; |
| 1032 | Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL); |
| 1033 | if (!Invert_singleton) return 0; |
| 1034 | Not_type = make_type("Not", unaryop_type, NULL, 0); |
| 1035 | if (!Not_type) return 0; |
| 1036 | Not_singleton = PyType_GenericNew(Not_type, NULL, NULL); |
| 1037 | if (!Not_singleton) return 0; |
| 1038 | UAdd_type = make_type("UAdd", unaryop_type, NULL, 0); |
| 1039 | if (!UAdd_type) return 0; |
| 1040 | UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL); |
| 1041 | if (!UAdd_singleton) return 0; |
| 1042 | USub_type = make_type("USub", unaryop_type, NULL, 0); |
| 1043 | if (!USub_type) return 0; |
| 1044 | USub_singleton = PyType_GenericNew(USub_type, NULL, NULL); |
| 1045 | if (!USub_singleton) return 0; |
| 1046 | cmpop_type = make_type("cmpop", &AST_type, NULL, 0); |
| 1047 | if (!cmpop_type) return 0; |
| 1048 | if (!add_attributes(cmpop_type, NULL, 0)) return 0; |
| 1049 | Eq_type = make_type("Eq", cmpop_type, NULL, 0); |
| 1050 | if (!Eq_type) return 0; |
| 1051 | Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL); |
| 1052 | if (!Eq_singleton) return 0; |
| 1053 | NotEq_type = make_type("NotEq", cmpop_type, NULL, 0); |
| 1054 | if (!NotEq_type) return 0; |
| 1055 | NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL); |
| 1056 | if (!NotEq_singleton) return 0; |
| 1057 | Lt_type = make_type("Lt", cmpop_type, NULL, 0); |
| 1058 | if (!Lt_type) return 0; |
| 1059 | Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL); |
| 1060 | if (!Lt_singleton) return 0; |
| 1061 | LtE_type = make_type("LtE", cmpop_type, NULL, 0); |
| 1062 | if (!LtE_type) return 0; |
| 1063 | LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL); |
| 1064 | if (!LtE_singleton) return 0; |
| 1065 | Gt_type = make_type("Gt", cmpop_type, NULL, 0); |
| 1066 | if (!Gt_type) return 0; |
| 1067 | Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL); |
| 1068 | if (!Gt_singleton) return 0; |
| 1069 | GtE_type = make_type("GtE", cmpop_type, NULL, 0); |
| 1070 | if (!GtE_type) return 0; |
| 1071 | GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL); |
| 1072 | if (!GtE_singleton) return 0; |
| 1073 | Is_type = make_type("Is", cmpop_type, NULL, 0); |
| 1074 | if (!Is_type) return 0; |
| 1075 | Is_singleton = PyType_GenericNew(Is_type, NULL, NULL); |
| 1076 | if (!Is_singleton) return 0; |
| 1077 | IsNot_type = make_type("IsNot", cmpop_type, NULL, 0); |
| 1078 | if (!IsNot_type) return 0; |
| 1079 | IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL); |
| 1080 | if (!IsNot_singleton) return 0; |
| 1081 | In_type = make_type("In", cmpop_type, NULL, 0); |
| 1082 | if (!In_type) return 0; |
| 1083 | In_singleton = PyType_GenericNew(In_type, NULL, NULL); |
| 1084 | if (!In_singleton) return 0; |
| 1085 | NotIn_type = make_type("NotIn", cmpop_type, NULL, 0); |
| 1086 | if (!NotIn_type) return 0; |
| 1087 | NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL); |
| 1088 | if (!NotIn_singleton) return 0; |
| 1089 | comprehension_type = make_type("comprehension", &AST_type, |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 1090 | comprehension_fields, 4); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1091 | if (!comprehension_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1092 | if (!add_attributes(comprehension_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1093 | excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0); |
| 1094 | if (!excepthandler_type) return 0; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1095 | if (!add_attributes(excepthandler_type, excepthandler_attributes, 4)) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1096 | return 0; |
| 1097 | ExceptHandler_type = make_type("ExceptHandler", excepthandler_type, |
| 1098 | ExceptHandler_fields, 3); |
| 1099 | if (!ExceptHandler_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1100 | arguments_type = make_type("arguments", &AST_type, arguments_fields, 6); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1101 | if (!arguments_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1102 | if (!add_attributes(arguments_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1103 | arg_type = make_type("arg", &AST_type, arg_fields, 2); |
| 1104 | if (!arg_type) return 0; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1105 | if (!add_attributes(arg_type, arg_attributes, 4)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1106 | keyword_type = make_type("keyword", &AST_type, keyword_fields, 2); |
| 1107 | if (!keyword_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1108 | if (!add_attributes(keyword_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1109 | alias_type = make_type("alias", &AST_type, alias_fields, 2); |
| 1110 | if (!alias_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1111 | if (!add_attributes(alias_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1112 | withitem_type = make_type("withitem", &AST_type, withitem_fields, 2); |
| 1113 | if (!withitem_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1114 | if (!add_attributes(withitem_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1115 | initialized = 1; |
| 1116 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1117 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 1118 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1119 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 1120 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 1121 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 1122 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 1123 | arena); |
| 1124 | static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena); |
| 1125 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 1126 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 1127 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 1128 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 1129 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 1130 | arena); |
| 1131 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 1132 | arena); |
| 1133 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 1134 | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
| 1135 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 1136 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1137 | 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] | 1138 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1139 | mod_ty |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 1140 | Module(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1141 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1142 | mod_ty p; |
| 1143 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1144 | if (!p) |
| 1145 | return NULL; |
| 1146 | p->kind = Module_kind; |
| 1147 | p->v.Module.body = body; |
| 1148 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1152 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1153 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1154 | mod_ty p; |
| 1155 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1156 | if (!p) |
| 1157 | return NULL; |
| 1158 | p->kind = Interactive_kind; |
| 1159 | p->v.Interactive.body = body; |
| 1160 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1161 | } |
| 1162 | |
| 1163 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1164 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1165 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1166 | mod_ty p; |
| 1167 | if (!body) { |
| 1168 | PyErr_SetString(PyExc_ValueError, |
| 1169 | "field body is required for Expression"); |
| 1170 | return NULL; |
| 1171 | } |
| 1172 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1173 | if (!p) |
| 1174 | return NULL; |
| 1175 | p->kind = Expression_kind; |
| 1176 | p->v.Expression.body = body; |
| 1177 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1181 | Suite(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1182 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1183 | mod_ty p; |
| 1184 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1185 | if (!p) |
| 1186 | return NULL; |
| 1187 | p->kind = Suite_kind; |
| 1188 | p->v.Suite.body = body; |
| 1189 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | stmt_ty |
| 1193 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1194 | decorator_list, expr_ty returns, int lineno, int col_offset, int |
| 1195 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1196 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1197 | stmt_ty p; |
| 1198 | if (!name) { |
| 1199 | PyErr_SetString(PyExc_ValueError, |
| 1200 | "field name is required for FunctionDef"); |
| 1201 | return NULL; |
| 1202 | } |
| 1203 | if (!args) { |
| 1204 | PyErr_SetString(PyExc_ValueError, |
| 1205 | "field args is required for FunctionDef"); |
| 1206 | return NULL; |
| 1207 | } |
| 1208 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1209 | if (!p) |
| 1210 | return NULL; |
| 1211 | p->kind = FunctionDef_kind; |
| 1212 | p->v.FunctionDef.name = name; |
| 1213 | p->v.FunctionDef.args = args; |
| 1214 | p->v.FunctionDef.body = body; |
| 1215 | p->v.FunctionDef.decorator_list = decorator_list; |
| 1216 | p->v.FunctionDef.returns = returns; |
| 1217 | p->lineno = lineno; |
| 1218 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1219 | p->end_lineno = end_lineno; |
| 1220 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1221 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1222 | } |
| 1223 | |
| 1224 | stmt_ty |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1225 | AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 1226 | * decorator_list, expr_ty returns, int lineno, int col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1227 | int end_lineno, int end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1228 | { |
| 1229 | stmt_ty p; |
| 1230 | if (!name) { |
| 1231 | PyErr_SetString(PyExc_ValueError, |
| 1232 | "field name is required for AsyncFunctionDef"); |
| 1233 | return NULL; |
| 1234 | } |
| 1235 | if (!args) { |
| 1236 | PyErr_SetString(PyExc_ValueError, |
| 1237 | "field args is required for AsyncFunctionDef"); |
| 1238 | return NULL; |
| 1239 | } |
| 1240 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1241 | if (!p) |
| 1242 | return NULL; |
| 1243 | p->kind = AsyncFunctionDef_kind; |
| 1244 | p->v.AsyncFunctionDef.name = name; |
| 1245 | p->v.AsyncFunctionDef.args = args; |
| 1246 | p->v.AsyncFunctionDef.body = body; |
| 1247 | p->v.AsyncFunctionDef.decorator_list = decorator_list; |
| 1248 | p->v.AsyncFunctionDef.returns = returns; |
| 1249 | p->lineno = lineno; |
| 1250 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1251 | p->end_lineno = end_lineno; |
| 1252 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1253 | return p; |
| 1254 | } |
| 1255 | |
| 1256 | stmt_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 1257 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1258 | body, asdl_seq * decorator_list, int lineno, int col_offset, int |
| 1259 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1260 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1261 | stmt_ty p; |
| 1262 | if (!name) { |
| 1263 | PyErr_SetString(PyExc_ValueError, |
| 1264 | "field name is required for ClassDef"); |
| 1265 | return NULL; |
| 1266 | } |
| 1267 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1268 | if (!p) |
| 1269 | return NULL; |
| 1270 | p->kind = ClassDef_kind; |
| 1271 | p->v.ClassDef.name = name; |
| 1272 | p->v.ClassDef.bases = bases; |
| 1273 | p->v.ClassDef.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1274 | p->v.ClassDef.body = body; |
| 1275 | p->v.ClassDef.decorator_list = decorator_list; |
| 1276 | p->lineno = lineno; |
| 1277 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1278 | p->end_lineno = end_lineno; |
| 1279 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1280 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1281 | } |
| 1282 | |
| 1283 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1284 | Return(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 1285 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1286 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1287 | stmt_ty p; |
| 1288 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1289 | if (!p) |
| 1290 | return NULL; |
| 1291 | p->kind = Return_kind; |
| 1292 | p->v.Return.value = value; |
| 1293 | p->lineno = lineno; |
| 1294 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1295 | p->end_lineno = end_lineno; |
| 1296 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1297 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1301 | Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int |
| 1302 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1303 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1304 | stmt_ty p; |
| 1305 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1306 | if (!p) |
| 1307 | return NULL; |
| 1308 | p->kind = Delete_kind; |
| 1309 | p->v.Delete.targets = targets; |
| 1310 | p->lineno = lineno; |
| 1311 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1312 | p->end_lineno = end_lineno; |
| 1313 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1314 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1318 | Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, int |
| 1319 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1320 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1321 | stmt_ty p; |
| 1322 | if (!value) { |
| 1323 | PyErr_SetString(PyExc_ValueError, |
| 1324 | "field value is required for Assign"); |
| 1325 | return NULL; |
| 1326 | } |
| 1327 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1328 | if (!p) |
| 1329 | return NULL; |
| 1330 | p->kind = Assign_kind; |
| 1331 | p->v.Assign.targets = targets; |
| 1332 | p->v.Assign.value = value; |
| 1333 | p->lineno = lineno; |
| 1334 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1335 | p->end_lineno = end_lineno; |
| 1336 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1337 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1341 | 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] | 1342 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1343 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1344 | stmt_ty p; |
| 1345 | if (!target) { |
| 1346 | PyErr_SetString(PyExc_ValueError, |
| 1347 | "field target is required for AugAssign"); |
| 1348 | return NULL; |
| 1349 | } |
| 1350 | if (!op) { |
| 1351 | PyErr_SetString(PyExc_ValueError, |
| 1352 | "field op is required for AugAssign"); |
| 1353 | return NULL; |
| 1354 | } |
| 1355 | if (!value) { |
| 1356 | PyErr_SetString(PyExc_ValueError, |
| 1357 | "field value is required for AugAssign"); |
| 1358 | return NULL; |
| 1359 | } |
| 1360 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1361 | if (!p) |
| 1362 | return NULL; |
| 1363 | p->kind = AugAssign_kind; |
| 1364 | p->v.AugAssign.target = target; |
| 1365 | p->v.AugAssign.op = op; |
| 1366 | p->v.AugAssign.value = value; |
| 1367 | p->lineno = lineno; |
| 1368 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1369 | p->end_lineno = end_lineno; |
| 1370 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1371 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1372 | } |
| 1373 | |
| 1374 | stmt_ty |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 1375 | 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] | 1376 | lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 1377 | *arena) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 1378 | { |
| 1379 | stmt_ty p; |
| 1380 | if (!target) { |
| 1381 | PyErr_SetString(PyExc_ValueError, |
| 1382 | "field target is required for AnnAssign"); |
| 1383 | return NULL; |
| 1384 | } |
| 1385 | if (!annotation) { |
| 1386 | PyErr_SetString(PyExc_ValueError, |
| 1387 | "field annotation is required for AnnAssign"); |
| 1388 | return NULL; |
| 1389 | } |
| 1390 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1391 | if (!p) |
| 1392 | return NULL; |
| 1393 | p->kind = AnnAssign_kind; |
| 1394 | p->v.AnnAssign.target = target; |
| 1395 | p->v.AnnAssign.annotation = annotation; |
| 1396 | p->v.AnnAssign.value = value; |
| 1397 | p->v.AnnAssign.simple = simple; |
| 1398 | p->lineno = lineno; |
| 1399 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1400 | p->end_lineno = end_lineno; |
| 1401 | p->end_col_offset = end_col_offset; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 1402 | return p; |
| 1403 | } |
| 1404 | |
| 1405 | stmt_ty |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1406 | 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] | 1407 | 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] | 1408 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1409 | stmt_ty p; |
| 1410 | if (!target) { |
| 1411 | PyErr_SetString(PyExc_ValueError, |
| 1412 | "field target is required for For"); |
| 1413 | return NULL; |
| 1414 | } |
| 1415 | if (!iter) { |
| 1416 | PyErr_SetString(PyExc_ValueError, |
| 1417 | "field iter is required for For"); |
| 1418 | return NULL; |
| 1419 | } |
| 1420 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1421 | if (!p) |
| 1422 | return NULL; |
| 1423 | p->kind = For_kind; |
| 1424 | p->v.For.target = target; |
| 1425 | p->v.For.iter = iter; |
| 1426 | p->v.For.body = body; |
| 1427 | p->v.For.orelse = orelse; |
| 1428 | p->lineno = lineno; |
| 1429 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1430 | p->end_lineno = end_lineno; |
| 1431 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1432 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1433 | } |
| 1434 | |
| 1435 | stmt_ty |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1436 | 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] | 1437 | lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 1438 | *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1439 | { |
| 1440 | stmt_ty p; |
| 1441 | if (!target) { |
| 1442 | PyErr_SetString(PyExc_ValueError, |
| 1443 | "field target is required for AsyncFor"); |
| 1444 | return NULL; |
| 1445 | } |
| 1446 | if (!iter) { |
| 1447 | PyErr_SetString(PyExc_ValueError, |
| 1448 | "field iter is required for AsyncFor"); |
| 1449 | return NULL; |
| 1450 | } |
| 1451 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1452 | if (!p) |
| 1453 | return NULL; |
| 1454 | p->kind = AsyncFor_kind; |
| 1455 | p->v.AsyncFor.target = target; |
| 1456 | p->v.AsyncFor.iter = iter; |
| 1457 | p->v.AsyncFor.body = body; |
| 1458 | p->v.AsyncFor.orelse = orelse; |
| 1459 | p->lineno = lineno; |
| 1460 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1461 | p->end_lineno = end_lineno; |
| 1462 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1463 | return p; |
| 1464 | } |
| 1465 | |
| 1466 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1467 | 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] | 1468 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1469 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1470 | stmt_ty p; |
| 1471 | if (!test) { |
| 1472 | PyErr_SetString(PyExc_ValueError, |
| 1473 | "field test is required for While"); |
| 1474 | return NULL; |
| 1475 | } |
| 1476 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1477 | if (!p) |
| 1478 | return NULL; |
| 1479 | p->kind = While_kind; |
| 1480 | p->v.While.test = test; |
| 1481 | p->v.While.body = body; |
| 1482 | p->v.While.orelse = orelse; |
| 1483 | p->lineno = lineno; |
| 1484 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1485 | p->end_lineno = end_lineno; |
| 1486 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1487 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1488 | } |
| 1489 | |
| 1490 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1491 | 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] | 1492 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1493 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1494 | stmt_ty p; |
| 1495 | if (!test) { |
| 1496 | PyErr_SetString(PyExc_ValueError, |
| 1497 | "field test is required for If"); |
| 1498 | return NULL; |
| 1499 | } |
| 1500 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1501 | if (!p) |
| 1502 | return NULL; |
| 1503 | p->kind = If_kind; |
| 1504 | p->v.If.test = test; |
| 1505 | p->v.If.body = body; |
| 1506 | p->v.If.orelse = orelse; |
| 1507 | p->lineno = lineno; |
| 1508 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1509 | p->end_lineno = end_lineno; |
| 1510 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1511 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1515 | With(asdl_seq * items, asdl_seq * body, int lineno, int col_offset, int |
| 1516 | end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1517 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1518 | stmt_ty p; |
| 1519 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1520 | if (!p) |
| 1521 | return NULL; |
| 1522 | p->kind = With_kind; |
| 1523 | p->v.With.items = items; |
| 1524 | p->v.With.body = body; |
| 1525 | p->lineno = lineno; |
| 1526 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1527 | p->end_lineno = end_lineno; |
| 1528 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1529 | return p; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1530 | } |
| 1531 | |
| 1532 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1533 | AsyncWith(asdl_seq * items, asdl_seq * body, int lineno, int col_offset, int |
| 1534 | end_lineno, int end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1535 | { |
| 1536 | stmt_ty p; |
| 1537 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1538 | if (!p) |
| 1539 | return NULL; |
| 1540 | p->kind = AsyncWith_kind; |
| 1541 | p->v.AsyncWith.items = items; |
| 1542 | p->v.AsyncWith.body = body; |
| 1543 | p->lineno = lineno; |
| 1544 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1545 | p->end_lineno = end_lineno; |
| 1546 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1547 | return p; |
| 1548 | } |
| 1549 | |
| 1550 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1551 | Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno, |
| 1552 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1553 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1554 | stmt_ty p; |
| 1555 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1556 | if (!p) |
| 1557 | return NULL; |
| 1558 | p->kind = Raise_kind; |
| 1559 | p->v.Raise.exc = exc; |
| 1560 | p->v.Raise.cause = cause; |
| 1561 | p->lineno = lineno; |
| 1562 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1563 | p->end_lineno = end_lineno; |
| 1564 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1565 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1566 | } |
| 1567 | |
| 1568 | stmt_ty |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 1569 | Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1570 | finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 1571 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1572 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1573 | stmt_ty p; |
| 1574 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1575 | if (!p) |
| 1576 | return NULL; |
| 1577 | p->kind = Try_kind; |
| 1578 | p->v.Try.body = body; |
| 1579 | p->v.Try.handlers = handlers; |
| 1580 | p->v.Try.orelse = orelse; |
| 1581 | p->v.Try.finalbody = finalbody; |
| 1582 | p->lineno = lineno; |
| 1583 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1584 | p->end_lineno = end_lineno; |
| 1585 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1586 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1590 | Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno, |
| 1591 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1592 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1593 | stmt_ty p; |
| 1594 | if (!test) { |
| 1595 | PyErr_SetString(PyExc_ValueError, |
| 1596 | "field test is required for Assert"); |
| 1597 | return NULL; |
| 1598 | } |
| 1599 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1600 | if (!p) |
| 1601 | return NULL; |
| 1602 | p->kind = Assert_kind; |
| 1603 | p->v.Assert.test = test; |
| 1604 | p->v.Assert.msg = msg; |
| 1605 | p->lineno = lineno; |
| 1606 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1607 | p->end_lineno = end_lineno; |
| 1608 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1609 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1610 | } |
| 1611 | |
| 1612 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1613 | Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 1614 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1615 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1616 | stmt_ty p; |
| 1617 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1618 | if (!p) |
| 1619 | return NULL; |
| 1620 | p->kind = Import_kind; |
| 1621 | p->v.Import.names = names; |
| 1622 | p->lineno = lineno; |
| 1623 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1624 | p->end_lineno = end_lineno; |
| 1625 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1626 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1627 | } |
| 1628 | |
| 1629 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1630 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1631 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1632 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1633 | stmt_ty p; |
| 1634 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1635 | if (!p) |
| 1636 | return NULL; |
| 1637 | p->kind = ImportFrom_kind; |
| 1638 | p->v.ImportFrom.module = module; |
| 1639 | p->v.ImportFrom.names = names; |
| 1640 | p->v.ImportFrom.level = level; |
| 1641 | p->lineno = lineno; |
| 1642 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1643 | p->end_lineno = end_lineno; |
| 1644 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1645 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1646 | } |
| 1647 | |
| 1648 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1649 | Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 1650 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1651 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1652 | stmt_ty p; |
| 1653 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1654 | if (!p) |
| 1655 | return NULL; |
| 1656 | p->kind = Global_kind; |
| 1657 | p->v.Global.names = names; |
| 1658 | p->lineno = lineno; |
| 1659 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1660 | p->end_lineno = end_lineno; |
| 1661 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1662 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1666 | Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 1667 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 1668 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1669 | stmt_ty p; |
| 1670 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1671 | if (!p) |
| 1672 | return NULL; |
| 1673 | p->kind = Nonlocal_kind; |
| 1674 | p->v.Nonlocal.names = names; |
| 1675 | p->lineno = lineno; |
| 1676 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1677 | p->end_lineno = end_lineno; |
| 1678 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1679 | return p; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 1680 | } |
| 1681 | |
| 1682 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1683 | Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 1684 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1685 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1686 | stmt_ty p; |
| 1687 | if (!value) { |
| 1688 | PyErr_SetString(PyExc_ValueError, |
| 1689 | "field value is required for Expr"); |
| 1690 | return NULL; |
| 1691 | } |
| 1692 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1693 | if (!p) |
| 1694 | return NULL; |
| 1695 | p->kind = Expr_kind; |
| 1696 | p->v.Expr.value = value; |
| 1697 | p->lineno = lineno; |
| 1698 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1699 | p->end_lineno = end_lineno; |
| 1700 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1701 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1702 | } |
| 1703 | |
| 1704 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1705 | Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 1706 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1707 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1708 | stmt_ty p; |
| 1709 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1710 | if (!p) |
| 1711 | return NULL; |
| 1712 | p->kind = Pass_kind; |
| 1713 | p->lineno = lineno; |
| 1714 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1715 | p->end_lineno = end_lineno; |
| 1716 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1717 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1718 | } |
| 1719 | |
| 1720 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1721 | Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 1722 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1723 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1724 | stmt_ty p; |
| 1725 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1726 | if (!p) |
| 1727 | return NULL; |
| 1728 | p->kind = Break_kind; |
| 1729 | p->lineno = lineno; |
| 1730 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1731 | p->end_lineno = end_lineno; |
| 1732 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1733 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1737 | Continue(int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 1738 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1739 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1740 | stmt_ty p; |
| 1741 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1742 | if (!p) |
| 1743 | return NULL; |
| 1744 | p->kind = Continue_kind; |
| 1745 | p->lineno = lineno; |
| 1746 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1747 | p->end_lineno = end_lineno; |
| 1748 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1749 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1753 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int |
| 1754 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1755 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1756 | expr_ty p; |
| 1757 | if (!op) { |
| 1758 | PyErr_SetString(PyExc_ValueError, |
| 1759 | "field op is required for BoolOp"); |
| 1760 | return NULL; |
| 1761 | } |
| 1762 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1763 | if (!p) |
| 1764 | return NULL; |
| 1765 | p->kind = BoolOp_kind; |
| 1766 | p->v.BoolOp.op = op; |
| 1767 | p->v.BoolOp.values = values; |
| 1768 | p->lineno = lineno; |
| 1769 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1770 | p->end_lineno = end_lineno; |
| 1771 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1772 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1773 | } |
| 1774 | |
| 1775 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1776 | 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] | 1777 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1778 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1779 | expr_ty p; |
| 1780 | if (!left) { |
| 1781 | PyErr_SetString(PyExc_ValueError, |
| 1782 | "field left is required for BinOp"); |
| 1783 | return NULL; |
| 1784 | } |
| 1785 | if (!op) { |
| 1786 | PyErr_SetString(PyExc_ValueError, |
| 1787 | "field op is required for BinOp"); |
| 1788 | return NULL; |
| 1789 | } |
| 1790 | if (!right) { |
| 1791 | PyErr_SetString(PyExc_ValueError, |
| 1792 | "field right is required for BinOp"); |
| 1793 | return NULL; |
| 1794 | } |
| 1795 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1796 | if (!p) |
| 1797 | return NULL; |
| 1798 | p->kind = BinOp_kind; |
| 1799 | p->v.BinOp.left = left; |
| 1800 | p->v.BinOp.op = op; |
| 1801 | p->v.BinOp.right = right; |
| 1802 | p->lineno = lineno; |
| 1803 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1804 | p->end_lineno = end_lineno; |
| 1805 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1806 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1810 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int |
| 1811 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1812 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1813 | expr_ty p; |
| 1814 | if (!op) { |
| 1815 | PyErr_SetString(PyExc_ValueError, |
| 1816 | "field op is required for UnaryOp"); |
| 1817 | return NULL; |
| 1818 | } |
| 1819 | if (!operand) { |
| 1820 | PyErr_SetString(PyExc_ValueError, |
| 1821 | "field operand is required for UnaryOp"); |
| 1822 | return NULL; |
| 1823 | } |
| 1824 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1825 | if (!p) |
| 1826 | return NULL; |
| 1827 | p->kind = UnaryOp_kind; |
| 1828 | p->v.UnaryOp.op = op; |
| 1829 | p->v.UnaryOp.operand = operand; |
| 1830 | p->lineno = lineno; |
| 1831 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1832 | p->end_lineno = end_lineno; |
| 1833 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1834 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1835 | } |
| 1836 | |
| 1837 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1838 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int |
| 1839 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1840 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1841 | expr_ty p; |
| 1842 | if (!args) { |
| 1843 | PyErr_SetString(PyExc_ValueError, |
| 1844 | "field args is required for Lambda"); |
| 1845 | return NULL; |
| 1846 | } |
| 1847 | if (!body) { |
| 1848 | PyErr_SetString(PyExc_ValueError, |
| 1849 | "field body is required for Lambda"); |
| 1850 | return NULL; |
| 1851 | } |
| 1852 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1853 | if (!p) |
| 1854 | return NULL; |
| 1855 | p->kind = Lambda_kind; |
| 1856 | p->v.Lambda.args = args; |
| 1857 | p->v.Lambda.body = body; |
| 1858 | p->lineno = lineno; |
| 1859 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1860 | p->end_lineno = end_lineno; |
| 1861 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1862 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1863 | } |
| 1864 | |
| 1865 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1866 | 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] | 1867 | int end_lineno, int end_col_offset, PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1868 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1869 | expr_ty p; |
| 1870 | if (!test) { |
| 1871 | PyErr_SetString(PyExc_ValueError, |
| 1872 | "field test is required for IfExp"); |
| 1873 | return NULL; |
| 1874 | } |
| 1875 | if (!body) { |
| 1876 | PyErr_SetString(PyExc_ValueError, |
| 1877 | "field body is required for IfExp"); |
| 1878 | return NULL; |
| 1879 | } |
| 1880 | if (!orelse) { |
| 1881 | PyErr_SetString(PyExc_ValueError, |
| 1882 | "field orelse is required for IfExp"); |
| 1883 | return NULL; |
| 1884 | } |
| 1885 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1886 | if (!p) |
| 1887 | return NULL; |
| 1888 | p->kind = IfExp_kind; |
| 1889 | p->v.IfExp.test = test; |
| 1890 | p->v.IfExp.body = body; |
| 1891 | p->v.IfExp.orelse = orelse; |
| 1892 | p->lineno = lineno; |
| 1893 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1894 | p->end_lineno = end_lineno; |
| 1895 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1896 | return p; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1897 | } |
| 1898 | |
| 1899 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1900 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int |
| 1901 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1902 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1903 | expr_ty p; |
| 1904 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1905 | if (!p) |
| 1906 | return NULL; |
| 1907 | p->kind = Dict_kind; |
| 1908 | p->v.Dict.keys = keys; |
| 1909 | p->v.Dict.values = values; |
| 1910 | p->lineno = lineno; |
| 1911 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1912 | p->end_lineno = end_lineno; |
| 1913 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1914 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1915 | } |
| 1916 | |
| 1917 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1918 | Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int |
| 1919 | end_col_offset, PyArena *arena) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1920 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1921 | expr_ty p; |
| 1922 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1923 | if (!p) |
| 1924 | return NULL; |
| 1925 | p->kind = Set_kind; |
| 1926 | p->v.Set.elts = elts; |
| 1927 | p->lineno = lineno; |
| 1928 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1929 | p->end_lineno = end_lineno; |
| 1930 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1931 | return p; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1932 | } |
| 1933 | |
| 1934 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1935 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 1936 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1937 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1938 | expr_ty p; |
| 1939 | if (!elt) { |
| 1940 | PyErr_SetString(PyExc_ValueError, |
| 1941 | "field elt is required for ListComp"); |
| 1942 | return NULL; |
| 1943 | } |
| 1944 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1945 | if (!p) |
| 1946 | return NULL; |
| 1947 | p->kind = ListComp_kind; |
| 1948 | p->v.ListComp.elt = elt; |
| 1949 | p->v.ListComp.generators = generators; |
| 1950 | p->lineno = lineno; |
| 1951 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1952 | p->end_lineno = end_lineno; |
| 1953 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1954 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1955 | } |
| 1956 | |
| 1957 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1958 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 1959 | end_lineno, int end_col_offset, PyArena *arena) |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 1960 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1961 | expr_ty p; |
| 1962 | if (!elt) { |
| 1963 | PyErr_SetString(PyExc_ValueError, |
| 1964 | "field elt is required for SetComp"); |
| 1965 | return NULL; |
| 1966 | } |
| 1967 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1968 | if (!p) |
| 1969 | return NULL; |
| 1970 | p->kind = SetComp_kind; |
| 1971 | p->v.SetComp.elt = elt; |
| 1972 | p->v.SetComp.generators = generators; |
| 1973 | p->lineno = lineno; |
| 1974 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1975 | p->end_lineno = end_lineno; |
| 1976 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1977 | return p; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 1978 | } |
| 1979 | |
| 1980 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 1981 | 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] | 1982 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 1983 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1984 | expr_ty p; |
| 1985 | if (!key) { |
| 1986 | PyErr_SetString(PyExc_ValueError, |
| 1987 | "field key is required for DictComp"); |
| 1988 | return NULL; |
| 1989 | } |
| 1990 | if (!value) { |
| 1991 | PyErr_SetString(PyExc_ValueError, |
| 1992 | "field value is required for DictComp"); |
| 1993 | return NULL; |
| 1994 | } |
| 1995 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1996 | if (!p) |
| 1997 | return NULL; |
| 1998 | p->kind = DictComp_kind; |
| 1999 | p->v.DictComp.key = key; |
| 2000 | p->v.DictComp.value = value; |
| 2001 | p->v.DictComp.generators = generators; |
| 2002 | p->lineno = lineno; |
| 2003 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2004 | p->end_lineno = end_lineno; |
| 2005 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2006 | return p; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2010 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2011 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2012 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2013 | expr_ty p; |
| 2014 | if (!elt) { |
| 2015 | PyErr_SetString(PyExc_ValueError, |
| 2016 | "field elt is required for GeneratorExp"); |
| 2017 | return NULL; |
| 2018 | } |
| 2019 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2020 | if (!p) |
| 2021 | return NULL; |
| 2022 | p->kind = GeneratorExp_kind; |
| 2023 | p->v.GeneratorExp.elt = elt; |
| 2024 | p->v.GeneratorExp.generators = generators; |
| 2025 | p->lineno = lineno; |
| 2026 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2027 | p->end_lineno = end_lineno; |
| 2028 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2029 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2030 | } |
| 2031 | |
| 2032 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2033 | Await(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2034 | end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2035 | { |
| 2036 | expr_ty p; |
| 2037 | if (!value) { |
| 2038 | PyErr_SetString(PyExc_ValueError, |
| 2039 | "field value is required for Await"); |
| 2040 | return NULL; |
| 2041 | } |
| 2042 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2043 | if (!p) |
| 2044 | return NULL; |
| 2045 | p->kind = Await_kind; |
| 2046 | p->v.Await.value = value; |
| 2047 | p->lineno = lineno; |
| 2048 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2049 | p->end_lineno = end_lineno; |
| 2050 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2051 | return p; |
| 2052 | } |
| 2053 | |
| 2054 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2055 | Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2056 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2057 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2058 | expr_ty p; |
| 2059 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2060 | if (!p) |
| 2061 | return NULL; |
| 2062 | p->kind = Yield_kind; |
| 2063 | p->v.Yield.value = value; |
| 2064 | p->lineno = lineno; |
| 2065 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2066 | p->end_lineno = end_lineno; |
| 2067 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2068 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2069 | } |
| 2070 | |
| 2071 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2072 | YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2073 | end_col_offset, PyArena *arena) |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2074 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2075 | expr_ty p; |
| 2076 | if (!value) { |
| 2077 | PyErr_SetString(PyExc_ValueError, |
| 2078 | "field value is required for YieldFrom"); |
| 2079 | return NULL; |
| 2080 | } |
| 2081 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2082 | if (!p) |
| 2083 | return NULL; |
| 2084 | p->kind = YieldFrom_kind; |
| 2085 | p->v.YieldFrom.value = value; |
| 2086 | p->lineno = lineno; |
| 2087 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2088 | p->end_lineno = end_lineno; |
| 2089 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2090 | return p; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2091 | } |
| 2092 | |
| 2093 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2094 | 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] | 2095 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2096 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2097 | expr_ty p; |
| 2098 | if (!left) { |
| 2099 | PyErr_SetString(PyExc_ValueError, |
| 2100 | "field left is required for Compare"); |
| 2101 | return NULL; |
| 2102 | } |
| 2103 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2104 | if (!p) |
| 2105 | return NULL; |
| 2106 | p->kind = Compare_kind; |
| 2107 | p->v.Compare.left = left; |
| 2108 | p->v.Compare.ops = ops; |
| 2109 | p->v.Compare.comparators = comparators; |
| 2110 | p->lineno = lineno; |
| 2111 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2112 | p->end_lineno = end_lineno; |
| 2113 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2114 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2115 | } |
| 2116 | |
| 2117 | expr_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 2118 | 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] | 2119 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2120 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2121 | expr_ty p; |
| 2122 | if (!func) { |
| 2123 | PyErr_SetString(PyExc_ValueError, |
| 2124 | "field func is required for Call"); |
| 2125 | return NULL; |
| 2126 | } |
| 2127 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2128 | if (!p) |
| 2129 | return NULL; |
| 2130 | p->kind = Call_kind; |
| 2131 | p->v.Call.func = func; |
| 2132 | p->v.Call.args = args; |
| 2133 | p->v.Call.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2134 | p->lineno = lineno; |
| 2135 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2136 | p->end_lineno = end_lineno; |
| 2137 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2138 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2139 | } |
| 2140 | |
| 2141 | expr_ty |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2142 | FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2143 | int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2144 | *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2145 | { |
| 2146 | expr_ty p; |
| 2147 | if (!value) { |
| 2148 | PyErr_SetString(PyExc_ValueError, |
| 2149 | "field value is required for FormattedValue"); |
| 2150 | return NULL; |
| 2151 | } |
| 2152 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2153 | if (!p) |
| 2154 | return NULL; |
| 2155 | p->kind = FormattedValue_kind; |
| 2156 | p->v.FormattedValue.value = value; |
| 2157 | p->v.FormattedValue.conversion = conversion; |
| 2158 | p->v.FormattedValue.format_spec = format_spec; |
| 2159 | p->lineno = lineno; |
| 2160 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2161 | p->end_lineno = end_lineno; |
| 2162 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2163 | return p; |
| 2164 | } |
| 2165 | |
| 2166 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2167 | JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int |
| 2168 | end_col_offset, PyArena *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2169 | { |
| 2170 | expr_ty p; |
| 2171 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2172 | if (!p) |
| 2173 | return NULL; |
| 2174 | p->kind = JoinedStr_kind; |
| 2175 | p->v.JoinedStr.values = values; |
| 2176 | p->lineno = lineno; |
| 2177 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2178 | p->end_lineno = end_lineno; |
| 2179 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2180 | return p; |
| 2181 | } |
| 2182 | |
| 2183 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2184 | Constant(constant value, int lineno, int col_offset, int end_lineno, int |
| 2185 | end_col_offset, PyArena *arena) |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 2186 | { |
| 2187 | expr_ty p; |
| 2188 | if (!value) { |
| 2189 | PyErr_SetString(PyExc_ValueError, |
| 2190 | "field value is required for Constant"); |
| 2191 | return NULL; |
| 2192 | } |
| 2193 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2194 | if (!p) |
| 2195 | return NULL; |
| 2196 | p->kind = Constant_kind; |
| 2197 | p->v.Constant.value = value; |
| 2198 | p->lineno = lineno; |
| 2199 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2200 | p->end_lineno = end_lineno; |
| 2201 | p->end_col_offset = end_col_offset; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 2202 | return p; |
| 2203 | } |
| 2204 | |
| 2205 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2206 | 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] | 2207 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2208 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2209 | expr_ty p; |
| 2210 | if (!value) { |
| 2211 | PyErr_SetString(PyExc_ValueError, |
| 2212 | "field value is required for Attribute"); |
| 2213 | return NULL; |
| 2214 | } |
| 2215 | if (!attr) { |
| 2216 | PyErr_SetString(PyExc_ValueError, |
| 2217 | "field attr is required for Attribute"); |
| 2218 | return NULL; |
| 2219 | } |
| 2220 | if (!ctx) { |
| 2221 | PyErr_SetString(PyExc_ValueError, |
| 2222 | "field ctx is required for Attribute"); |
| 2223 | return NULL; |
| 2224 | } |
| 2225 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2226 | if (!p) |
| 2227 | return NULL; |
| 2228 | p->kind = Attribute_kind; |
| 2229 | p->v.Attribute.value = value; |
| 2230 | p->v.Attribute.attr = attr; |
| 2231 | p->v.Attribute.ctx = ctx; |
| 2232 | p->lineno = lineno; |
| 2233 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2234 | p->end_lineno = end_lineno; |
| 2235 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2236 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2237 | } |
| 2238 | |
| 2239 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2240 | 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] | 2241 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2242 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2243 | expr_ty p; |
| 2244 | if (!value) { |
| 2245 | PyErr_SetString(PyExc_ValueError, |
| 2246 | "field value is required for Subscript"); |
| 2247 | return NULL; |
| 2248 | } |
| 2249 | if (!slice) { |
| 2250 | PyErr_SetString(PyExc_ValueError, |
| 2251 | "field slice is required for Subscript"); |
| 2252 | return NULL; |
| 2253 | } |
| 2254 | if (!ctx) { |
| 2255 | PyErr_SetString(PyExc_ValueError, |
| 2256 | "field ctx is required for Subscript"); |
| 2257 | return NULL; |
| 2258 | } |
| 2259 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2260 | if (!p) |
| 2261 | return NULL; |
| 2262 | p->kind = Subscript_kind; |
| 2263 | p->v.Subscript.value = value; |
| 2264 | p->v.Subscript.slice = slice; |
| 2265 | p->v.Subscript.ctx = ctx; |
| 2266 | p->lineno = lineno; |
| 2267 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2268 | p->end_lineno = end_lineno; |
| 2269 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2270 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2271 | } |
| 2272 | |
| 2273 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2274 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int |
| 2275 | end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2276 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2277 | expr_ty p; |
| 2278 | if (!value) { |
| 2279 | PyErr_SetString(PyExc_ValueError, |
| 2280 | "field value is required for Starred"); |
| 2281 | return NULL; |
| 2282 | } |
| 2283 | if (!ctx) { |
| 2284 | PyErr_SetString(PyExc_ValueError, |
| 2285 | "field ctx is required for Starred"); |
| 2286 | return NULL; |
| 2287 | } |
| 2288 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2289 | if (!p) |
| 2290 | return NULL; |
| 2291 | p->kind = Starred_kind; |
| 2292 | p->v.Starred.value = value; |
| 2293 | p->v.Starred.ctx = ctx; |
| 2294 | p->lineno = lineno; |
| 2295 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2296 | p->end_lineno = end_lineno; |
| 2297 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2298 | return p; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2299 | } |
| 2300 | |
| 2301 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2302 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int |
| 2303 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2304 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2305 | expr_ty p; |
| 2306 | if (!id) { |
| 2307 | PyErr_SetString(PyExc_ValueError, |
| 2308 | "field id is required for Name"); |
| 2309 | return NULL; |
| 2310 | } |
| 2311 | if (!ctx) { |
| 2312 | PyErr_SetString(PyExc_ValueError, |
| 2313 | "field ctx is required for Name"); |
| 2314 | return NULL; |
| 2315 | } |
| 2316 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2317 | if (!p) |
| 2318 | return NULL; |
| 2319 | p->kind = Name_kind; |
| 2320 | p->v.Name.id = id; |
| 2321 | p->v.Name.ctx = ctx; |
| 2322 | p->lineno = lineno; |
| 2323 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2324 | p->end_lineno = end_lineno; |
| 2325 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2326 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2327 | } |
| 2328 | |
| 2329 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2330 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 2331 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2332 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2333 | expr_ty p; |
| 2334 | if (!ctx) { |
| 2335 | PyErr_SetString(PyExc_ValueError, |
| 2336 | "field ctx is required for List"); |
| 2337 | return NULL; |
| 2338 | } |
| 2339 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2340 | if (!p) |
| 2341 | return NULL; |
| 2342 | p->kind = List_kind; |
| 2343 | p->v.List.elts = elts; |
| 2344 | p->v.List.ctx = ctx; |
| 2345 | p->lineno = lineno; |
| 2346 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2347 | p->end_lineno = end_lineno; |
| 2348 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2349 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2350 | } |
| 2351 | |
| 2352 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2353 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 2354 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2355 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2356 | expr_ty p; |
| 2357 | if (!ctx) { |
| 2358 | PyErr_SetString(PyExc_ValueError, |
| 2359 | "field ctx is required for Tuple"); |
| 2360 | return NULL; |
| 2361 | } |
| 2362 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2363 | if (!p) |
| 2364 | return NULL; |
| 2365 | p->kind = Tuple_kind; |
| 2366 | p->v.Tuple.elts = elts; |
| 2367 | p->v.Tuple.ctx = ctx; |
| 2368 | p->lineno = lineno; |
| 2369 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2370 | p->end_lineno = end_lineno; |
| 2371 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2372 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2373 | } |
| 2374 | |
| 2375 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2376 | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2377 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2378 | slice_ty p; |
| 2379 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2380 | if (!p) |
| 2381 | return NULL; |
| 2382 | p->kind = Slice_kind; |
| 2383 | p->v.Slice.lower = lower; |
| 2384 | p->v.Slice.upper = upper; |
| 2385 | p->v.Slice.step = step; |
| 2386 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2387 | } |
| 2388 | |
| 2389 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2390 | ExtSlice(asdl_seq * dims, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2391 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2392 | slice_ty p; |
| 2393 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2394 | if (!p) |
| 2395 | return NULL; |
| 2396 | p->kind = ExtSlice_kind; |
| 2397 | p->v.ExtSlice.dims = dims; |
| 2398 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2399 | } |
| 2400 | |
| 2401 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2402 | Index(expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2403 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2404 | slice_ty p; |
| 2405 | if (!value) { |
| 2406 | PyErr_SetString(PyExc_ValueError, |
| 2407 | "field value is required for Index"); |
| 2408 | return NULL; |
| 2409 | } |
| 2410 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2411 | if (!p) |
| 2412 | return NULL; |
| 2413 | p->kind = Index_kind; |
| 2414 | p->v.Index.value = value; |
| 2415 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2416 | } |
| 2417 | |
| 2418 | comprehension_ty |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 2419 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async, |
| 2420 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2421 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2422 | comprehension_ty p; |
| 2423 | if (!target) { |
| 2424 | PyErr_SetString(PyExc_ValueError, |
| 2425 | "field target is required for comprehension"); |
| 2426 | return NULL; |
| 2427 | } |
| 2428 | if (!iter) { |
| 2429 | PyErr_SetString(PyExc_ValueError, |
| 2430 | "field iter is required for comprehension"); |
| 2431 | return NULL; |
| 2432 | } |
| 2433 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2434 | if (!p) |
| 2435 | return NULL; |
| 2436 | p->target = target; |
| 2437 | p->iter = iter; |
| 2438 | p->ifs = ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 2439 | p->is_async = is_async; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2440 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2441 | } |
| 2442 | |
| 2443 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 2444 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2445 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2446 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2447 | excepthandler_ty p; |
| 2448 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2449 | if (!p) |
| 2450 | return NULL; |
| 2451 | p->kind = ExceptHandler_kind; |
| 2452 | p->v.ExceptHandler.type = type; |
| 2453 | p->v.ExceptHandler.name = name; |
| 2454 | p->v.ExceptHandler.body = body; |
| 2455 | p->lineno = lineno; |
| 2456 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2457 | p->end_lineno = end_lineno; |
| 2458 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2459 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2460 | } |
| 2461 | |
| 2462 | arguments_ty |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 2463 | arguments(asdl_seq * args, arg_ty vararg, asdl_seq * kwonlyargs, asdl_seq * |
| 2464 | kw_defaults, arg_ty kwarg, asdl_seq * defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2465 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2466 | arguments_ty p; |
| 2467 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2468 | if (!p) |
| 2469 | return NULL; |
| 2470 | p->args = args; |
| 2471 | p->vararg = vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2472 | p->kwonlyargs = kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2473 | p->kw_defaults = kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 2474 | p->kwarg = kwarg; |
| 2475 | p->defaults = defaults; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2476 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2477 | } |
| 2478 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2479 | arg_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2480 | arg(identifier arg, expr_ty annotation, int lineno, int col_offset, int |
| 2481 | end_lineno, int end_col_offset, PyArena *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2482 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2483 | arg_ty p; |
| 2484 | if (!arg) { |
| 2485 | PyErr_SetString(PyExc_ValueError, |
| 2486 | "field arg is required for arg"); |
| 2487 | return NULL; |
| 2488 | } |
| 2489 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2490 | if (!p) |
| 2491 | return NULL; |
| 2492 | p->arg = arg; |
| 2493 | p->annotation = annotation; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 2494 | p->lineno = lineno; |
| 2495 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2496 | p->end_lineno = end_lineno; |
| 2497 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2498 | return p; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2499 | } |
| 2500 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2501 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2502 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2503 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2504 | keyword_ty p; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2505 | if (!value) { |
| 2506 | PyErr_SetString(PyExc_ValueError, |
| 2507 | "field value is required for keyword"); |
| 2508 | return NULL; |
| 2509 | } |
| 2510 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2511 | if (!p) |
| 2512 | return NULL; |
| 2513 | p->arg = arg; |
| 2514 | p->value = value; |
| 2515 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2516 | } |
| 2517 | |
| 2518 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2519 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2520 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2521 | alias_ty p; |
| 2522 | if (!name) { |
| 2523 | PyErr_SetString(PyExc_ValueError, |
| 2524 | "field name is required for alias"); |
| 2525 | return NULL; |
| 2526 | } |
| 2527 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2528 | if (!p) |
| 2529 | return NULL; |
| 2530 | p->name = name; |
| 2531 | p->asname = asname; |
| 2532 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2533 | } |
| 2534 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2535 | withitem_ty |
| 2536 | withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) |
| 2537 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2538 | withitem_ty p; |
| 2539 | if (!context_expr) { |
| 2540 | PyErr_SetString(PyExc_ValueError, |
| 2541 | "field context_expr is required for withitem"); |
| 2542 | return NULL; |
| 2543 | } |
| 2544 | p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2545 | if (!p) |
| 2546 | return NULL; |
| 2547 | p->context_expr = context_expr; |
| 2548 | p->optional_vars = optional_vars; |
| 2549 | return p; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2550 | } |
| 2551 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2552 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2553 | PyObject* |
| 2554 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2555 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2556 | mod_ty o = (mod_ty)_o; |
| 2557 | PyObject *result = NULL, *value = NULL; |
| 2558 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 2559 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2560 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2561 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2562 | switch (o->kind) { |
| 2563 | case Module_kind: |
| 2564 | result = PyType_GenericNew(Module_type, NULL, NULL); |
| 2565 | if (!result) goto failed; |
| 2566 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 2567 | if (!value) goto failed; |
| 2568 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2569 | goto failed; |
| 2570 | Py_DECREF(value); |
| 2571 | break; |
| 2572 | case Interactive_kind: |
| 2573 | result = PyType_GenericNew(Interactive_type, NULL, NULL); |
| 2574 | if (!result) goto failed; |
| 2575 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 2576 | if (!value) goto failed; |
| 2577 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2578 | goto failed; |
| 2579 | Py_DECREF(value); |
| 2580 | break; |
| 2581 | case Expression_kind: |
| 2582 | result = PyType_GenericNew(Expression_type, NULL, NULL); |
| 2583 | if (!result) goto failed; |
| 2584 | value = ast2obj_expr(o->v.Expression.body); |
| 2585 | if (!value) goto failed; |
| 2586 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2587 | goto failed; |
| 2588 | Py_DECREF(value); |
| 2589 | break; |
| 2590 | case Suite_kind: |
| 2591 | result = PyType_GenericNew(Suite_type, NULL, NULL); |
| 2592 | if (!result) goto failed; |
| 2593 | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
| 2594 | if (!value) goto failed; |
| 2595 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2596 | goto failed; |
| 2597 | Py_DECREF(value); |
| 2598 | break; |
| 2599 | } |
| 2600 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2601 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2602 | Py_XDECREF(value); |
| 2603 | Py_XDECREF(result); |
| 2604 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2605 | } |
| 2606 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2607 | PyObject* |
| 2608 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2609 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2610 | stmt_ty o = (stmt_ty)_o; |
| 2611 | PyObject *result = NULL, *value = NULL; |
| 2612 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 2613 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2614 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2615 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2616 | switch (o->kind) { |
| 2617 | case FunctionDef_kind: |
| 2618 | result = PyType_GenericNew(FunctionDef_type, NULL, NULL); |
| 2619 | if (!result) goto failed; |
| 2620 | value = ast2obj_identifier(o->v.FunctionDef.name); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2621 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2622 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2623 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2624 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2625 | value = ast2obj_arguments(o->v.FunctionDef.args); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2626 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2627 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 2628 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2629 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2630 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 2631 | if (!value) goto failed; |
| 2632 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2633 | goto failed; |
| 2634 | Py_DECREF(value); |
| 2635 | value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr); |
| 2636 | if (!value) goto failed; |
| 2637 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2638 | goto failed; |
| 2639 | Py_DECREF(value); |
| 2640 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 2641 | if (!value) goto failed; |
| 2642 | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
| 2643 | goto failed; |
| 2644 | Py_DECREF(value); |
| 2645 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2646 | case AsyncFunctionDef_kind: |
| 2647 | result = PyType_GenericNew(AsyncFunctionDef_type, NULL, NULL); |
| 2648 | if (!result) goto failed; |
| 2649 | value = ast2obj_identifier(o->v.AsyncFunctionDef.name); |
| 2650 | if (!value) goto failed; |
| 2651 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2652 | goto failed; |
| 2653 | Py_DECREF(value); |
| 2654 | value = ast2obj_arguments(o->v.AsyncFunctionDef.args); |
| 2655 | if (!value) goto failed; |
| 2656 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 2657 | goto failed; |
| 2658 | Py_DECREF(value); |
| 2659 | value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt); |
| 2660 | if (!value) goto failed; |
| 2661 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2662 | goto failed; |
| 2663 | Py_DECREF(value); |
| 2664 | value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list, |
| 2665 | ast2obj_expr); |
| 2666 | if (!value) goto failed; |
| 2667 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2668 | goto failed; |
| 2669 | Py_DECREF(value); |
| 2670 | value = ast2obj_expr(o->v.AsyncFunctionDef.returns); |
| 2671 | if (!value) goto failed; |
| 2672 | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
| 2673 | goto failed; |
| 2674 | Py_DECREF(value); |
| 2675 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2676 | case ClassDef_kind: |
| 2677 | result = PyType_GenericNew(ClassDef_type, NULL, NULL); |
| 2678 | if (!result) goto failed; |
| 2679 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 2680 | if (!value) goto failed; |
| 2681 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2682 | goto failed; |
| 2683 | Py_DECREF(value); |
| 2684 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 2685 | if (!value) goto failed; |
| 2686 | if (_PyObject_SetAttrId(result, &PyId_bases, value) == -1) |
| 2687 | goto failed; |
| 2688 | Py_DECREF(value); |
| 2689 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 2690 | if (!value) goto failed; |
| 2691 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
| 2692 | goto failed; |
| 2693 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2694 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 2695 | if (!value) goto failed; |
| 2696 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2697 | goto failed; |
| 2698 | Py_DECREF(value); |
| 2699 | value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr); |
| 2700 | if (!value) goto failed; |
| 2701 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2702 | goto failed; |
| 2703 | Py_DECREF(value); |
| 2704 | break; |
| 2705 | case Return_kind: |
| 2706 | result = PyType_GenericNew(Return_type, NULL, NULL); |
| 2707 | if (!result) goto failed; |
| 2708 | value = ast2obj_expr(o->v.Return.value); |
| 2709 | if (!value) goto failed; |
| 2710 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2711 | goto failed; |
| 2712 | Py_DECREF(value); |
| 2713 | break; |
| 2714 | case Delete_kind: |
| 2715 | result = PyType_GenericNew(Delete_type, NULL, NULL); |
| 2716 | if (!result) goto failed; |
| 2717 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 2718 | if (!value) goto failed; |
| 2719 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
| 2720 | goto failed; |
| 2721 | Py_DECREF(value); |
| 2722 | break; |
| 2723 | case Assign_kind: |
| 2724 | result = PyType_GenericNew(Assign_type, NULL, NULL); |
| 2725 | if (!result) goto failed; |
| 2726 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 2727 | if (!value) goto failed; |
| 2728 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
| 2729 | goto failed; |
| 2730 | Py_DECREF(value); |
| 2731 | value = ast2obj_expr(o->v.Assign.value); |
| 2732 | if (!value) goto failed; |
| 2733 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2734 | goto failed; |
| 2735 | Py_DECREF(value); |
| 2736 | break; |
| 2737 | case AugAssign_kind: |
| 2738 | result = PyType_GenericNew(AugAssign_type, NULL, NULL); |
| 2739 | if (!result) goto failed; |
| 2740 | value = ast2obj_expr(o->v.AugAssign.target); |
| 2741 | if (!value) goto failed; |
| 2742 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2743 | goto failed; |
| 2744 | Py_DECREF(value); |
| 2745 | value = ast2obj_operator(o->v.AugAssign.op); |
| 2746 | if (!value) goto failed; |
| 2747 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 2748 | goto failed; |
| 2749 | Py_DECREF(value); |
| 2750 | value = ast2obj_expr(o->v.AugAssign.value); |
| 2751 | if (!value) goto failed; |
| 2752 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2753 | goto failed; |
| 2754 | Py_DECREF(value); |
| 2755 | break; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2756 | case AnnAssign_kind: |
| 2757 | result = PyType_GenericNew(AnnAssign_type, NULL, NULL); |
| 2758 | if (!result) goto failed; |
| 2759 | value = ast2obj_expr(o->v.AnnAssign.target); |
| 2760 | if (!value) goto failed; |
| 2761 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2762 | goto failed; |
| 2763 | Py_DECREF(value); |
| 2764 | value = ast2obj_expr(o->v.AnnAssign.annotation); |
| 2765 | if (!value) goto failed; |
| 2766 | if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) |
| 2767 | goto failed; |
| 2768 | Py_DECREF(value); |
| 2769 | value = ast2obj_expr(o->v.AnnAssign.value); |
| 2770 | if (!value) goto failed; |
| 2771 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2772 | goto failed; |
| 2773 | Py_DECREF(value); |
| 2774 | value = ast2obj_int(o->v.AnnAssign.simple); |
| 2775 | if (!value) goto failed; |
| 2776 | if (_PyObject_SetAttrId(result, &PyId_simple, value) == -1) |
| 2777 | goto failed; |
| 2778 | Py_DECREF(value); |
| 2779 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2780 | case For_kind: |
| 2781 | result = PyType_GenericNew(For_type, NULL, NULL); |
| 2782 | if (!result) goto failed; |
| 2783 | value = ast2obj_expr(o->v.For.target); |
| 2784 | if (!value) goto failed; |
| 2785 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2786 | goto failed; |
| 2787 | Py_DECREF(value); |
| 2788 | value = ast2obj_expr(o->v.For.iter); |
| 2789 | if (!value) goto failed; |
| 2790 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 2791 | goto failed; |
| 2792 | Py_DECREF(value); |
| 2793 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 2794 | if (!value) goto failed; |
| 2795 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2796 | goto failed; |
| 2797 | Py_DECREF(value); |
| 2798 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 2799 | if (!value) goto failed; |
| 2800 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2801 | goto failed; |
| 2802 | Py_DECREF(value); |
| 2803 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2804 | case AsyncFor_kind: |
| 2805 | result = PyType_GenericNew(AsyncFor_type, NULL, NULL); |
| 2806 | if (!result) goto failed; |
| 2807 | value = ast2obj_expr(o->v.AsyncFor.target); |
| 2808 | if (!value) goto failed; |
| 2809 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2810 | goto failed; |
| 2811 | Py_DECREF(value); |
| 2812 | value = ast2obj_expr(o->v.AsyncFor.iter); |
| 2813 | if (!value) goto failed; |
| 2814 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 2815 | goto failed; |
| 2816 | Py_DECREF(value); |
| 2817 | value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt); |
| 2818 | if (!value) goto failed; |
| 2819 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2820 | goto failed; |
| 2821 | Py_DECREF(value); |
| 2822 | value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt); |
| 2823 | if (!value) goto failed; |
| 2824 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2825 | goto failed; |
| 2826 | Py_DECREF(value); |
| 2827 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2828 | case While_kind: |
| 2829 | result = PyType_GenericNew(While_type, NULL, NULL); |
| 2830 | if (!result) goto failed; |
| 2831 | value = ast2obj_expr(o->v.While.test); |
| 2832 | if (!value) goto failed; |
| 2833 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 2834 | goto failed; |
| 2835 | Py_DECREF(value); |
| 2836 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 2837 | if (!value) goto failed; |
| 2838 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2839 | goto failed; |
| 2840 | Py_DECREF(value); |
| 2841 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 2842 | if (!value) goto failed; |
| 2843 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2844 | goto failed; |
| 2845 | Py_DECREF(value); |
| 2846 | break; |
| 2847 | case If_kind: |
| 2848 | result = PyType_GenericNew(If_type, NULL, NULL); |
| 2849 | if (!result) goto failed; |
| 2850 | value = ast2obj_expr(o->v.If.test); |
| 2851 | if (!value) goto failed; |
| 2852 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 2853 | goto failed; |
| 2854 | Py_DECREF(value); |
| 2855 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 2856 | if (!value) goto failed; |
| 2857 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2858 | goto failed; |
| 2859 | Py_DECREF(value); |
| 2860 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 2861 | if (!value) goto failed; |
| 2862 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2863 | goto failed; |
| 2864 | Py_DECREF(value); |
| 2865 | break; |
| 2866 | case With_kind: |
| 2867 | result = PyType_GenericNew(With_type, NULL, NULL); |
| 2868 | if (!result) goto failed; |
| 2869 | value = ast2obj_list(o->v.With.items, ast2obj_withitem); |
| 2870 | if (!value) goto failed; |
| 2871 | if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) |
| 2872 | goto failed; |
| 2873 | Py_DECREF(value); |
| 2874 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 2875 | if (!value) goto failed; |
| 2876 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2877 | goto failed; |
| 2878 | Py_DECREF(value); |
| 2879 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2880 | case AsyncWith_kind: |
| 2881 | result = PyType_GenericNew(AsyncWith_type, NULL, NULL); |
| 2882 | if (!result) goto failed; |
| 2883 | value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem); |
| 2884 | if (!value) goto failed; |
| 2885 | if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) |
| 2886 | goto failed; |
| 2887 | Py_DECREF(value); |
| 2888 | value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt); |
| 2889 | if (!value) goto failed; |
| 2890 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2891 | goto failed; |
| 2892 | Py_DECREF(value); |
| 2893 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2894 | case Raise_kind: |
| 2895 | result = PyType_GenericNew(Raise_type, NULL, NULL); |
| 2896 | if (!result) goto failed; |
| 2897 | value = ast2obj_expr(o->v.Raise.exc); |
| 2898 | if (!value) goto failed; |
| 2899 | if (_PyObject_SetAttrId(result, &PyId_exc, value) == -1) |
| 2900 | goto failed; |
| 2901 | Py_DECREF(value); |
| 2902 | value = ast2obj_expr(o->v.Raise.cause); |
| 2903 | if (!value) goto failed; |
| 2904 | if (_PyObject_SetAttrId(result, &PyId_cause, value) == -1) |
| 2905 | goto failed; |
| 2906 | Py_DECREF(value); |
| 2907 | break; |
| 2908 | case Try_kind: |
| 2909 | result = PyType_GenericNew(Try_type, NULL, NULL); |
| 2910 | if (!result) goto failed; |
| 2911 | value = ast2obj_list(o->v.Try.body, ast2obj_stmt); |
| 2912 | if (!value) goto failed; |
| 2913 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2914 | goto failed; |
| 2915 | Py_DECREF(value); |
| 2916 | value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); |
| 2917 | if (!value) goto failed; |
| 2918 | if (_PyObject_SetAttrId(result, &PyId_handlers, value) == -1) |
| 2919 | goto failed; |
| 2920 | Py_DECREF(value); |
| 2921 | value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); |
| 2922 | if (!value) goto failed; |
| 2923 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2924 | goto failed; |
| 2925 | Py_DECREF(value); |
| 2926 | value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); |
| 2927 | if (!value) goto failed; |
| 2928 | if (_PyObject_SetAttrId(result, &PyId_finalbody, value) == -1) |
| 2929 | goto failed; |
| 2930 | Py_DECREF(value); |
| 2931 | break; |
| 2932 | case Assert_kind: |
| 2933 | result = PyType_GenericNew(Assert_type, NULL, NULL); |
| 2934 | if (!result) goto failed; |
| 2935 | value = ast2obj_expr(o->v.Assert.test); |
| 2936 | if (!value) goto failed; |
| 2937 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 2938 | goto failed; |
| 2939 | Py_DECREF(value); |
| 2940 | value = ast2obj_expr(o->v.Assert.msg); |
| 2941 | if (!value) goto failed; |
| 2942 | if (_PyObject_SetAttrId(result, &PyId_msg, value) == -1) |
| 2943 | goto failed; |
| 2944 | Py_DECREF(value); |
| 2945 | break; |
| 2946 | case Import_kind: |
| 2947 | result = PyType_GenericNew(Import_type, NULL, NULL); |
| 2948 | if (!result) goto failed; |
| 2949 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 2950 | if (!value) goto failed; |
| 2951 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 2952 | goto failed; |
| 2953 | Py_DECREF(value); |
| 2954 | break; |
| 2955 | case ImportFrom_kind: |
| 2956 | result = PyType_GenericNew(ImportFrom_type, NULL, NULL); |
| 2957 | if (!result) goto failed; |
| 2958 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 2959 | if (!value) goto failed; |
| 2960 | if (_PyObject_SetAttrId(result, &PyId_module, value) == -1) |
| 2961 | goto failed; |
| 2962 | Py_DECREF(value); |
| 2963 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 2964 | if (!value) goto failed; |
| 2965 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 2966 | goto failed; |
| 2967 | Py_DECREF(value); |
| 2968 | value = ast2obj_int(o->v.ImportFrom.level); |
| 2969 | if (!value) goto failed; |
| 2970 | if (_PyObject_SetAttrId(result, &PyId_level, value) == -1) |
| 2971 | goto failed; |
| 2972 | Py_DECREF(value); |
| 2973 | break; |
| 2974 | case Global_kind: |
| 2975 | result = PyType_GenericNew(Global_type, NULL, NULL); |
| 2976 | if (!result) goto failed; |
| 2977 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 2978 | if (!value) goto failed; |
| 2979 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 2980 | goto failed; |
| 2981 | Py_DECREF(value); |
| 2982 | break; |
| 2983 | case Nonlocal_kind: |
| 2984 | result = PyType_GenericNew(Nonlocal_type, NULL, NULL); |
| 2985 | if (!result) goto failed; |
| 2986 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 2987 | if (!value) goto failed; |
| 2988 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 2989 | goto failed; |
| 2990 | Py_DECREF(value); |
| 2991 | break; |
| 2992 | case Expr_kind: |
| 2993 | result = PyType_GenericNew(Expr_type, NULL, NULL); |
| 2994 | if (!result) goto failed; |
| 2995 | value = ast2obj_expr(o->v.Expr.value); |
| 2996 | if (!value) goto failed; |
| 2997 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2998 | goto failed; |
| 2999 | Py_DECREF(value); |
| 3000 | break; |
| 3001 | case Pass_kind: |
| 3002 | result = PyType_GenericNew(Pass_type, NULL, NULL); |
| 3003 | if (!result) goto failed; |
| 3004 | break; |
| 3005 | case Break_kind: |
| 3006 | result = PyType_GenericNew(Break_type, NULL, NULL); |
| 3007 | if (!result) goto failed; |
| 3008 | break; |
| 3009 | case Continue_kind: |
| 3010 | result = PyType_GenericNew(Continue_type, NULL, NULL); |
| 3011 | if (!result) goto failed; |
| 3012 | break; |
| 3013 | } |
| 3014 | value = ast2obj_int(o->lineno); |
| 3015 | if (!value) goto failed; |
| 3016 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3017 | goto failed; |
| 3018 | Py_DECREF(value); |
| 3019 | value = ast2obj_int(o->col_offset); |
| 3020 | if (!value) goto failed; |
| 3021 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3022 | goto failed; |
| 3023 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3024 | value = ast2obj_int(o->end_lineno); |
| 3025 | if (!value) goto failed; |
| 3026 | if (_PyObject_SetAttrId(result, &PyId_end_lineno, value) < 0) |
| 3027 | goto failed; |
| 3028 | Py_DECREF(value); |
| 3029 | value = ast2obj_int(o->end_col_offset); |
| 3030 | if (!value) goto failed; |
| 3031 | if (_PyObject_SetAttrId(result, &PyId_end_col_offset, value) < 0) |
| 3032 | goto failed; |
| 3033 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3034 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3035 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3036 | Py_XDECREF(value); |
| 3037 | Py_XDECREF(result); |
| 3038 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3039 | } |
| 3040 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3041 | PyObject* |
| 3042 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3043 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3044 | expr_ty o = (expr_ty)_o; |
| 3045 | PyObject *result = NULL, *value = NULL; |
| 3046 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3047 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3048 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3049 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3050 | switch (o->kind) { |
| 3051 | case BoolOp_kind: |
| 3052 | result = PyType_GenericNew(BoolOp_type, NULL, NULL); |
| 3053 | if (!result) goto failed; |
| 3054 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 3055 | if (!value) goto failed; |
| 3056 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 3057 | goto failed; |
| 3058 | Py_DECREF(value); |
| 3059 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 3060 | if (!value) goto failed; |
| 3061 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 3062 | goto failed; |
| 3063 | Py_DECREF(value); |
| 3064 | break; |
| 3065 | case BinOp_kind: |
| 3066 | result = PyType_GenericNew(BinOp_type, NULL, NULL); |
| 3067 | if (!result) goto failed; |
| 3068 | value = ast2obj_expr(o->v.BinOp.left); |
| 3069 | if (!value) goto failed; |
| 3070 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
| 3071 | goto failed; |
| 3072 | Py_DECREF(value); |
| 3073 | value = ast2obj_operator(o->v.BinOp.op); |
| 3074 | if (!value) goto failed; |
| 3075 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 3076 | goto failed; |
| 3077 | Py_DECREF(value); |
| 3078 | value = ast2obj_expr(o->v.BinOp.right); |
| 3079 | if (!value) goto failed; |
| 3080 | if (_PyObject_SetAttrId(result, &PyId_right, value) == -1) |
| 3081 | goto failed; |
| 3082 | Py_DECREF(value); |
| 3083 | break; |
| 3084 | case UnaryOp_kind: |
| 3085 | result = PyType_GenericNew(UnaryOp_type, NULL, NULL); |
| 3086 | if (!result) goto failed; |
| 3087 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 3088 | if (!value) goto failed; |
| 3089 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 3090 | goto failed; |
| 3091 | Py_DECREF(value); |
| 3092 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 3093 | if (!value) goto failed; |
| 3094 | if (_PyObject_SetAttrId(result, &PyId_operand, value) == -1) |
| 3095 | goto failed; |
| 3096 | Py_DECREF(value); |
| 3097 | break; |
| 3098 | case Lambda_kind: |
| 3099 | result = PyType_GenericNew(Lambda_type, NULL, NULL); |
| 3100 | if (!result) goto failed; |
| 3101 | value = ast2obj_arguments(o->v.Lambda.args); |
| 3102 | if (!value) goto failed; |
| 3103 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3104 | goto failed; |
| 3105 | Py_DECREF(value); |
| 3106 | value = ast2obj_expr(o->v.Lambda.body); |
| 3107 | if (!value) goto failed; |
| 3108 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3109 | goto failed; |
| 3110 | Py_DECREF(value); |
| 3111 | break; |
| 3112 | case IfExp_kind: |
| 3113 | result = PyType_GenericNew(IfExp_type, NULL, NULL); |
| 3114 | if (!result) goto failed; |
| 3115 | value = ast2obj_expr(o->v.IfExp.test); |
| 3116 | if (!value) goto failed; |
| 3117 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 3118 | goto failed; |
| 3119 | Py_DECREF(value); |
| 3120 | value = ast2obj_expr(o->v.IfExp.body); |
| 3121 | if (!value) goto failed; |
| 3122 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3123 | goto failed; |
| 3124 | Py_DECREF(value); |
| 3125 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 3126 | if (!value) goto failed; |
| 3127 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 3128 | goto failed; |
| 3129 | Py_DECREF(value); |
| 3130 | break; |
| 3131 | case Dict_kind: |
| 3132 | result = PyType_GenericNew(Dict_type, NULL, NULL); |
| 3133 | if (!result) goto failed; |
| 3134 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 3135 | if (!value) goto failed; |
| 3136 | if (_PyObject_SetAttrId(result, &PyId_keys, value) == -1) |
| 3137 | goto failed; |
| 3138 | Py_DECREF(value); |
| 3139 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 3140 | if (!value) goto failed; |
| 3141 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 3142 | goto failed; |
| 3143 | Py_DECREF(value); |
| 3144 | break; |
| 3145 | case Set_kind: |
| 3146 | result = PyType_GenericNew(Set_type, NULL, NULL); |
| 3147 | if (!result) goto failed; |
| 3148 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 3149 | if (!value) goto failed; |
| 3150 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3151 | goto failed; |
| 3152 | Py_DECREF(value); |
| 3153 | break; |
| 3154 | case ListComp_kind: |
| 3155 | result = PyType_GenericNew(ListComp_type, NULL, NULL); |
| 3156 | if (!result) goto failed; |
| 3157 | value = ast2obj_expr(o->v.ListComp.elt); |
| 3158 | if (!value) goto failed; |
| 3159 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 3160 | goto failed; |
| 3161 | Py_DECREF(value); |
| 3162 | value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension); |
| 3163 | if (!value) goto failed; |
| 3164 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3165 | goto failed; |
| 3166 | Py_DECREF(value); |
| 3167 | break; |
| 3168 | case SetComp_kind: |
| 3169 | result = PyType_GenericNew(SetComp_type, NULL, NULL); |
| 3170 | if (!result) goto failed; |
| 3171 | value = ast2obj_expr(o->v.SetComp.elt); |
| 3172 | if (!value) goto failed; |
| 3173 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 3174 | goto failed; |
| 3175 | Py_DECREF(value); |
| 3176 | value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension); |
| 3177 | if (!value) goto failed; |
| 3178 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3179 | goto failed; |
| 3180 | Py_DECREF(value); |
| 3181 | break; |
| 3182 | case DictComp_kind: |
| 3183 | result = PyType_GenericNew(DictComp_type, NULL, NULL); |
| 3184 | if (!result) goto failed; |
| 3185 | value = ast2obj_expr(o->v.DictComp.key); |
| 3186 | if (!value) goto failed; |
| 3187 | if (_PyObject_SetAttrId(result, &PyId_key, value) == -1) |
| 3188 | goto failed; |
| 3189 | Py_DECREF(value); |
| 3190 | value = ast2obj_expr(o->v.DictComp.value); |
| 3191 | if (!value) goto failed; |
| 3192 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3193 | goto failed; |
| 3194 | Py_DECREF(value); |
| 3195 | value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension); |
| 3196 | if (!value) goto failed; |
| 3197 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3198 | goto failed; |
| 3199 | Py_DECREF(value); |
| 3200 | break; |
| 3201 | case GeneratorExp_kind: |
| 3202 | result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); |
| 3203 | if (!result) goto failed; |
| 3204 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 3205 | if (!value) goto failed; |
| 3206 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 3207 | goto failed; |
| 3208 | Py_DECREF(value); |
| 3209 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 3210 | ast2obj_comprehension); |
| 3211 | if (!value) goto failed; |
| 3212 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3213 | goto failed; |
| 3214 | Py_DECREF(value); |
| 3215 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3216 | case Await_kind: |
| 3217 | result = PyType_GenericNew(Await_type, NULL, NULL); |
| 3218 | if (!result) goto failed; |
| 3219 | value = ast2obj_expr(o->v.Await.value); |
| 3220 | if (!value) goto failed; |
| 3221 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3222 | goto failed; |
| 3223 | Py_DECREF(value); |
| 3224 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3225 | case Yield_kind: |
| 3226 | result = PyType_GenericNew(Yield_type, NULL, NULL); |
| 3227 | if (!result) goto failed; |
| 3228 | value = ast2obj_expr(o->v.Yield.value); |
| 3229 | if (!value) goto failed; |
| 3230 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3231 | goto failed; |
| 3232 | Py_DECREF(value); |
| 3233 | break; |
| 3234 | case YieldFrom_kind: |
| 3235 | result = PyType_GenericNew(YieldFrom_type, NULL, NULL); |
| 3236 | if (!result) goto failed; |
| 3237 | value = ast2obj_expr(o->v.YieldFrom.value); |
| 3238 | if (!value) goto failed; |
| 3239 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3240 | goto failed; |
| 3241 | Py_DECREF(value); |
| 3242 | break; |
| 3243 | case Compare_kind: |
| 3244 | result = PyType_GenericNew(Compare_type, NULL, NULL); |
| 3245 | if (!result) goto failed; |
| 3246 | value = ast2obj_expr(o->v.Compare.left); |
| 3247 | if (!value) goto failed; |
| 3248 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
| 3249 | goto failed; |
| 3250 | Py_DECREF(value); |
| 3251 | { |
| 3252 | Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 3253 | value = PyList_New(n); |
| 3254 | if (!value) goto failed; |
| 3255 | for(i = 0; i < n; i++) |
| 3256 | 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] | 3257 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 3258 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3259 | if (_PyObject_SetAttrId(result, &PyId_ops, value) == -1) |
| 3260 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3261 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3262 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3263 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3264 | if (_PyObject_SetAttrId(result, &PyId_comparators, value) == -1) |
| 3265 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3266 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3267 | break; |
| 3268 | case Call_kind: |
| 3269 | result = PyType_GenericNew(Call_type, NULL, NULL); |
| 3270 | if (!result) goto failed; |
| 3271 | value = ast2obj_expr(o->v.Call.func); |
| 3272 | if (!value) goto failed; |
| 3273 | if (_PyObject_SetAttrId(result, &PyId_func, value) == -1) |
| 3274 | goto failed; |
| 3275 | Py_DECREF(value); |
| 3276 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 3277 | if (!value) goto failed; |
| 3278 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3279 | goto failed; |
| 3280 | Py_DECREF(value); |
| 3281 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 3282 | if (!value) goto failed; |
| 3283 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
| 3284 | goto failed; |
| 3285 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3286 | break; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3287 | case FormattedValue_kind: |
| 3288 | result = PyType_GenericNew(FormattedValue_type, NULL, NULL); |
| 3289 | if (!result) goto failed; |
| 3290 | value = ast2obj_expr(o->v.FormattedValue.value); |
| 3291 | if (!value) goto failed; |
| 3292 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3293 | goto failed; |
| 3294 | Py_DECREF(value); |
| 3295 | value = ast2obj_int(o->v.FormattedValue.conversion); |
| 3296 | if (!value) goto failed; |
| 3297 | if (_PyObject_SetAttrId(result, &PyId_conversion, value) == -1) |
| 3298 | goto failed; |
| 3299 | Py_DECREF(value); |
| 3300 | value = ast2obj_expr(o->v.FormattedValue.format_spec); |
| 3301 | if (!value) goto failed; |
| 3302 | if (_PyObject_SetAttrId(result, &PyId_format_spec, value) == -1) |
| 3303 | goto failed; |
| 3304 | Py_DECREF(value); |
| 3305 | break; |
| 3306 | case JoinedStr_kind: |
| 3307 | result = PyType_GenericNew(JoinedStr_type, NULL, NULL); |
| 3308 | if (!result) goto failed; |
| 3309 | value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr); |
| 3310 | if (!value) goto failed; |
| 3311 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 3312 | goto failed; |
| 3313 | Py_DECREF(value); |
| 3314 | break; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3315 | case Constant_kind: |
| 3316 | result = PyType_GenericNew(Constant_type, NULL, NULL); |
| 3317 | if (!result) goto failed; |
| 3318 | value = ast2obj_constant(o->v.Constant.value); |
| 3319 | if (!value) goto failed; |
| 3320 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3321 | goto failed; |
| 3322 | Py_DECREF(value); |
| 3323 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3324 | case Attribute_kind: |
| 3325 | result = PyType_GenericNew(Attribute_type, NULL, NULL); |
| 3326 | if (!result) goto failed; |
| 3327 | value = ast2obj_expr(o->v.Attribute.value); |
| 3328 | if (!value) goto failed; |
| 3329 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3330 | goto failed; |
| 3331 | Py_DECREF(value); |
| 3332 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 3333 | if (!value) goto failed; |
| 3334 | if (_PyObject_SetAttrId(result, &PyId_attr, value) == -1) |
| 3335 | goto failed; |
| 3336 | Py_DECREF(value); |
| 3337 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 3338 | if (!value) goto failed; |
| 3339 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3340 | goto failed; |
| 3341 | Py_DECREF(value); |
| 3342 | break; |
| 3343 | case Subscript_kind: |
| 3344 | result = PyType_GenericNew(Subscript_type, NULL, NULL); |
| 3345 | if (!result) goto failed; |
| 3346 | value = ast2obj_expr(o->v.Subscript.value); |
| 3347 | if (!value) goto failed; |
| 3348 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3349 | goto failed; |
| 3350 | Py_DECREF(value); |
| 3351 | value = ast2obj_slice(o->v.Subscript.slice); |
| 3352 | if (!value) goto failed; |
| 3353 | if (_PyObject_SetAttrId(result, &PyId_slice, value) == -1) |
| 3354 | goto failed; |
| 3355 | Py_DECREF(value); |
| 3356 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 3357 | if (!value) goto failed; |
| 3358 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3359 | goto failed; |
| 3360 | Py_DECREF(value); |
| 3361 | break; |
| 3362 | case Starred_kind: |
| 3363 | result = PyType_GenericNew(Starred_type, NULL, NULL); |
| 3364 | if (!result) goto failed; |
| 3365 | value = ast2obj_expr(o->v.Starred.value); |
| 3366 | if (!value) goto failed; |
| 3367 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3368 | goto failed; |
| 3369 | Py_DECREF(value); |
| 3370 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 3371 | if (!value) goto failed; |
| 3372 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3373 | goto failed; |
| 3374 | Py_DECREF(value); |
| 3375 | break; |
| 3376 | case Name_kind: |
| 3377 | result = PyType_GenericNew(Name_type, NULL, NULL); |
| 3378 | if (!result) goto failed; |
| 3379 | value = ast2obj_identifier(o->v.Name.id); |
| 3380 | if (!value) goto failed; |
| 3381 | if (_PyObject_SetAttrId(result, &PyId_id, value) == -1) |
| 3382 | goto failed; |
| 3383 | Py_DECREF(value); |
| 3384 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 3385 | if (!value) goto failed; |
| 3386 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3387 | goto failed; |
| 3388 | Py_DECREF(value); |
| 3389 | break; |
| 3390 | case List_kind: |
| 3391 | result = PyType_GenericNew(List_type, NULL, NULL); |
| 3392 | if (!result) goto failed; |
| 3393 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 3394 | if (!value) goto failed; |
| 3395 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3396 | goto failed; |
| 3397 | Py_DECREF(value); |
| 3398 | value = ast2obj_expr_context(o->v.List.ctx); |
| 3399 | if (!value) goto failed; |
| 3400 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3401 | goto failed; |
| 3402 | Py_DECREF(value); |
| 3403 | break; |
| 3404 | case Tuple_kind: |
| 3405 | result = PyType_GenericNew(Tuple_type, NULL, NULL); |
| 3406 | if (!result) goto failed; |
| 3407 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 3408 | if (!value) goto failed; |
| 3409 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3410 | goto failed; |
| 3411 | Py_DECREF(value); |
| 3412 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 3413 | if (!value) goto failed; |
| 3414 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3415 | goto failed; |
| 3416 | Py_DECREF(value); |
| 3417 | break; |
| 3418 | } |
| 3419 | value = ast2obj_int(o->lineno); |
| 3420 | if (!value) goto failed; |
| 3421 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3422 | goto failed; |
| 3423 | Py_DECREF(value); |
| 3424 | value = ast2obj_int(o->col_offset); |
| 3425 | if (!value) goto failed; |
| 3426 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3427 | goto failed; |
| 3428 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3429 | value = ast2obj_int(o->end_lineno); |
| 3430 | if (!value) goto failed; |
| 3431 | if (_PyObject_SetAttrId(result, &PyId_end_lineno, value) < 0) |
| 3432 | goto failed; |
| 3433 | Py_DECREF(value); |
| 3434 | value = ast2obj_int(o->end_col_offset); |
| 3435 | if (!value) goto failed; |
| 3436 | if (_PyObject_SetAttrId(result, &PyId_end_col_offset, value) < 0) |
| 3437 | goto failed; |
| 3438 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3439 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3440 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3441 | Py_XDECREF(value); |
| 3442 | Py_XDECREF(result); |
| 3443 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3444 | } |
| 3445 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3446 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3447 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3448 | switch(o) { |
| 3449 | case Load: |
| 3450 | Py_INCREF(Load_singleton); |
| 3451 | return Load_singleton; |
| 3452 | case Store: |
| 3453 | Py_INCREF(Store_singleton); |
| 3454 | return Store_singleton; |
| 3455 | case Del: |
| 3456 | Py_INCREF(Del_singleton); |
| 3457 | return Del_singleton; |
| 3458 | case AugLoad: |
| 3459 | Py_INCREF(AugLoad_singleton); |
| 3460 | return AugLoad_singleton; |
| 3461 | case AugStore: |
| 3462 | Py_INCREF(AugStore_singleton); |
| 3463 | return AugStore_singleton; |
| 3464 | case Param: |
| 3465 | Py_INCREF(Param_singleton); |
| 3466 | return Param_singleton; |
| 3467 | default: |
| 3468 | /* should never happen, but just in case ... */ |
| 3469 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 3470 | return NULL; |
| 3471 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3472 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3473 | PyObject* |
| 3474 | ast2obj_slice(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3475 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3476 | slice_ty o = (slice_ty)_o; |
| 3477 | PyObject *result = NULL, *value = NULL; |
| 3478 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3479 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3480 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3481 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3482 | switch (o->kind) { |
| 3483 | case Slice_kind: |
| 3484 | result = PyType_GenericNew(Slice_type, NULL, NULL); |
| 3485 | if (!result) goto failed; |
| 3486 | value = ast2obj_expr(o->v.Slice.lower); |
| 3487 | if (!value) goto failed; |
| 3488 | if (_PyObject_SetAttrId(result, &PyId_lower, value) == -1) |
| 3489 | goto failed; |
| 3490 | Py_DECREF(value); |
| 3491 | value = ast2obj_expr(o->v.Slice.upper); |
| 3492 | if (!value) goto failed; |
| 3493 | if (_PyObject_SetAttrId(result, &PyId_upper, value) == -1) |
| 3494 | goto failed; |
| 3495 | Py_DECREF(value); |
| 3496 | value = ast2obj_expr(o->v.Slice.step); |
| 3497 | if (!value) goto failed; |
| 3498 | if (_PyObject_SetAttrId(result, &PyId_step, value) == -1) |
| 3499 | goto failed; |
| 3500 | Py_DECREF(value); |
| 3501 | break; |
| 3502 | case ExtSlice_kind: |
| 3503 | result = PyType_GenericNew(ExtSlice_type, NULL, NULL); |
| 3504 | if (!result) goto failed; |
| 3505 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 3506 | if (!value) goto failed; |
| 3507 | if (_PyObject_SetAttrId(result, &PyId_dims, value) == -1) |
| 3508 | goto failed; |
| 3509 | Py_DECREF(value); |
| 3510 | break; |
| 3511 | case Index_kind: |
| 3512 | result = PyType_GenericNew(Index_type, NULL, NULL); |
| 3513 | if (!result) goto failed; |
| 3514 | value = ast2obj_expr(o->v.Index.value); |
| 3515 | if (!value) goto failed; |
| 3516 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3517 | goto failed; |
| 3518 | Py_DECREF(value); |
| 3519 | break; |
| 3520 | } |
| 3521 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3522 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3523 | Py_XDECREF(value); |
| 3524 | Py_XDECREF(result); |
| 3525 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3526 | } |
| 3527 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3528 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3529 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3530 | switch(o) { |
| 3531 | case And: |
| 3532 | Py_INCREF(And_singleton); |
| 3533 | return And_singleton; |
| 3534 | case Or: |
| 3535 | Py_INCREF(Or_singleton); |
| 3536 | return Or_singleton; |
| 3537 | default: |
| 3538 | /* should never happen, but just in case ... */ |
| 3539 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 3540 | return NULL; |
| 3541 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3542 | } |
| 3543 | PyObject* ast2obj_operator(operator_ty o) |
| 3544 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3545 | switch(o) { |
| 3546 | case Add: |
| 3547 | Py_INCREF(Add_singleton); |
| 3548 | return Add_singleton; |
| 3549 | case Sub: |
| 3550 | Py_INCREF(Sub_singleton); |
| 3551 | return Sub_singleton; |
| 3552 | case Mult: |
| 3553 | Py_INCREF(Mult_singleton); |
| 3554 | return Mult_singleton; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 3555 | case MatMult: |
| 3556 | Py_INCREF(MatMult_singleton); |
| 3557 | return MatMult_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3558 | case Div: |
| 3559 | Py_INCREF(Div_singleton); |
| 3560 | return Div_singleton; |
| 3561 | case Mod: |
| 3562 | Py_INCREF(Mod_singleton); |
| 3563 | return Mod_singleton; |
| 3564 | case Pow: |
| 3565 | Py_INCREF(Pow_singleton); |
| 3566 | return Pow_singleton; |
| 3567 | case LShift: |
| 3568 | Py_INCREF(LShift_singleton); |
| 3569 | return LShift_singleton; |
| 3570 | case RShift: |
| 3571 | Py_INCREF(RShift_singleton); |
| 3572 | return RShift_singleton; |
| 3573 | case BitOr: |
| 3574 | Py_INCREF(BitOr_singleton); |
| 3575 | return BitOr_singleton; |
| 3576 | case BitXor: |
| 3577 | Py_INCREF(BitXor_singleton); |
| 3578 | return BitXor_singleton; |
| 3579 | case BitAnd: |
| 3580 | Py_INCREF(BitAnd_singleton); |
| 3581 | return BitAnd_singleton; |
| 3582 | case FloorDiv: |
| 3583 | Py_INCREF(FloorDiv_singleton); |
| 3584 | return FloorDiv_singleton; |
| 3585 | default: |
| 3586 | /* should never happen, but just in case ... */ |
| 3587 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 3588 | return NULL; |
| 3589 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3590 | } |
| 3591 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 3592 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3593 | switch(o) { |
| 3594 | case Invert: |
| 3595 | Py_INCREF(Invert_singleton); |
| 3596 | return Invert_singleton; |
| 3597 | case Not: |
| 3598 | Py_INCREF(Not_singleton); |
| 3599 | return Not_singleton; |
| 3600 | case UAdd: |
| 3601 | Py_INCREF(UAdd_singleton); |
| 3602 | return UAdd_singleton; |
| 3603 | case USub: |
| 3604 | Py_INCREF(USub_singleton); |
| 3605 | return USub_singleton; |
| 3606 | default: |
| 3607 | /* should never happen, but just in case ... */ |
| 3608 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 3609 | return NULL; |
| 3610 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3611 | } |
| 3612 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 3613 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3614 | switch(o) { |
| 3615 | case Eq: |
| 3616 | Py_INCREF(Eq_singleton); |
| 3617 | return Eq_singleton; |
| 3618 | case NotEq: |
| 3619 | Py_INCREF(NotEq_singleton); |
| 3620 | return NotEq_singleton; |
| 3621 | case Lt: |
| 3622 | Py_INCREF(Lt_singleton); |
| 3623 | return Lt_singleton; |
| 3624 | case LtE: |
| 3625 | Py_INCREF(LtE_singleton); |
| 3626 | return LtE_singleton; |
| 3627 | case Gt: |
| 3628 | Py_INCREF(Gt_singleton); |
| 3629 | return Gt_singleton; |
| 3630 | case GtE: |
| 3631 | Py_INCREF(GtE_singleton); |
| 3632 | return GtE_singleton; |
| 3633 | case Is: |
| 3634 | Py_INCREF(Is_singleton); |
| 3635 | return Is_singleton; |
| 3636 | case IsNot: |
| 3637 | Py_INCREF(IsNot_singleton); |
| 3638 | return IsNot_singleton; |
| 3639 | case In: |
| 3640 | Py_INCREF(In_singleton); |
| 3641 | return In_singleton; |
| 3642 | case NotIn: |
| 3643 | Py_INCREF(NotIn_singleton); |
| 3644 | return NotIn_singleton; |
| 3645 | default: |
| 3646 | /* should never happen, but just in case ... */ |
| 3647 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 3648 | return NULL; |
| 3649 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3650 | } |
| 3651 | PyObject* |
| 3652 | ast2obj_comprehension(void* _o) |
| 3653 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3654 | comprehension_ty o = (comprehension_ty)_o; |
| 3655 | PyObject *result = NULL, *value = NULL; |
| 3656 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3657 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3658 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3659 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3660 | result = PyType_GenericNew(comprehension_type, NULL, NULL); |
| 3661 | if (!result) return NULL; |
| 3662 | value = ast2obj_expr(o->target); |
| 3663 | if (!value) goto failed; |
| 3664 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 3665 | goto failed; |
| 3666 | Py_DECREF(value); |
| 3667 | value = ast2obj_expr(o->iter); |
| 3668 | if (!value) goto failed; |
| 3669 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 3670 | goto failed; |
| 3671 | Py_DECREF(value); |
| 3672 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 3673 | if (!value) goto failed; |
| 3674 | if (_PyObject_SetAttrId(result, &PyId_ifs, value) == -1) |
| 3675 | goto failed; |
| 3676 | Py_DECREF(value); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 3677 | value = ast2obj_int(o->is_async); |
| 3678 | if (!value) goto failed; |
| 3679 | if (_PyObject_SetAttrId(result, &PyId_is_async, value) == -1) |
| 3680 | goto failed; |
| 3681 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3682 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3683 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3684 | Py_XDECREF(value); |
| 3685 | Py_XDECREF(result); |
| 3686 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3687 | } |
| 3688 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3689 | PyObject* |
| 3690 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3691 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3692 | excepthandler_ty o = (excepthandler_ty)_o; |
| 3693 | PyObject *result = NULL, *value = NULL; |
| 3694 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3695 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3696 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3697 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3698 | switch (o->kind) { |
| 3699 | case ExceptHandler_kind: |
| 3700 | result = PyType_GenericNew(ExceptHandler_type, NULL, NULL); |
| 3701 | if (!result) goto failed; |
| 3702 | value = ast2obj_expr(o->v.ExceptHandler.type); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3703 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3704 | if (_PyObject_SetAttrId(result, &PyId_type, value) == -1) |
| 3705 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3706 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3707 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3708 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3709 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 3710 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3711 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3712 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 3713 | if (!value) goto failed; |
| 3714 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3715 | goto failed; |
| 3716 | Py_DECREF(value); |
| 3717 | break; |
| 3718 | } |
| 3719 | value = ast2obj_int(o->lineno); |
| 3720 | if (!value) goto failed; |
| 3721 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3722 | goto failed; |
| 3723 | Py_DECREF(value); |
| 3724 | value = ast2obj_int(o->col_offset); |
| 3725 | if (!value) goto failed; |
| 3726 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3727 | goto failed; |
| 3728 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3729 | value = ast2obj_int(o->end_lineno); |
| 3730 | if (!value) goto failed; |
| 3731 | if (_PyObject_SetAttrId(result, &PyId_end_lineno, value) < 0) |
| 3732 | goto failed; |
| 3733 | Py_DECREF(value); |
| 3734 | value = ast2obj_int(o->end_col_offset); |
| 3735 | if (!value) goto failed; |
| 3736 | if (_PyObject_SetAttrId(result, &PyId_end_col_offset, value) < 0) |
| 3737 | goto failed; |
| 3738 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3739 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3740 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3741 | Py_XDECREF(value); |
| 3742 | Py_XDECREF(result); |
| 3743 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3744 | } |
| 3745 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3746 | PyObject* |
| 3747 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3748 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3749 | arguments_ty o = (arguments_ty)_o; |
| 3750 | PyObject *result = NULL, *value = NULL; |
| 3751 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3752 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3753 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3754 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3755 | result = PyType_GenericNew(arguments_type, NULL, NULL); |
| 3756 | if (!result) return NULL; |
| 3757 | value = ast2obj_list(o->args, ast2obj_arg); |
| 3758 | if (!value) goto failed; |
| 3759 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3760 | goto failed; |
| 3761 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3762 | value = ast2obj_arg(o->vararg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3763 | if (!value) goto failed; |
| 3764 | if (_PyObject_SetAttrId(result, &PyId_vararg, value) == -1) |
| 3765 | goto failed; |
| 3766 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3767 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
| 3768 | if (!value) goto failed; |
| 3769 | if (_PyObject_SetAttrId(result, &PyId_kwonlyargs, value) == -1) |
| 3770 | goto failed; |
| 3771 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3772 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3773 | if (!value) goto failed; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3774 | if (_PyObject_SetAttrId(result, &PyId_kw_defaults, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3775 | goto failed; |
| 3776 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3777 | value = ast2obj_arg(o->kwarg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3778 | if (!value) goto failed; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3779 | if (_PyObject_SetAttrId(result, &PyId_kwarg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3780 | goto failed; |
| 3781 | Py_DECREF(value); |
| 3782 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 3783 | if (!value) goto failed; |
| 3784 | if (_PyObject_SetAttrId(result, &PyId_defaults, value) == -1) |
| 3785 | goto failed; |
| 3786 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3787 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3788 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3789 | Py_XDECREF(value); |
| 3790 | Py_XDECREF(result); |
| 3791 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3792 | } |
| 3793 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3794 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3795 | ast2obj_arg(void* _o) |
| 3796 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3797 | arg_ty o = (arg_ty)_o; |
| 3798 | PyObject *result = NULL, *value = NULL; |
| 3799 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3800 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3801 | } |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3802 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3803 | result = PyType_GenericNew(arg_type, NULL, NULL); |
| 3804 | if (!result) return NULL; |
| 3805 | value = ast2obj_identifier(o->arg); |
| 3806 | if (!value) goto failed; |
| 3807 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
| 3808 | goto failed; |
| 3809 | Py_DECREF(value); |
| 3810 | value = ast2obj_expr(o->annotation); |
| 3811 | if (!value) goto failed; |
| 3812 | if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) |
| 3813 | goto failed; |
| 3814 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3815 | value = ast2obj_int(o->lineno); |
| 3816 | if (!value) goto failed; |
| 3817 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3818 | goto failed; |
| 3819 | Py_DECREF(value); |
| 3820 | value = ast2obj_int(o->col_offset); |
| 3821 | if (!value) goto failed; |
| 3822 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3823 | goto failed; |
| 3824 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3825 | value = ast2obj_int(o->end_lineno); |
| 3826 | if (!value) goto failed; |
| 3827 | if (_PyObject_SetAttrId(result, &PyId_end_lineno, value) < 0) |
| 3828 | goto failed; |
| 3829 | Py_DECREF(value); |
| 3830 | value = ast2obj_int(o->end_col_offset); |
| 3831 | if (!value) goto failed; |
| 3832 | if (_PyObject_SetAttrId(result, &PyId_end_col_offset, value) < 0) |
| 3833 | goto failed; |
| 3834 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3835 | return result; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3836 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3837 | Py_XDECREF(value); |
| 3838 | Py_XDECREF(result); |
| 3839 | return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3840 | } |
| 3841 | |
| 3842 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3843 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3844 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3845 | keyword_ty o = (keyword_ty)_o; |
| 3846 | PyObject *result = NULL, *value = NULL; |
| 3847 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3848 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3849 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3850 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3851 | result = PyType_GenericNew(keyword_type, NULL, NULL); |
| 3852 | if (!result) return NULL; |
| 3853 | value = ast2obj_identifier(o->arg); |
| 3854 | if (!value) goto failed; |
| 3855 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
| 3856 | goto failed; |
| 3857 | Py_DECREF(value); |
| 3858 | value = ast2obj_expr(o->value); |
| 3859 | if (!value) goto failed; |
| 3860 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3861 | goto failed; |
| 3862 | Py_DECREF(value); |
| 3863 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3864 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3865 | Py_XDECREF(value); |
| 3866 | Py_XDECREF(result); |
| 3867 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3868 | } |
| 3869 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3870 | PyObject* |
| 3871 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3872 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3873 | alias_ty o = (alias_ty)_o; |
| 3874 | PyObject *result = NULL, *value = NULL; |
| 3875 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3876 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3877 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3878 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3879 | result = PyType_GenericNew(alias_type, NULL, NULL); |
| 3880 | if (!result) return NULL; |
| 3881 | value = ast2obj_identifier(o->name); |
| 3882 | if (!value) goto failed; |
| 3883 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 3884 | goto failed; |
| 3885 | Py_DECREF(value); |
| 3886 | value = ast2obj_identifier(o->asname); |
| 3887 | if (!value) goto failed; |
| 3888 | if (_PyObject_SetAttrId(result, &PyId_asname, value) == -1) |
| 3889 | goto failed; |
| 3890 | Py_DECREF(value); |
| 3891 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3892 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3893 | Py_XDECREF(value); |
| 3894 | Py_XDECREF(result); |
| 3895 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3896 | } |
| 3897 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3898 | PyObject* |
| 3899 | ast2obj_withitem(void* _o) |
| 3900 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3901 | withitem_ty o = (withitem_ty)_o; |
| 3902 | PyObject *result = NULL, *value = NULL; |
| 3903 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3904 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3905 | } |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3906 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3907 | result = PyType_GenericNew(withitem_type, NULL, NULL); |
| 3908 | if (!result) return NULL; |
| 3909 | value = ast2obj_expr(o->context_expr); |
| 3910 | if (!value) goto failed; |
| 3911 | if (_PyObject_SetAttrId(result, &PyId_context_expr, value) == -1) |
| 3912 | goto failed; |
| 3913 | Py_DECREF(value); |
| 3914 | value = ast2obj_expr(o->optional_vars); |
| 3915 | if (!value) goto failed; |
| 3916 | if (_PyObject_SetAttrId(result, &PyId_optional_vars, value) == -1) |
| 3917 | goto failed; |
| 3918 | Py_DECREF(value); |
| 3919 | return result; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3920 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3921 | Py_XDECREF(value); |
| 3922 | Py_XDECREF(result); |
| 3923 | return NULL; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3924 | } |
| 3925 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3926 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3927 | int |
| 3928 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 3929 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3930 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3931 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3932 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3933 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3934 | if (obj == Py_None) { |
| 3935 | *out = NULL; |
| 3936 | return 0; |
| 3937 | } |
| 3938 | isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type); |
| 3939 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3940 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3941 | } |
| 3942 | if (isinstance) { |
| 3943 | asdl_seq* body; |
| 3944 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 3945 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 3946 | return 1; |
| 3947 | } |
| 3948 | if (tmp == NULL) { |
| 3949 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 3950 | return 1; |
| 3951 | } |
| 3952 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3953 | int res; |
| 3954 | Py_ssize_t len; |
| 3955 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3956 | if (!PyList_Check(tmp)) { |
| 3957 | PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3958 | goto failed; |
| 3959 | } |
| 3960 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 3961 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3962 | if (body == NULL) goto failed; |
| 3963 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 3964 | stmt_ty val; |
| 3965 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3966 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 3967 | if (len != PyList_GET_SIZE(tmp)) { |
| 3968 | PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration"); |
| 3969 | goto failed; |
| 3970 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 3971 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3972 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 3973 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 3974 | } |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 3975 | *out = Module(body, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3976 | if (*out == NULL) goto failed; |
| 3977 | return 0; |
| 3978 | } |
| 3979 | isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type); |
| 3980 | if (isinstance == -1) { |
| 3981 | return 1; |
| 3982 | } |
| 3983 | if (isinstance) { |
| 3984 | asdl_seq* body; |
| 3985 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 3986 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 3987 | return 1; |
| 3988 | } |
| 3989 | if (tmp == NULL) { |
| 3990 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 3991 | return 1; |
| 3992 | } |
| 3993 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3994 | int res; |
| 3995 | Py_ssize_t len; |
| 3996 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3997 | if (!PyList_Check(tmp)) { |
| 3998 | PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3999 | goto failed; |
| 4000 | } |
| 4001 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4002 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4003 | if (body == NULL) goto failed; |
| 4004 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4005 | stmt_ty val; |
| 4006 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4007 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4008 | if (len != PyList_GET_SIZE(tmp)) { |
| 4009 | PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration"); |
| 4010 | goto failed; |
| 4011 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4012 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4013 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4014 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4015 | } |
| 4016 | *out = Interactive(body, arena); |
| 4017 | if (*out == NULL) goto failed; |
| 4018 | return 0; |
| 4019 | } |
| 4020 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type); |
| 4021 | if (isinstance == -1) { |
| 4022 | return 1; |
| 4023 | } |
| 4024 | if (isinstance) { |
| 4025 | expr_ty body; |
| 4026 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4027 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 4028 | return 1; |
| 4029 | } |
| 4030 | if (tmp == NULL) { |
| 4031 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 4032 | return 1; |
| 4033 | } |
| 4034 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4035 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4036 | res = obj2ast_expr(tmp, &body, arena); |
| 4037 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4038 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4039 | } |
| 4040 | *out = Expression(body, arena); |
| 4041 | if (*out == NULL) goto failed; |
| 4042 | return 0; |
| 4043 | } |
| 4044 | isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type); |
| 4045 | if (isinstance == -1) { |
| 4046 | return 1; |
| 4047 | } |
| 4048 | if (isinstance) { |
| 4049 | asdl_seq* body; |
| 4050 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4051 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 4052 | return 1; |
| 4053 | } |
| 4054 | if (tmp == NULL) { |
| 4055 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite"); |
| 4056 | return 1; |
| 4057 | } |
| 4058 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4059 | int res; |
| 4060 | Py_ssize_t len; |
| 4061 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4062 | if (!PyList_Check(tmp)) { |
| 4063 | PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4064 | goto failed; |
| 4065 | } |
| 4066 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4067 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4068 | if (body == NULL) goto failed; |
| 4069 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4070 | stmt_ty val; |
| 4071 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4072 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4073 | if (len != PyList_GET_SIZE(tmp)) { |
| 4074 | PyErr_SetString(PyExc_RuntimeError, "Suite field \"body\" changed size during iteration"); |
| 4075 | goto failed; |
| 4076 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4077 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4078 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4079 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4080 | } |
| 4081 | *out = Suite(body, arena); |
| 4082 | if (*out == NULL) goto failed; |
| 4083 | return 0; |
| 4084 | } |
| 4085 | |
| 4086 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
| 4087 | failed: |
| 4088 | Py_XDECREF(tmp); |
| 4089 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4090 | } |
| 4091 | |
| 4092 | int |
| 4093 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 4094 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4095 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4096 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4097 | PyObject *tmp = NULL; |
| 4098 | int lineno; |
| 4099 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4100 | int end_lineno; |
| 4101 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4102 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4103 | if (obj == Py_None) { |
| 4104 | *out = NULL; |
| 4105 | return 0; |
| 4106 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4107 | if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) { |
| 4108 | return 1; |
| 4109 | } |
| 4110 | if (tmp == NULL) { |
| 4111 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 4112 | return 1; |
| 4113 | } |
| 4114 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4115 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4116 | res = obj2ast_int(tmp, &lineno, arena); |
| 4117 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4118 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4119 | } |
| 4120 | if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4121 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4122 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4123 | if (tmp == NULL) { |
| 4124 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 4125 | return 1; |
| 4126 | } |
| 4127 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4128 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4129 | res = obj2ast_int(tmp, &col_offset, arena); |
| 4130 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4131 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4132 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4133 | if (_PyObject_LookupAttrId(obj, &PyId_end_lineno, &tmp) < 0) { |
| 4134 | return 1; |
| 4135 | } |
| 4136 | if (tmp == NULL || tmp == Py_None) { |
| 4137 | Py_CLEAR(tmp); |
| 4138 | end_lineno = 0; |
| 4139 | } |
| 4140 | else { |
| 4141 | int res; |
| 4142 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 4143 | if (res != 0) goto failed; |
| 4144 | Py_CLEAR(tmp); |
| 4145 | } |
| 4146 | if (_PyObject_LookupAttrId(obj, &PyId_end_col_offset, &tmp) < 0) { |
| 4147 | return 1; |
| 4148 | } |
| 4149 | if (tmp == NULL || tmp == Py_None) { |
| 4150 | Py_CLEAR(tmp); |
| 4151 | end_col_offset = 0; |
| 4152 | } |
| 4153 | else { |
| 4154 | int res; |
| 4155 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 4156 | if (res != 0) goto failed; |
| 4157 | Py_CLEAR(tmp); |
| 4158 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4159 | isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type); |
| 4160 | if (isinstance == -1) { |
| 4161 | return 1; |
| 4162 | } |
| 4163 | if (isinstance) { |
| 4164 | identifier name; |
| 4165 | arguments_ty args; |
| 4166 | asdl_seq* body; |
| 4167 | asdl_seq* decorator_list; |
| 4168 | expr_ty returns; |
| 4169 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4170 | if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) { |
| 4171 | return 1; |
| 4172 | } |
| 4173 | if (tmp == NULL) { |
| 4174 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 4175 | return 1; |
| 4176 | } |
| 4177 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4178 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4179 | res = obj2ast_identifier(tmp, &name, arena); |
| 4180 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4181 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4182 | } |
| 4183 | if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4184 | return 1; |
| 4185 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4186 | if (tmp == NULL) { |
| 4187 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 4188 | return 1; |
| 4189 | } |
| 4190 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4191 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4192 | res = obj2ast_arguments(tmp, &args, arena); |
| 4193 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4194 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4195 | } |
| 4196 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4197 | return 1; |
| 4198 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4199 | if (tmp == NULL) { |
| 4200 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 4201 | return 1; |
| 4202 | } |
| 4203 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4204 | int res; |
| 4205 | Py_ssize_t len; |
| 4206 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4207 | if (!PyList_Check(tmp)) { |
| 4208 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4209 | goto failed; |
| 4210 | } |
| 4211 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4212 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4213 | if (body == NULL) goto failed; |
| 4214 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4215 | stmt_ty val; |
| 4216 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4217 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4218 | if (len != PyList_GET_SIZE(tmp)) { |
| 4219 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration"); |
| 4220 | goto failed; |
| 4221 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4222 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4223 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4224 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4225 | } |
| 4226 | if (_PyObject_LookupAttrId(obj, &PyId_decorator_list, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4227 | return 1; |
| 4228 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4229 | if (tmp == NULL) { |
| 4230 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 4231 | return 1; |
| 4232 | } |
| 4233 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4234 | int res; |
| 4235 | Py_ssize_t len; |
| 4236 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4237 | if (!PyList_Check(tmp)) { |
| 4238 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4239 | goto failed; |
| 4240 | } |
| 4241 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4242 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4243 | if (decorator_list == NULL) goto failed; |
| 4244 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4245 | expr_ty val; |
| 4246 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4247 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4248 | if (len != PyList_GET_SIZE(tmp)) { |
| 4249 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration"); |
| 4250 | goto failed; |
| 4251 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4252 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4253 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4254 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4255 | } |
| 4256 | if (_PyObject_LookupAttrId(obj, &PyId_returns, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4257 | return 1; |
| 4258 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4259 | if (tmp == NULL || tmp == Py_None) { |
| 4260 | Py_CLEAR(tmp); |
| 4261 | returns = NULL; |
| 4262 | } |
| 4263 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4264 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4265 | res = obj2ast_expr(tmp, &returns, arena); |
| 4266 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4267 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4268 | } |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 4269 | *out = FunctionDef(name, args, body, decorator_list, returns, lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4270 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4271 | if (*out == NULL) goto failed; |
| 4272 | return 0; |
| 4273 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4274 | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncFunctionDef_type); |
| 4275 | if (isinstance == -1) { |
| 4276 | return 1; |
| 4277 | } |
| 4278 | if (isinstance) { |
| 4279 | identifier name; |
| 4280 | arguments_ty args; |
| 4281 | asdl_seq* body; |
| 4282 | asdl_seq* decorator_list; |
| 4283 | expr_ty returns; |
| 4284 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4285 | if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) { |
| 4286 | return 1; |
| 4287 | } |
| 4288 | if (tmp == NULL) { |
| 4289 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef"); |
| 4290 | return 1; |
| 4291 | } |
| 4292 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4293 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4294 | res = obj2ast_identifier(tmp, &name, arena); |
| 4295 | if (res != 0) goto failed; |
| 4296 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4297 | } |
| 4298 | if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4299 | return 1; |
| 4300 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4301 | if (tmp == NULL) { |
| 4302 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef"); |
| 4303 | return 1; |
| 4304 | } |
| 4305 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4306 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4307 | res = obj2ast_arguments(tmp, &args, arena); |
| 4308 | if (res != 0) goto failed; |
| 4309 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4310 | } |
| 4311 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4312 | return 1; |
| 4313 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4314 | if (tmp == NULL) { |
| 4315 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef"); |
| 4316 | return 1; |
| 4317 | } |
| 4318 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4319 | int res; |
| 4320 | Py_ssize_t len; |
| 4321 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4322 | if (!PyList_Check(tmp)) { |
| 4323 | PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4324 | goto failed; |
| 4325 | } |
| 4326 | len = PyList_GET_SIZE(tmp); |
| 4327 | body = _Py_asdl_seq_new(len, arena); |
| 4328 | if (body == NULL) goto failed; |
| 4329 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4330 | stmt_ty val; |
| 4331 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4332 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4333 | if (len != PyList_GET_SIZE(tmp)) { |
| 4334 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration"); |
| 4335 | goto failed; |
| 4336 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4337 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4338 | } |
| 4339 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4340 | } |
| 4341 | if (_PyObject_LookupAttrId(obj, &PyId_decorator_list, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4342 | return 1; |
| 4343 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4344 | if (tmp == NULL) { |
| 4345 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef"); |
| 4346 | return 1; |
| 4347 | } |
| 4348 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4349 | int res; |
| 4350 | Py_ssize_t len; |
| 4351 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4352 | if (!PyList_Check(tmp)) { |
| 4353 | PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4354 | goto failed; |
| 4355 | } |
| 4356 | len = PyList_GET_SIZE(tmp); |
| 4357 | decorator_list = _Py_asdl_seq_new(len, arena); |
| 4358 | if (decorator_list == NULL) goto failed; |
| 4359 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4360 | expr_ty val; |
| 4361 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4362 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4363 | if (len != PyList_GET_SIZE(tmp)) { |
| 4364 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration"); |
| 4365 | goto failed; |
| 4366 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4367 | asdl_seq_SET(decorator_list, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4368 | } |
| 4369 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4370 | } |
| 4371 | if (_PyObject_LookupAttrId(obj, &PyId_returns, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4372 | return 1; |
| 4373 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4374 | if (tmp == NULL || tmp == Py_None) { |
| 4375 | Py_CLEAR(tmp); |
| 4376 | returns = NULL; |
| 4377 | } |
| 4378 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4379 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4380 | res = obj2ast_expr(tmp, &returns, arena); |
| 4381 | if (res != 0) goto failed; |
| 4382 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4383 | } |
| 4384 | *out = AsyncFunctionDef(name, args, body, decorator_list, returns, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4385 | lineno, col_offset, end_lineno, end_col_offset, |
| 4386 | arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4387 | if (*out == NULL) goto failed; |
| 4388 | return 0; |
| 4389 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4390 | isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type); |
| 4391 | if (isinstance == -1) { |
| 4392 | return 1; |
| 4393 | } |
| 4394 | if (isinstance) { |
| 4395 | identifier name; |
| 4396 | asdl_seq* bases; |
| 4397 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4398 | asdl_seq* body; |
| 4399 | asdl_seq* decorator_list; |
| 4400 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4401 | if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) { |
| 4402 | return 1; |
| 4403 | } |
| 4404 | if (tmp == NULL) { |
| 4405 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 4406 | return 1; |
| 4407 | } |
| 4408 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4409 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4410 | res = obj2ast_identifier(tmp, &name, arena); |
| 4411 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4412 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4413 | } |
| 4414 | if (_PyObject_LookupAttrId(obj, &PyId_bases, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4415 | return 1; |
| 4416 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4417 | if (tmp == NULL) { |
| 4418 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 4419 | return 1; |
| 4420 | } |
| 4421 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4422 | int res; |
| 4423 | Py_ssize_t len; |
| 4424 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4425 | if (!PyList_Check(tmp)) { |
| 4426 | PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4427 | goto failed; |
| 4428 | } |
| 4429 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4430 | bases = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4431 | if (bases == NULL) goto failed; |
| 4432 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4433 | expr_ty val; |
| 4434 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4435 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4436 | if (len != PyList_GET_SIZE(tmp)) { |
| 4437 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration"); |
| 4438 | goto failed; |
| 4439 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4440 | asdl_seq_SET(bases, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4441 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4442 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4443 | } |
| 4444 | if (_PyObject_LookupAttrId(obj, &PyId_keywords, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4445 | return 1; |
| 4446 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4447 | if (tmp == NULL) { |
| 4448 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 4449 | return 1; |
| 4450 | } |
| 4451 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4452 | int res; |
| 4453 | Py_ssize_t len; |
| 4454 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4455 | if (!PyList_Check(tmp)) { |
| 4456 | PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4457 | goto failed; |
| 4458 | } |
| 4459 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4460 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4461 | if (keywords == NULL) goto failed; |
| 4462 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4463 | keyword_ty val; |
| 4464 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4465 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4466 | if (len != PyList_GET_SIZE(tmp)) { |
| 4467 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration"); |
| 4468 | goto failed; |
| 4469 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4470 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4471 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4472 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4473 | } |
| 4474 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4475 | return 1; |
| 4476 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4477 | if (tmp == NULL) { |
| 4478 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 4479 | return 1; |
| 4480 | } |
| 4481 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4482 | int res; |
| 4483 | Py_ssize_t len; |
| 4484 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4485 | if (!PyList_Check(tmp)) { |
| 4486 | PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4487 | goto failed; |
| 4488 | } |
| 4489 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4490 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4491 | if (body == NULL) goto failed; |
| 4492 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4493 | stmt_ty val; |
| 4494 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4495 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4496 | if (len != PyList_GET_SIZE(tmp)) { |
| 4497 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration"); |
| 4498 | goto failed; |
| 4499 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4500 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4501 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4502 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4503 | } |
| 4504 | if (_PyObject_LookupAttrId(obj, &PyId_decorator_list, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4505 | return 1; |
| 4506 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4507 | if (tmp == NULL) { |
| 4508 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 4509 | return 1; |
| 4510 | } |
| 4511 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4512 | int res; |
| 4513 | Py_ssize_t len; |
| 4514 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4515 | if (!PyList_Check(tmp)) { |
| 4516 | PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4517 | goto failed; |
| 4518 | } |
| 4519 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4520 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4521 | if (decorator_list == NULL) goto failed; |
| 4522 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4523 | expr_ty val; |
| 4524 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4525 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4526 | if (len != PyList_GET_SIZE(tmp)) { |
| 4527 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration"); |
| 4528 | goto failed; |
| 4529 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4530 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4531 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4532 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4533 | } |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 4534 | *out = ClassDef(name, bases, keywords, body, decorator_list, lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4535 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4536 | if (*out == NULL) goto failed; |
| 4537 | return 0; |
| 4538 | } |
| 4539 | isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type); |
| 4540 | if (isinstance == -1) { |
| 4541 | return 1; |
| 4542 | } |
| 4543 | if (isinstance) { |
| 4544 | expr_ty value; |
| 4545 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4546 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 4547 | return 1; |
| 4548 | } |
| 4549 | if (tmp == NULL || tmp == Py_None) { |
| 4550 | Py_CLEAR(tmp); |
| 4551 | value = NULL; |
| 4552 | } |
| 4553 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4554 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4555 | res = obj2ast_expr(tmp, &value, arena); |
| 4556 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4557 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4558 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4559 | *out = Return(value, lineno, col_offset, end_lineno, end_col_offset, |
| 4560 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4561 | if (*out == NULL) goto failed; |
| 4562 | return 0; |
| 4563 | } |
| 4564 | isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type); |
| 4565 | if (isinstance == -1) { |
| 4566 | return 1; |
| 4567 | } |
| 4568 | if (isinstance) { |
| 4569 | asdl_seq* targets; |
| 4570 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4571 | if (_PyObject_LookupAttrId(obj, &PyId_targets, &tmp) < 0) { |
| 4572 | return 1; |
| 4573 | } |
| 4574 | if (tmp == NULL) { |
| 4575 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 4576 | return 1; |
| 4577 | } |
| 4578 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4579 | int res; |
| 4580 | Py_ssize_t len; |
| 4581 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4582 | if (!PyList_Check(tmp)) { |
| 4583 | PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4584 | goto failed; |
| 4585 | } |
| 4586 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4587 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4588 | if (targets == NULL) goto failed; |
| 4589 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4590 | expr_ty val; |
| 4591 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4592 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4593 | if (len != PyList_GET_SIZE(tmp)) { |
| 4594 | PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration"); |
| 4595 | goto failed; |
| 4596 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4597 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4598 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4599 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4600 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4601 | *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset, |
| 4602 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4603 | if (*out == NULL) goto failed; |
| 4604 | return 0; |
| 4605 | } |
| 4606 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type); |
| 4607 | if (isinstance == -1) { |
| 4608 | return 1; |
| 4609 | } |
| 4610 | if (isinstance) { |
| 4611 | asdl_seq* targets; |
| 4612 | expr_ty value; |
| 4613 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4614 | if (_PyObject_LookupAttrId(obj, &PyId_targets, &tmp) < 0) { |
| 4615 | return 1; |
| 4616 | } |
| 4617 | if (tmp == NULL) { |
| 4618 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 4619 | return 1; |
| 4620 | } |
| 4621 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4622 | int res; |
| 4623 | Py_ssize_t len; |
| 4624 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4625 | if (!PyList_Check(tmp)) { |
| 4626 | PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4627 | goto failed; |
| 4628 | } |
| 4629 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4630 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4631 | if (targets == NULL) goto failed; |
| 4632 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4633 | expr_ty val; |
| 4634 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4635 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4636 | if (len != PyList_GET_SIZE(tmp)) { |
| 4637 | PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration"); |
| 4638 | goto failed; |
| 4639 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4640 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4641 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4642 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4643 | } |
| 4644 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4645 | return 1; |
| 4646 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4647 | if (tmp == NULL) { |
| 4648 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 4649 | return 1; |
| 4650 | } |
| 4651 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4652 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4653 | res = obj2ast_expr(tmp, &value, arena); |
| 4654 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4655 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4656 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4657 | *out = Assign(targets, value, lineno, col_offset, end_lineno, |
| 4658 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4659 | if (*out == NULL) goto failed; |
| 4660 | return 0; |
| 4661 | } |
| 4662 | isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type); |
| 4663 | if (isinstance == -1) { |
| 4664 | return 1; |
| 4665 | } |
| 4666 | if (isinstance) { |
| 4667 | expr_ty target; |
| 4668 | operator_ty op; |
| 4669 | expr_ty value; |
| 4670 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4671 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 4672 | return 1; |
| 4673 | } |
| 4674 | if (tmp == NULL) { |
| 4675 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 4676 | return 1; |
| 4677 | } |
| 4678 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4679 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4680 | res = obj2ast_expr(tmp, &target, arena); |
| 4681 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4682 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4683 | } |
| 4684 | if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4685 | return 1; |
| 4686 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4687 | if (tmp == NULL) { |
| 4688 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 4689 | return 1; |
| 4690 | } |
| 4691 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4692 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4693 | res = obj2ast_operator(tmp, &op, arena); |
| 4694 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4695 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4696 | } |
| 4697 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4698 | return 1; |
| 4699 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4700 | if (tmp == NULL) { |
| 4701 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 4702 | return 1; |
| 4703 | } |
| 4704 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4705 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4706 | res = obj2ast_expr(tmp, &value, arena); |
| 4707 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4708 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4709 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4710 | *out = AugAssign(target, op, value, lineno, col_offset, end_lineno, |
| 4711 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4712 | if (*out == NULL) goto failed; |
| 4713 | return 0; |
| 4714 | } |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4715 | isinstance = PyObject_IsInstance(obj, (PyObject*)AnnAssign_type); |
| 4716 | if (isinstance == -1) { |
| 4717 | return 1; |
| 4718 | } |
| 4719 | if (isinstance) { |
| 4720 | expr_ty target; |
| 4721 | expr_ty annotation; |
| 4722 | expr_ty value; |
| 4723 | int simple; |
| 4724 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4725 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 4726 | return 1; |
| 4727 | } |
| 4728 | if (tmp == NULL) { |
| 4729 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign"); |
| 4730 | return 1; |
| 4731 | } |
| 4732 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4733 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4734 | res = obj2ast_expr(tmp, &target, arena); |
| 4735 | if (res != 0) goto failed; |
| 4736 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4737 | } |
| 4738 | if (_PyObject_LookupAttrId(obj, &PyId_annotation, &tmp) < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4739 | return 1; |
| 4740 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4741 | if (tmp == NULL) { |
| 4742 | PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign"); |
| 4743 | return 1; |
| 4744 | } |
| 4745 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4746 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4747 | res = obj2ast_expr(tmp, &annotation, arena); |
| 4748 | if (res != 0) goto failed; |
| 4749 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4750 | } |
| 4751 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4752 | return 1; |
| 4753 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4754 | if (tmp == NULL || tmp == Py_None) { |
| 4755 | Py_CLEAR(tmp); |
| 4756 | value = NULL; |
| 4757 | } |
| 4758 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4759 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4760 | res = obj2ast_expr(tmp, &value, arena); |
| 4761 | if (res != 0) goto failed; |
| 4762 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4763 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4764 | if (_PyObject_LookupAttrId(obj, &PyId_simple, &tmp) < 0) { |
| 4765 | return 1; |
| 4766 | } |
| 4767 | if (tmp == NULL) { |
| 4768 | PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign"); |
| 4769 | return 1; |
| 4770 | } |
| 4771 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4772 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4773 | res = obj2ast_int(tmp, &simple, arena); |
| 4774 | if (res != 0) goto failed; |
| 4775 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4776 | } |
| 4777 | *out = AnnAssign(target, annotation, value, simple, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4778 | end_lineno, end_col_offset, arena); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4779 | if (*out == NULL) goto failed; |
| 4780 | return 0; |
| 4781 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4782 | isinstance = PyObject_IsInstance(obj, (PyObject*)For_type); |
| 4783 | if (isinstance == -1) { |
| 4784 | return 1; |
| 4785 | } |
| 4786 | if (isinstance) { |
| 4787 | expr_ty target; |
| 4788 | expr_ty iter; |
| 4789 | asdl_seq* body; |
| 4790 | asdl_seq* orelse; |
| 4791 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4792 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 4793 | return 1; |
| 4794 | } |
| 4795 | if (tmp == NULL) { |
| 4796 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 4797 | return 1; |
| 4798 | } |
| 4799 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4800 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4801 | res = obj2ast_expr(tmp, &target, arena); |
| 4802 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4803 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4804 | } |
| 4805 | if (_PyObject_LookupAttrId(obj, &PyId_iter, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4806 | return 1; |
| 4807 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4808 | if (tmp == NULL) { |
| 4809 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 4810 | return 1; |
| 4811 | } |
| 4812 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4813 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4814 | res = obj2ast_expr(tmp, &iter, arena); |
| 4815 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4816 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4817 | } |
| 4818 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4819 | return 1; |
| 4820 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4821 | if (tmp == NULL) { |
| 4822 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 4823 | return 1; |
| 4824 | } |
| 4825 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4826 | int res; |
| 4827 | Py_ssize_t len; |
| 4828 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4829 | if (!PyList_Check(tmp)) { |
| 4830 | PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4831 | goto failed; |
| 4832 | } |
| 4833 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4834 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4835 | if (body == NULL) goto failed; |
| 4836 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4837 | stmt_ty val; |
| 4838 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4839 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4840 | if (len != PyList_GET_SIZE(tmp)) { |
| 4841 | PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration"); |
| 4842 | goto failed; |
| 4843 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4844 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4845 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4846 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4847 | } |
| 4848 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4849 | return 1; |
| 4850 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4851 | if (tmp == NULL) { |
| 4852 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 4853 | return 1; |
| 4854 | } |
| 4855 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4856 | int res; |
| 4857 | Py_ssize_t len; |
| 4858 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4859 | if (!PyList_Check(tmp)) { |
| 4860 | PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4861 | goto failed; |
| 4862 | } |
| 4863 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4864 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4865 | if (orelse == NULL) goto failed; |
| 4866 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4867 | stmt_ty val; |
| 4868 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4869 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4870 | if (len != PyList_GET_SIZE(tmp)) { |
| 4871 | PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration"); |
| 4872 | goto failed; |
| 4873 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4874 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4875 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4876 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4877 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4878 | *out = For(target, iter, body, orelse, lineno, col_offset, end_lineno, |
| 4879 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4880 | if (*out == NULL) goto failed; |
| 4881 | return 0; |
| 4882 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4883 | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncFor_type); |
| 4884 | if (isinstance == -1) { |
| 4885 | return 1; |
| 4886 | } |
| 4887 | if (isinstance) { |
| 4888 | expr_ty target; |
| 4889 | expr_ty iter; |
| 4890 | asdl_seq* body; |
| 4891 | asdl_seq* orelse; |
| 4892 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4893 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 4894 | return 1; |
| 4895 | } |
| 4896 | if (tmp == NULL) { |
| 4897 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor"); |
| 4898 | return 1; |
| 4899 | } |
| 4900 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4901 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4902 | res = obj2ast_expr(tmp, &target, arena); |
| 4903 | if (res != 0) goto failed; |
| 4904 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4905 | } |
| 4906 | if (_PyObject_LookupAttrId(obj, &PyId_iter, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [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 \"iter\" missing from AsyncFor"); |
| 4911 | return 1; |
| 4912 | } |
| 4913 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4914 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4915 | res = obj2ast_expr(tmp, &iter, arena); |
| 4916 | if (res != 0) goto failed; |
| 4917 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4918 | } |
| 4919 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4920 | return 1; |
| 4921 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4922 | if (tmp == NULL) { |
| 4923 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor"); |
| 4924 | return 1; |
| 4925 | } |
| 4926 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4927 | int res; |
| 4928 | Py_ssize_t len; |
| 4929 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4930 | if (!PyList_Check(tmp)) { |
| 4931 | PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4932 | goto failed; |
| 4933 | } |
| 4934 | len = PyList_GET_SIZE(tmp); |
| 4935 | body = _Py_asdl_seq_new(len, arena); |
| 4936 | if (body == NULL) goto failed; |
| 4937 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4938 | stmt_ty val; |
| 4939 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4940 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4941 | if (len != PyList_GET_SIZE(tmp)) { |
| 4942 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration"); |
| 4943 | goto failed; |
| 4944 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4945 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4946 | } |
| 4947 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4948 | } |
| 4949 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4950 | return 1; |
| 4951 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4952 | if (tmp == NULL) { |
| 4953 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor"); |
| 4954 | return 1; |
| 4955 | } |
| 4956 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4957 | int res; |
| 4958 | Py_ssize_t len; |
| 4959 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4960 | if (!PyList_Check(tmp)) { |
| 4961 | PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4962 | goto failed; |
| 4963 | } |
| 4964 | len = PyList_GET_SIZE(tmp); |
| 4965 | orelse = _Py_asdl_seq_new(len, arena); |
| 4966 | if (orelse == NULL) goto failed; |
| 4967 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4968 | stmt_ty val; |
| 4969 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4970 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4971 | if (len != PyList_GET_SIZE(tmp)) { |
| 4972 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration"); |
| 4973 | goto failed; |
| 4974 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4975 | asdl_seq_SET(orelse, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4976 | } |
| 4977 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4978 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4979 | *out = AsyncFor(target, iter, body, orelse, lineno, col_offset, |
| 4980 | end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4981 | if (*out == NULL) goto failed; |
| 4982 | return 0; |
| 4983 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4984 | isinstance = PyObject_IsInstance(obj, (PyObject*)While_type); |
| 4985 | if (isinstance == -1) { |
| 4986 | return 1; |
| 4987 | } |
| 4988 | if (isinstance) { |
| 4989 | expr_ty test; |
| 4990 | asdl_seq* body; |
| 4991 | asdl_seq* orelse; |
| 4992 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4993 | if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) { |
| 4994 | return 1; |
| 4995 | } |
| 4996 | if (tmp == NULL) { |
| 4997 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 4998 | return 1; |
| 4999 | } |
| 5000 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5001 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5002 | res = obj2ast_expr(tmp, &test, arena); |
| 5003 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5004 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5005 | } |
| 5006 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5007 | return 1; |
| 5008 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5009 | if (tmp == NULL) { |
| 5010 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 5011 | return 1; |
| 5012 | } |
| 5013 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5014 | int res; |
| 5015 | Py_ssize_t len; |
| 5016 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5017 | if (!PyList_Check(tmp)) { |
| 5018 | PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5019 | goto failed; |
| 5020 | } |
| 5021 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5022 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5023 | if (body == NULL) goto failed; |
| 5024 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5025 | stmt_ty val; |
| 5026 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5027 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5028 | if (len != PyList_GET_SIZE(tmp)) { |
| 5029 | PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration"); |
| 5030 | goto failed; |
| 5031 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5032 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5033 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5034 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5035 | } |
| 5036 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5037 | return 1; |
| 5038 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5039 | if (tmp == NULL) { |
| 5040 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 5041 | return 1; |
| 5042 | } |
| 5043 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5044 | int res; |
| 5045 | Py_ssize_t len; |
| 5046 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5047 | if (!PyList_Check(tmp)) { |
| 5048 | PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5049 | goto failed; |
| 5050 | } |
| 5051 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5052 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5053 | if (orelse == NULL) goto failed; |
| 5054 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5055 | stmt_ty val; |
| 5056 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5057 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5058 | if (len != PyList_GET_SIZE(tmp)) { |
| 5059 | PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration"); |
| 5060 | goto failed; |
| 5061 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5062 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5063 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5064 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5065 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5066 | *out = While(test, body, orelse, lineno, col_offset, end_lineno, |
| 5067 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5068 | if (*out == NULL) goto failed; |
| 5069 | return 0; |
| 5070 | } |
| 5071 | isinstance = PyObject_IsInstance(obj, (PyObject*)If_type); |
| 5072 | if (isinstance == -1) { |
| 5073 | return 1; |
| 5074 | } |
| 5075 | if (isinstance) { |
| 5076 | expr_ty test; |
| 5077 | asdl_seq* body; |
| 5078 | asdl_seq* orelse; |
| 5079 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5080 | if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) { |
| 5081 | return 1; |
| 5082 | } |
| 5083 | if (tmp == NULL) { |
| 5084 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 5085 | return 1; |
| 5086 | } |
| 5087 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5088 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5089 | res = obj2ast_expr(tmp, &test, arena); |
| 5090 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5091 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5092 | } |
| 5093 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5094 | return 1; |
| 5095 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5096 | if (tmp == NULL) { |
| 5097 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 5098 | return 1; |
| 5099 | } |
| 5100 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5101 | int res; |
| 5102 | Py_ssize_t len; |
| 5103 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5104 | if (!PyList_Check(tmp)) { |
| 5105 | PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5106 | goto failed; |
| 5107 | } |
| 5108 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5109 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5110 | if (body == NULL) goto failed; |
| 5111 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5112 | stmt_ty val; |
| 5113 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5114 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5115 | if (len != PyList_GET_SIZE(tmp)) { |
| 5116 | PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration"); |
| 5117 | goto failed; |
| 5118 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5119 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5120 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5121 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5122 | } |
| 5123 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5124 | return 1; |
| 5125 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5126 | if (tmp == NULL) { |
| 5127 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 5128 | return 1; |
| 5129 | } |
| 5130 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5131 | int res; |
| 5132 | Py_ssize_t len; |
| 5133 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5134 | if (!PyList_Check(tmp)) { |
| 5135 | PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5136 | goto failed; |
| 5137 | } |
| 5138 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5139 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5140 | if (orelse == NULL) goto failed; |
| 5141 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5142 | stmt_ty val; |
| 5143 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5144 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5145 | if (len != PyList_GET_SIZE(tmp)) { |
| 5146 | PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration"); |
| 5147 | goto failed; |
| 5148 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5149 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5150 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5151 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5152 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5153 | *out = If(test, body, orelse, lineno, col_offset, end_lineno, |
| 5154 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5155 | if (*out == NULL) goto failed; |
| 5156 | return 0; |
| 5157 | } |
| 5158 | isinstance = PyObject_IsInstance(obj, (PyObject*)With_type); |
| 5159 | if (isinstance == -1) { |
| 5160 | return 1; |
| 5161 | } |
| 5162 | if (isinstance) { |
| 5163 | asdl_seq* items; |
| 5164 | asdl_seq* body; |
| 5165 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5166 | if (_PyObject_LookupAttrId(obj, &PyId_items, &tmp) < 0) { |
| 5167 | return 1; |
| 5168 | } |
| 5169 | if (tmp == NULL) { |
| 5170 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); |
| 5171 | return 1; |
| 5172 | } |
| 5173 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5174 | int res; |
| 5175 | Py_ssize_t len; |
| 5176 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5177 | if (!PyList_Check(tmp)) { |
| 5178 | PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5179 | goto failed; |
| 5180 | } |
| 5181 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5182 | items = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5183 | if (items == NULL) goto failed; |
| 5184 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5185 | withitem_ty val; |
| 5186 | res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5187 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5188 | if (len != PyList_GET_SIZE(tmp)) { |
| 5189 | PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration"); |
| 5190 | goto failed; |
| 5191 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5192 | asdl_seq_SET(items, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5193 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5194 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5195 | } |
| 5196 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5197 | return 1; |
| 5198 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5199 | if (tmp == NULL) { |
| 5200 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 5201 | return 1; |
| 5202 | } |
| 5203 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5204 | int res; |
| 5205 | Py_ssize_t len; |
| 5206 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5207 | if (!PyList_Check(tmp)) { |
| 5208 | PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5209 | goto failed; |
| 5210 | } |
| 5211 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5212 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5213 | if (body == NULL) goto failed; |
| 5214 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5215 | stmt_ty val; |
| 5216 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5217 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5218 | if (len != PyList_GET_SIZE(tmp)) { |
| 5219 | PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration"); |
| 5220 | goto failed; |
| 5221 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5222 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5223 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5224 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5225 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5226 | *out = With(items, body, lineno, col_offset, end_lineno, |
| 5227 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5228 | if (*out == NULL) goto failed; |
| 5229 | return 0; |
| 5230 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5231 | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncWith_type); |
| 5232 | if (isinstance == -1) { |
| 5233 | return 1; |
| 5234 | } |
| 5235 | if (isinstance) { |
| 5236 | asdl_seq* items; |
| 5237 | asdl_seq* body; |
| 5238 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5239 | if (_PyObject_LookupAttrId(obj, &PyId_items, &tmp) < 0) { |
| 5240 | return 1; |
| 5241 | } |
| 5242 | if (tmp == NULL) { |
| 5243 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith"); |
| 5244 | return 1; |
| 5245 | } |
| 5246 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5247 | int res; |
| 5248 | Py_ssize_t len; |
| 5249 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5250 | if (!PyList_Check(tmp)) { |
| 5251 | PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5252 | goto failed; |
| 5253 | } |
| 5254 | len = PyList_GET_SIZE(tmp); |
| 5255 | items = _Py_asdl_seq_new(len, arena); |
| 5256 | if (items == NULL) goto failed; |
| 5257 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5258 | withitem_ty val; |
| 5259 | res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5260 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5261 | if (len != PyList_GET_SIZE(tmp)) { |
| 5262 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration"); |
| 5263 | goto failed; |
| 5264 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5265 | asdl_seq_SET(items, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5266 | } |
| 5267 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5268 | } |
| 5269 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5270 | return 1; |
| 5271 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5272 | if (tmp == NULL) { |
| 5273 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith"); |
| 5274 | return 1; |
| 5275 | } |
| 5276 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5277 | int res; |
| 5278 | Py_ssize_t len; |
| 5279 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5280 | if (!PyList_Check(tmp)) { |
| 5281 | PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5282 | goto failed; |
| 5283 | } |
| 5284 | len = PyList_GET_SIZE(tmp); |
| 5285 | body = _Py_asdl_seq_new(len, arena); |
| 5286 | if (body == NULL) goto failed; |
| 5287 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5288 | stmt_ty val; |
| 5289 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5290 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5291 | if (len != PyList_GET_SIZE(tmp)) { |
| 5292 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration"); |
| 5293 | goto failed; |
| 5294 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5295 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5296 | } |
| 5297 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5298 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5299 | *out = AsyncWith(items, body, lineno, col_offset, end_lineno, |
| 5300 | end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5301 | if (*out == NULL) goto failed; |
| 5302 | return 0; |
| 5303 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5304 | isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type); |
| 5305 | if (isinstance == -1) { |
| 5306 | return 1; |
| 5307 | } |
| 5308 | if (isinstance) { |
| 5309 | expr_ty exc; |
| 5310 | expr_ty cause; |
| 5311 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5312 | if (_PyObject_LookupAttrId(obj, &PyId_exc, &tmp) < 0) { |
| 5313 | return 1; |
| 5314 | } |
| 5315 | if (tmp == NULL || tmp == Py_None) { |
| 5316 | Py_CLEAR(tmp); |
| 5317 | exc = NULL; |
| 5318 | } |
| 5319 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5320 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5321 | res = obj2ast_expr(tmp, &exc, arena); |
| 5322 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5323 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5324 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5325 | if (_PyObject_LookupAttrId(obj, &PyId_cause, &tmp) < 0) { |
| 5326 | return 1; |
| 5327 | } |
| 5328 | if (tmp == NULL || tmp == Py_None) { |
| 5329 | Py_CLEAR(tmp); |
| 5330 | cause = NULL; |
| 5331 | } |
| 5332 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5333 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5334 | res = obj2ast_expr(tmp, &cause, arena); |
| 5335 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5336 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5337 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5338 | *out = Raise(exc, cause, lineno, col_offset, end_lineno, |
| 5339 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5340 | if (*out == NULL) goto failed; |
| 5341 | return 0; |
| 5342 | } |
| 5343 | isinstance = PyObject_IsInstance(obj, (PyObject*)Try_type); |
| 5344 | if (isinstance == -1) { |
| 5345 | return 1; |
| 5346 | } |
| 5347 | if (isinstance) { |
| 5348 | asdl_seq* body; |
| 5349 | asdl_seq* handlers; |
| 5350 | asdl_seq* orelse; |
| 5351 | asdl_seq* finalbody; |
| 5352 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5353 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 5354 | return 1; |
| 5355 | } |
| 5356 | if (tmp == NULL) { |
| 5357 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); |
| 5358 | return 1; |
| 5359 | } |
| 5360 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5361 | int res; |
| 5362 | Py_ssize_t len; |
| 5363 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5364 | if (!PyList_Check(tmp)) { |
| 5365 | PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5366 | goto failed; |
| 5367 | } |
| 5368 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5369 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5370 | if (body == NULL) goto failed; |
| 5371 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5372 | stmt_ty val; |
| 5373 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5374 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5375 | if (len != PyList_GET_SIZE(tmp)) { |
| 5376 | PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration"); |
| 5377 | goto failed; |
| 5378 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5379 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5380 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5381 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5382 | } |
| 5383 | if (_PyObject_LookupAttrId(obj, &PyId_handlers, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5384 | return 1; |
| 5385 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5386 | if (tmp == NULL) { |
| 5387 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); |
| 5388 | return 1; |
| 5389 | } |
| 5390 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5391 | int res; |
| 5392 | Py_ssize_t len; |
| 5393 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5394 | if (!PyList_Check(tmp)) { |
| 5395 | PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5396 | goto failed; |
| 5397 | } |
| 5398 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5399 | handlers = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5400 | if (handlers == NULL) goto failed; |
| 5401 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5402 | excepthandler_ty val; |
| 5403 | res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5404 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5405 | if (len != PyList_GET_SIZE(tmp)) { |
| 5406 | PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration"); |
| 5407 | goto failed; |
| 5408 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5409 | asdl_seq_SET(handlers, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5410 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5411 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5412 | } |
| 5413 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5414 | return 1; |
| 5415 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5416 | if (tmp == NULL) { |
| 5417 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); |
| 5418 | return 1; |
| 5419 | } |
| 5420 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5421 | int res; |
| 5422 | Py_ssize_t len; |
| 5423 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5424 | if (!PyList_Check(tmp)) { |
| 5425 | PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5426 | goto failed; |
| 5427 | } |
| 5428 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5429 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5430 | if (orelse == NULL) goto failed; |
| 5431 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5432 | stmt_ty val; |
| 5433 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5434 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5435 | if (len != PyList_GET_SIZE(tmp)) { |
| 5436 | PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration"); |
| 5437 | goto failed; |
| 5438 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5439 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5440 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5441 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5442 | } |
| 5443 | if (_PyObject_LookupAttrId(obj, &PyId_finalbody, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5444 | return 1; |
| 5445 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5446 | if (tmp == NULL) { |
| 5447 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); |
| 5448 | return 1; |
| 5449 | } |
| 5450 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5451 | int res; |
| 5452 | Py_ssize_t len; |
| 5453 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5454 | if (!PyList_Check(tmp)) { |
| 5455 | PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5456 | goto failed; |
| 5457 | } |
| 5458 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5459 | finalbody = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5460 | if (finalbody == NULL) goto failed; |
| 5461 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5462 | stmt_ty val; |
| 5463 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5464 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5465 | if (len != PyList_GET_SIZE(tmp)) { |
| 5466 | PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration"); |
| 5467 | goto failed; |
| 5468 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5469 | asdl_seq_SET(finalbody, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5470 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5471 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5472 | } |
| 5473 | *out = Try(body, handlers, orelse, finalbody, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5474 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5475 | if (*out == NULL) goto failed; |
| 5476 | return 0; |
| 5477 | } |
| 5478 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type); |
| 5479 | if (isinstance == -1) { |
| 5480 | return 1; |
| 5481 | } |
| 5482 | if (isinstance) { |
| 5483 | expr_ty test; |
| 5484 | expr_ty msg; |
| 5485 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5486 | if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) { |
| 5487 | return 1; |
| 5488 | } |
| 5489 | if (tmp == NULL) { |
| 5490 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 5491 | return 1; |
| 5492 | } |
| 5493 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5494 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5495 | res = obj2ast_expr(tmp, &test, arena); |
| 5496 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5497 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5498 | } |
| 5499 | if (_PyObject_LookupAttrId(obj, &PyId_msg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5500 | return 1; |
| 5501 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5502 | if (tmp == NULL || tmp == Py_None) { |
| 5503 | Py_CLEAR(tmp); |
| 5504 | msg = NULL; |
| 5505 | } |
| 5506 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5507 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5508 | res = obj2ast_expr(tmp, &msg, arena); |
| 5509 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5510 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5511 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5512 | *out = Assert(test, msg, lineno, col_offset, end_lineno, |
| 5513 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5514 | if (*out == NULL) goto failed; |
| 5515 | return 0; |
| 5516 | } |
| 5517 | isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type); |
| 5518 | if (isinstance == -1) { |
| 5519 | return 1; |
| 5520 | } |
| 5521 | if (isinstance) { |
| 5522 | asdl_seq* names; |
| 5523 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5524 | if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) { |
| 5525 | return 1; |
| 5526 | } |
| 5527 | if (tmp == NULL) { |
| 5528 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 5529 | return 1; |
| 5530 | } |
| 5531 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5532 | int res; |
| 5533 | Py_ssize_t len; |
| 5534 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5535 | if (!PyList_Check(tmp)) { |
| 5536 | PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5537 | goto failed; |
| 5538 | } |
| 5539 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5540 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5541 | if (names == NULL) goto failed; |
| 5542 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5543 | alias_ty val; |
| 5544 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5545 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5546 | if (len != PyList_GET_SIZE(tmp)) { |
| 5547 | PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration"); |
| 5548 | goto failed; |
| 5549 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5550 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5551 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5552 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5553 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5554 | *out = Import(names, lineno, col_offset, end_lineno, end_col_offset, |
| 5555 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5556 | if (*out == NULL) goto failed; |
| 5557 | return 0; |
| 5558 | } |
| 5559 | isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type); |
| 5560 | if (isinstance == -1) { |
| 5561 | return 1; |
| 5562 | } |
| 5563 | if (isinstance) { |
| 5564 | identifier module; |
| 5565 | asdl_seq* names; |
| 5566 | int level; |
| 5567 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5568 | if (_PyObject_LookupAttrId(obj, &PyId_module, &tmp) < 0) { |
| 5569 | return 1; |
| 5570 | } |
| 5571 | if (tmp == NULL || tmp == Py_None) { |
| 5572 | Py_CLEAR(tmp); |
| 5573 | module = NULL; |
| 5574 | } |
| 5575 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5576 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5577 | res = obj2ast_identifier(tmp, &module, arena); |
| 5578 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5579 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5580 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5581 | if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) { |
| 5582 | return 1; |
| 5583 | } |
| 5584 | if (tmp == NULL) { |
| 5585 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 5586 | return 1; |
| 5587 | } |
| 5588 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5589 | int res; |
| 5590 | Py_ssize_t len; |
| 5591 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5592 | if (!PyList_Check(tmp)) { |
| 5593 | PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5594 | goto failed; |
| 5595 | } |
| 5596 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5597 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5598 | if (names == NULL) goto failed; |
| 5599 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5600 | alias_ty val; |
| 5601 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5602 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5603 | if (len != PyList_GET_SIZE(tmp)) { |
| 5604 | PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration"); |
| 5605 | goto failed; |
| 5606 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5607 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5608 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5609 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5610 | } |
| 5611 | if (_PyObject_LookupAttrId(obj, &PyId_level, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5612 | return 1; |
| 5613 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5614 | if (tmp == NULL || tmp == Py_None) { |
| 5615 | Py_CLEAR(tmp); |
| 5616 | level = 0; |
| 5617 | } |
| 5618 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5619 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5620 | res = obj2ast_int(tmp, &level, arena); |
| 5621 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5622 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5623 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5624 | *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno, |
| 5625 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5626 | if (*out == NULL) goto failed; |
| 5627 | return 0; |
| 5628 | } |
| 5629 | isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type); |
| 5630 | if (isinstance == -1) { |
| 5631 | return 1; |
| 5632 | } |
| 5633 | if (isinstance) { |
| 5634 | asdl_seq* names; |
| 5635 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5636 | if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) { |
| 5637 | return 1; |
| 5638 | } |
| 5639 | if (tmp == NULL) { |
| 5640 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 5641 | return 1; |
| 5642 | } |
| 5643 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5644 | int res; |
| 5645 | Py_ssize_t len; |
| 5646 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5647 | if (!PyList_Check(tmp)) { |
| 5648 | PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5649 | goto failed; |
| 5650 | } |
| 5651 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5652 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5653 | if (names == NULL) goto failed; |
| 5654 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5655 | identifier val; |
| 5656 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5657 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5658 | if (len != PyList_GET_SIZE(tmp)) { |
| 5659 | PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration"); |
| 5660 | goto failed; |
| 5661 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5662 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5663 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5664 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5665 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5666 | *out = Global(names, lineno, col_offset, end_lineno, end_col_offset, |
| 5667 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5668 | if (*out == NULL) goto failed; |
| 5669 | return 0; |
| 5670 | } |
| 5671 | isinstance = PyObject_IsInstance(obj, (PyObject*)Nonlocal_type); |
| 5672 | if (isinstance == -1) { |
| 5673 | return 1; |
| 5674 | } |
| 5675 | if (isinstance) { |
| 5676 | asdl_seq* names; |
| 5677 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5678 | if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) { |
| 5679 | return 1; |
| 5680 | } |
| 5681 | if (tmp == NULL) { |
| 5682 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 5683 | return 1; |
| 5684 | } |
| 5685 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5686 | int res; |
| 5687 | Py_ssize_t len; |
| 5688 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5689 | if (!PyList_Check(tmp)) { |
| 5690 | PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5691 | goto failed; |
| 5692 | } |
| 5693 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5694 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5695 | if (names == NULL) goto failed; |
| 5696 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5697 | identifier val; |
| 5698 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5699 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5700 | if (len != PyList_GET_SIZE(tmp)) { |
| 5701 | PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration"); |
| 5702 | goto failed; |
| 5703 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5704 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5705 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5706 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5707 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5708 | *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset, |
| 5709 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5710 | if (*out == NULL) goto failed; |
| 5711 | return 0; |
| 5712 | } |
| 5713 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type); |
| 5714 | if (isinstance == -1) { |
| 5715 | return 1; |
| 5716 | } |
| 5717 | if (isinstance) { |
| 5718 | expr_ty value; |
| 5719 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5720 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 5721 | return 1; |
| 5722 | } |
| 5723 | if (tmp == NULL) { |
| 5724 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 5725 | return 1; |
| 5726 | } |
| 5727 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5728 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5729 | res = obj2ast_expr(tmp, &value, arena); |
| 5730 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5731 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5732 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5733 | *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset, |
| 5734 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5735 | if (*out == NULL) goto failed; |
| 5736 | return 0; |
| 5737 | } |
| 5738 | isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type); |
| 5739 | if (isinstance == -1) { |
| 5740 | return 1; |
| 5741 | } |
| 5742 | if (isinstance) { |
| 5743 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5744 | *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5745 | if (*out == NULL) goto failed; |
| 5746 | return 0; |
| 5747 | } |
| 5748 | isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type); |
| 5749 | if (isinstance == -1) { |
| 5750 | return 1; |
| 5751 | } |
| 5752 | if (isinstance) { |
| 5753 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5754 | *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5755 | if (*out == NULL) goto failed; |
| 5756 | return 0; |
| 5757 | } |
| 5758 | isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type); |
| 5759 | if (isinstance == -1) { |
| 5760 | return 1; |
| 5761 | } |
| 5762 | if (isinstance) { |
| 5763 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5764 | *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5765 | if (*out == NULL) goto failed; |
| 5766 | return 0; |
| 5767 | } |
| 5768 | |
| 5769 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
| 5770 | failed: |
| 5771 | Py_XDECREF(tmp); |
| 5772 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5773 | } |
| 5774 | |
| 5775 | int |
| 5776 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 5777 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5778 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5779 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5780 | PyObject *tmp = NULL; |
| 5781 | int lineno; |
| 5782 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5783 | int end_lineno; |
| 5784 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5785 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5786 | if (obj == Py_None) { |
| 5787 | *out = NULL; |
| 5788 | return 0; |
| 5789 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5790 | if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) { |
| 5791 | return 1; |
| 5792 | } |
| 5793 | if (tmp == NULL) { |
| 5794 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 5795 | return 1; |
| 5796 | } |
| 5797 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5798 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5799 | res = obj2ast_int(tmp, &lineno, arena); |
| 5800 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5801 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5802 | } |
| 5803 | if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5804 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5805 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5806 | if (tmp == NULL) { |
| 5807 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 5808 | return 1; |
| 5809 | } |
| 5810 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5811 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5812 | res = obj2ast_int(tmp, &col_offset, arena); |
| 5813 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5814 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5815 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5816 | if (_PyObject_LookupAttrId(obj, &PyId_end_lineno, &tmp) < 0) { |
| 5817 | return 1; |
| 5818 | } |
| 5819 | if (tmp == NULL || tmp == Py_None) { |
| 5820 | Py_CLEAR(tmp); |
| 5821 | end_lineno = 0; |
| 5822 | } |
| 5823 | else { |
| 5824 | int res; |
| 5825 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 5826 | if (res != 0) goto failed; |
| 5827 | Py_CLEAR(tmp); |
| 5828 | } |
| 5829 | if (_PyObject_LookupAttrId(obj, &PyId_end_col_offset, &tmp) < 0) { |
| 5830 | return 1; |
| 5831 | } |
| 5832 | if (tmp == NULL || tmp == Py_None) { |
| 5833 | Py_CLEAR(tmp); |
| 5834 | end_col_offset = 0; |
| 5835 | } |
| 5836 | else { |
| 5837 | int res; |
| 5838 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 5839 | if (res != 0) goto failed; |
| 5840 | Py_CLEAR(tmp); |
| 5841 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5842 | isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type); |
| 5843 | if (isinstance == -1) { |
| 5844 | return 1; |
| 5845 | } |
| 5846 | if (isinstance) { |
| 5847 | boolop_ty op; |
| 5848 | asdl_seq* values; |
| 5849 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5850 | if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) { |
| 5851 | return 1; |
| 5852 | } |
| 5853 | if (tmp == NULL) { |
| 5854 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 5855 | return 1; |
| 5856 | } |
| 5857 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5858 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5859 | res = obj2ast_boolop(tmp, &op, arena); |
| 5860 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5861 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5862 | } |
| 5863 | if (_PyObject_LookupAttrId(obj, &PyId_values, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5864 | return 1; |
| 5865 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5866 | if (tmp == NULL) { |
| 5867 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 5868 | return 1; |
| 5869 | } |
| 5870 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5871 | int res; |
| 5872 | Py_ssize_t len; |
| 5873 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5874 | if (!PyList_Check(tmp)) { |
| 5875 | PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5876 | goto failed; |
| 5877 | } |
| 5878 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5879 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5880 | if (values == NULL) goto failed; |
| 5881 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5882 | expr_ty val; |
| 5883 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5884 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5885 | if (len != PyList_GET_SIZE(tmp)) { |
| 5886 | PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration"); |
| 5887 | goto failed; |
| 5888 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5889 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5890 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5891 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5892 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5893 | *out = BoolOp(op, values, lineno, col_offset, end_lineno, |
| 5894 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5895 | if (*out == NULL) goto failed; |
| 5896 | return 0; |
| 5897 | } |
| 5898 | isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type); |
| 5899 | if (isinstance == -1) { |
| 5900 | return 1; |
| 5901 | } |
| 5902 | if (isinstance) { |
| 5903 | expr_ty left; |
| 5904 | operator_ty op; |
| 5905 | expr_ty right; |
| 5906 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5907 | if (_PyObject_LookupAttrId(obj, &PyId_left, &tmp) < 0) { |
| 5908 | return 1; |
| 5909 | } |
| 5910 | if (tmp == NULL) { |
| 5911 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 5912 | return 1; |
| 5913 | } |
| 5914 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5915 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5916 | res = obj2ast_expr(tmp, &left, arena); |
| 5917 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5918 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5919 | } |
| 5920 | if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5921 | return 1; |
| 5922 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5923 | if (tmp == NULL) { |
| 5924 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 5925 | return 1; |
| 5926 | } |
| 5927 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5928 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5929 | res = obj2ast_operator(tmp, &op, arena); |
| 5930 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5931 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5932 | } |
| 5933 | if (_PyObject_LookupAttrId(obj, &PyId_right, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5934 | return 1; |
| 5935 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5936 | if (tmp == NULL) { |
| 5937 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 5938 | return 1; |
| 5939 | } |
| 5940 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5941 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5942 | res = obj2ast_expr(tmp, &right, arena); |
| 5943 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5944 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5945 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5946 | *out = BinOp(left, op, right, lineno, col_offset, end_lineno, |
| 5947 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5948 | if (*out == NULL) goto failed; |
| 5949 | return 0; |
| 5950 | } |
| 5951 | isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type); |
| 5952 | if (isinstance == -1) { |
| 5953 | return 1; |
| 5954 | } |
| 5955 | if (isinstance) { |
| 5956 | unaryop_ty op; |
| 5957 | expr_ty operand; |
| 5958 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5959 | if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) { |
| 5960 | return 1; |
| 5961 | } |
| 5962 | if (tmp == NULL) { |
| 5963 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 5964 | return 1; |
| 5965 | } |
| 5966 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5967 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5968 | res = obj2ast_unaryop(tmp, &op, arena); |
| 5969 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5970 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5971 | } |
| 5972 | if (_PyObject_LookupAttrId(obj, &PyId_operand, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5973 | return 1; |
| 5974 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5975 | if (tmp == NULL) { |
| 5976 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 5977 | return 1; |
| 5978 | } |
| 5979 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5980 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5981 | res = obj2ast_expr(tmp, &operand, arena); |
| 5982 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5983 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5984 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5985 | *out = UnaryOp(op, operand, lineno, col_offset, end_lineno, |
| 5986 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5987 | if (*out == NULL) goto failed; |
| 5988 | return 0; |
| 5989 | } |
| 5990 | isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type); |
| 5991 | if (isinstance == -1) { |
| 5992 | return 1; |
| 5993 | } |
| 5994 | if (isinstance) { |
| 5995 | arguments_ty args; |
| 5996 | expr_ty body; |
| 5997 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5998 | if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) { |
| 5999 | return 1; |
| 6000 | } |
| 6001 | if (tmp == NULL) { |
| 6002 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 6003 | return 1; |
| 6004 | } |
| 6005 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6006 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6007 | res = obj2ast_arguments(tmp, &args, arena); |
| 6008 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6009 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6010 | } |
| 6011 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6012 | return 1; |
| 6013 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6014 | if (tmp == NULL) { |
| 6015 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 6016 | return 1; |
| 6017 | } |
| 6018 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6019 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6020 | res = obj2ast_expr(tmp, &body, arena); |
| 6021 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6022 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6023 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6024 | *out = Lambda(args, body, lineno, col_offset, end_lineno, |
| 6025 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6026 | if (*out == NULL) goto failed; |
| 6027 | return 0; |
| 6028 | } |
| 6029 | isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type); |
| 6030 | if (isinstance == -1) { |
| 6031 | return 1; |
| 6032 | } |
| 6033 | if (isinstance) { |
| 6034 | expr_ty test; |
| 6035 | expr_ty body; |
| 6036 | expr_ty orelse; |
| 6037 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6038 | if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) { |
| 6039 | return 1; |
| 6040 | } |
| 6041 | if (tmp == NULL) { |
| 6042 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 6043 | return 1; |
| 6044 | } |
| 6045 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6046 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6047 | res = obj2ast_expr(tmp, &test, arena); |
| 6048 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6049 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6050 | } |
| 6051 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6052 | return 1; |
| 6053 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6054 | if (tmp == NULL) { |
| 6055 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 6056 | return 1; |
| 6057 | } |
| 6058 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6059 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6060 | res = obj2ast_expr(tmp, &body, arena); |
| 6061 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6062 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6063 | } |
| 6064 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6065 | return 1; |
| 6066 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6067 | if (tmp == NULL) { |
| 6068 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 6069 | return 1; |
| 6070 | } |
| 6071 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6072 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6073 | res = obj2ast_expr(tmp, &orelse, arena); |
| 6074 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6075 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6076 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6077 | *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno, |
| 6078 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6079 | if (*out == NULL) goto failed; |
| 6080 | return 0; |
| 6081 | } |
| 6082 | isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type); |
| 6083 | if (isinstance == -1) { |
| 6084 | return 1; |
| 6085 | } |
| 6086 | if (isinstance) { |
| 6087 | asdl_seq* keys; |
| 6088 | asdl_seq* values; |
| 6089 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6090 | if (_PyObject_LookupAttrId(obj, &PyId_keys, &tmp) < 0) { |
| 6091 | return 1; |
| 6092 | } |
| 6093 | if (tmp == NULL) { |
| 6094 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 6095 | return 1; |
| 6096 | } |
| 6097 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6098 | int res; |
| 6099 | Py_ssize_t len; |
| 6100 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6101 | if (!PyList_Check(tmp)) { |
| 6102 | PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6103 | goto failed; |
| 6104 | } |
| 6105 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6106 | keys = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6107 | if (keys == NULL) goto failed; |
| 6108 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6109 | expr_ty val; |
| 6110 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6111 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6112 | if (len != PyList_GET_SIZE(tmp)) { |
| 6113 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration"); |
| 6114 | goto failed; |
| 6115 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6116 | asdl_seq_SET(keys, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6117 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6118 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6119 | } |
| 6120 | if (_PyObject_LookupAttrId(obj, &PyId_values, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6121 | return 1; |
| 6122 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6123 | if (tmp == NULL) { |
| 6124 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 6125 | return 1; |
| 6126 | } |
| 6127 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6128 | int res; |
| 6129 | Py_ssize_t len; |
| 6130 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6131 | if (!PyList_Check(tmp)) { |
| 6132 | PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6133 | goto failed; |
| 6134 | } |
| 6135 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6136 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6137 | if (values == NULL) goto failed; |
| 6138 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6139 | expr_ty val; |
| 6140 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6141 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6142 | if (len != PyList_GET_SIZE(tmp)) { |
| 6143 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration"); |
| 6144 | goto failed; |
| 6145 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6146 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6147 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6148 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6149 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6150 | *out = Dict(keys, values, lineno, col_offset, end_lineno, |
| 6151 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6152 | if (*out == NULL) goto failed; |
| 6153 | return 0; |
| 6154 | } |
| 6155 | isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type); |
| 6156 | if (isinstance == -1) { |
| 6157 | return 1; |
| 6158 | } |
| 6159 | if (isinstance) { |
| 6160 | asdl_seq* elts; |
| 6161 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6162 | if (_PyObject_LookupAttrId(obj, &PyId_elts, &tmp) < 0) { |
| 6163 | return 1; |
| 6164 | } |
| 6165 | if (tmp == NULL) { |
| 6166 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 6167 | return 1; |
| 6168 | } |
| 6169 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6170 | int res; |
| 6171 | Py_ssize_t len; |
| 6172 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6173 | if (!PyList_Check(tmp)) { |
| 6174 | PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6175 | goto failed; |
| 6176 | } |
| 6177 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6178 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6179 | if (elts == NULL) goto failed; |
| 6180 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6181 | expr_ty val; |
| 6182 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6183 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6184 | if (len != PyList_GET_SIZE(tmp)) { |
| 6185 | PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration"); |
| 6186 | goto failed; |
| 6187 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6188 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6189 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6190 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6191 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6192 | *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6193 | if (*out == NULL) goto failed; |
| 6194 | return 0; |
| 6195 | } |
| 6196 | isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type); |
| 6197 | if (isinstance == -1) { |
| 6198 | return 1; |
| 6199 | } |
| 6200 | if (isinstance) { |
| 6201 | expr_ty elt; |
| 6202 | asdl_seq* generators; |
| 6203 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6204 | if (_PyObject_LookupAttrId(obj, &PyId_elt, &tmp) < 0) { |
| 6205 | return 1; |
| 6206 | } |
| 6207 | if (tmp == NULL) { |
| 6208 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 6209 | return 1; |
| 6210 | } |
| 6211 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6212 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6213 | res = obj2ast_expr(tmp, &elt, arena); |
| 6214 | if (res != 0) goto failed; |
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_generators, &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 \"generators\" missing from ListComp"); |
| 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, "ListComp field \"generators\" 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 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6234 | if (generators == NULL) goto failed; |
| 6235 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6236 | comprehension_ty val; |
| 6237 | res = obj2ast_comprehension(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, "ListComp field \"generators\" 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(generators, 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 = ListComp(elt, generators, 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*)SetComp_type); |
| 6253 | if (isinstance == -1) { |
| 6254 | return 1; |
| 6255 | } |
| 6256 | if (isinstance) { |
| 6257 | expr_ty elt; |
| 6258 | asdl_seq* generators; |
| 6259 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6260 | if (_PyObject_LookupAttrId(obj, &PyId_elt, &tmp) < 0) { |
| 6261 | return 1; |
| 6262 | } |
| 6263 | if (tmp == NULL) { |
| 6264 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 6265 | return 1; |
| 6266 | } |
| 6267 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6268 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6269 | res = obj2ast_expr(tmp, &elt, arena); |
| 6270 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6271 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6272 | } |
| 6273 | if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6274 | return 1; |
| 6275 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6276 | if (tmp == NULL) { |
| 6277 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 6278 | return 1; |
| 6279 | } |
| 6280 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6281 | int res; |
| 6282 | Py_ssize_t len; |
| 6283 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6284 | if (!PyList_Check(tmp)) { |
| 6285 | PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6286 | goto failed; |
| 6287 | } |
| 6288 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6289 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6290 | if (generators == NULL) goto failed; |
| 6291 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6292 | comprehension_ty val; |
| 6293 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6294 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6295 | if (len != PyList_GET_SIZE(tmp)) { |
| 6296 | PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration"); |
| 6297 | goto failed; |
| 6298 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6299 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6300 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6301 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6302 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6303 | *out = SetComp(elt, generators, lineno, col_offset, end_lineno, |
| 6304 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6305 | if (*out == NULL) goto failed; |
| 6306 | return 0; |
| 6307 | } |
| 6308 | isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type); |
| 6309 | if (isinstance == -1) { |
| 6310 | return 1; |
| 6311 | } |
| 6312 | if (isinstance) { |
| 6313 | expr_ty key; |
| 6314 | expr_ty value; |
| 6315 | asdl_seq* generators; |
| 6316 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6317 | if (_PyObject_LookupAttrId(obj, &PyId_key, &tmp) < 0) { |
| 6318 | return 1; |
| 6319 | } |
| 6320 | if (tmp == NULL) { |
| 6321 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 6322 | return 1; |
| 6323 | } |
| 6324 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6325 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6326 | res = obj2ast_expr(tmp, &key, arena); |
| 6327 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6328 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6329 | } |
| 6330 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6331 | return 1; |
| 6332 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6333 | if (tmp == NULL) { |
| 6334 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 6335 | return 1; |
| 6336 | } |
| 6337 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6338 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6339 | res = obj2ast_expr(tmp, &value, arena); |
| 6340 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6341 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6342 | } |
| 6343 | if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6344 | return 1; |
| 6345 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6346 | if (tmp == NULL) { |
| 6347 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 6348 | return 1; |
| 6349 | } |
| 6350 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6351 | int res; |
| 6352 | Py_ssize_t len; |
| 6353 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6354 | if (!PyList_Check(tmp)) { |
| 6355 | PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6356 | goto failed; |
| 6357 | } |
| 6358 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6359 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6360 | if (generators == NULL) goto failed; |
| 6361 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6362 | comprehension_ty val; |
| 6363 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6364 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6365 | if (len != PyList_GET_SIZE(tmp)) { |
| 6366 | PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration"); |
| 6367 | goto failed; |
| 6368 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6369 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6370 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6371 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6372 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6373 | *out = DictComp(key, value, generators, lineno, col_offset, end_lineno, |
| 6374 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6375 | if (*out == NULL) goto failed; |
| 6376 | return 0; |
| 6377 | } |
| 6378 | isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type); |
| 6379 | if (isinstance == -1) { |
| 6380 | return 1; |
| 6381 | } |
| 6382 | if (isinstance) { |
| 6383 | expr_ty elt; |
| 6384 | asdl_seq* generators; |
| 6385 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6386 | if (_PyObject_LookupAttrId(obj, &PyId_elt, &tmp) < 0) { |
| 6387 | return 1; |
| 6388 | } |
| 6389 | if (tmp == NULL) { |
| 6390 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 6391 | return 1; |
| 6392 | } |
| 6393 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6394 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6395 | res = obj2ast_expr(tmp, &elt, arena); |
| 6396 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6397 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6398 | } |
| 6399 | if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6400 | return 1; |
| 6401 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6402 | if (tmp == NULL) { |
| 6403 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 6404 | return 1; |
| 6405 | } |
| 6406 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6407 | int res; |
| 6408 | Py_ssize_t len; |
| 6409 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6410 | if (!PyList_Check(tmp)) { |
| 6411 | PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6412 | goto failed; |
| 6413 | } |
| 6414 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6415 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6416 | if (generators == NULL) goto failed; |
| 6417 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6418 | comprehension_ty val; |
| 6419 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6420 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6421 | if (len != PyList_GET_SIZE(tmp)) { |
| 6422 | PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration"); |
| 6423 | goto failed; |
| 6424 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6425 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6426 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6427 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6428 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6429 | *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno, |
| 6430 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6431 | if (*out == NULL) goto failed; |
| 6432 | return 0; |
| 6433 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6434 | isinstance = PyObject_IsInstance(obj, (PyObject*)Await_type); |
| 6435 | if (isinstance == -1) { |
| 6436 | return 1; |
| 6437 | } |
| 6438 | if (isinstance) { |
| 6439 | expr_ty value; |
| 6440 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6441 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6442 | return 1; |
| 6443 | } |
| 6444 | if (tmp == NULL) { |
| 6445 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await"); |
| 6446 | return 1; |
| 6447 | } |
| 6448 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6449 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6450 | res = obj2ast_expr(tmp, &value, arena); |
| 6451 | if (res != 0) goto failed; |
| 6452 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6453 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6454 | *out = Await(value, lineno, col_offset, end_lineno, end_col_offset, |
| 6455 | arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6456 | if (*out == NULL) goto failed; |
| 6457 | return 0; |
| 6458 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6459 | isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); |
| 6460 | if (isinstance == -1) { |
| 6461 | return 1; |
| 6462 | } |
| 6463 | if (isinstance) { |
| 6464 | expr_ty value; |
| 6465 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6466 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6467 | return 1; |
| 6468 | } |
| 6469 | if (tmp == NULL || tmp == Py_None) { |
| 6470 | Py_CLEAR(tmp); |
| 6471 | value = NULL; |
| 6472 | } |
| 6473 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6474 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6475 | res = obj2ast_expr(tmp, &value, arena); |
| 6476 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6477 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6478 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6479 | *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset, |
| 6480 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6481 | if (*out == NULL) goto failed; |
| 6482 | return 0; |
| 6483 | } |
| 6484 | isinstance = PyObject_IsInstance(obj, (PyObject*)YieldFrom_type); |
| 6485 | if (isinstance == -1) { |
| 6486 | return 1; |
| 6487 | } |
| 6488 | if (isinstance) { |
| 6489 | expr_ty value; |
| 6490 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6491 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6492 | return 1; |
| 6493 | } |
| 6494 | if (tmp == NULL) { |
| 6495 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom"); |
| 6496 | return 1; |
| 6497 | } |
| 6498 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6499 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6500 | res = obj2ast_expr(tmp, &value, arena); |
| 6501 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6502 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6503 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6504 | *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset, |
| 6505 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6506 | if (*out == NULL) goto failed; |
| 6507 | return 0; |
| 6508 | } |
| 6509 | isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); |
| 6510 | if (isinstance == -1) { |
| 6511 | return 1; |
| 6512 | } |
| 6513 | if (isinstance) { |
| 6514 | expr_ty left; |
| 6515 | asdl_int_seq* ops; |
| 6516 | asdl_seq* comparators; |
| 6517 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6518 | if (_PyObject_LookupAttrId(obj, &PyId_left, &tmp) < 0) { |
| 6519 | return 1; |
| 6520 | } |
| 6521 | if (tmp == NULL) { |
| 6522 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 6523 | return 1; |
| 6524 | } |
| 6525 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6526 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6527 | res = obj2ast_expr(tmp, &left, arena); |
| 6528 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6529 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6530 | } |
| 6531 | if (_PyObject_LookupAttrId(obj, &PyId_ops, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6532 | return 1; |
| 6533 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6534 | if (tmp == NULL) { |
| 6535 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 6536 | return 1; |
| 6537 | } |
| 6538 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6539 | int res; |
| 6540 | Py_ssize_t len; |
| 6541 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6542 | if (!PyList_Check(tmp)) { |
| 6543 | PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6544 | goto failed; |
| 6545 | } |
| 6546 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6547 | ops = _Py_asdl_int_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6548 | if (ops == NULL) goto failed; |
| 6549 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6550 | cmpop_ty val; |
| 6551 | res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6552 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6553 | if (len != PyList_GET_SIZE(tmp)) { |
| 6554 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration"); |
| 6555 | goto failed; |
| 6556 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6557 | asdl_seq_SET(ops, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6558 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6559 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6560 | } |
| 6561 | if (_PyObject_LookupAttrId(obj, &PyId_comparators, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6562 | return 1; |
| 6563 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6564 | if (tmp == NULL) { |
| 6565 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 6566 | return 1; |
| 6567 | } |
| 6568 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6569 | int res; |
| 6570 | Py_ssize_t len; |
| 6571 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6572 | if (!PyList_Check(tmp)) { |
| 6573 | PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6574 | goto failed; |
| 6575 | } |
| 6576 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6577 | comparators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6578 | if (comparators == NULL) goto failed; |
| 6579 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6580 | expr_ty val; |
| 6581 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6582 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6583 | if (len != PyList_GET_SIZE(tmp)) { |
| 6584 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration"); |
| 6585 | goto failed; |
| 6586 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6587 | asdl_seq_SET(comparators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6588 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6589 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6590 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6591 | *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno, |
| 6592 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6593 | if (*out == NULL) goto failed; |
| 6594 | return 0; |
| 6595 | } |
| 6596 | isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type); |
| 6597 | if (isinstance == -1) { |
| 6598 | return 1; |
| 6599 | } |
| 6600 | if (isinstance) { |
| 6601 | expr_ty func; |
| 6602 | asdl_seq* args; |
| 6603 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6604 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6605 | if (_PyObject_LookupAttrId(obj, &PyId_func, &tmp) < 0) { |
| 6606 | return 1; |
| 6607 | } |
| 6608 | if (tmp == NULL) { |
| 6609 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 6610 | return 1; |
| 6611 | } |
| 6612 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6613 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6614 | res = obj2ast_expr(tmp, &func, arena); |
| 6615 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6616 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6617 | } |
| 6618 | if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6619 | return 1; |
| 6620 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6621 | if (tmp == NULL) { |
| 6622 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 6623 | return 1; |
| 6624 | } |
| 6625 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6626 | int res; |
| 6627 | Py_ssize_t len; |
| 6628 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6629 | if (!PyList_Check(tmp)) { |
| 6630 | PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6631 | goto failed; |
| 6632 | } |
| 6633 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6634 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6635 | if (args == NULL) goto failed; |
| 6636 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6637 | expr_ty val; |
| 6638 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6639 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6640 | if (len != PyList_GET_SIZE(tmp)) { |
| 6641 | PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration"); |
| 6642 | goto failed; |
| 6643 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6644 | asdl_seq_SET(args, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6645 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6646 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6647 | } |
| 6648 | if (_PyObject_LookupAttrId(obj, &PyId_keywords, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6649 | return 1; |
| 6650 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6651 | if (tmp == NULL) { |
| 6652 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 6653 | return 1; |
| 6654 | } |
| 6655 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6656 | int res; |
| 6657 | Py_ssize_t len; |
| 6658 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6659 | if (!PyList_Check(tmp)) { |
| 6660 | PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6661 | goto failed; |
| 6662 | } |
| 6663 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6664 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6665 | if (keywords == NULL) goto failed; |
| 6666 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6667 | keyword_ty val; |
| 6668 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6669 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6670 | if (len != PyList_GET_SIZE(tmp)) { |
| 6671 | PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration"); |
| 6672 | goto failed; |
| 6673 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6674 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6675 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6676 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6677 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6678 | *out = Call(func, args, keywords, lineno, col_offset, end_lineno, |
| 6679 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6680 | if (*out == NULL) goto failed; |
| 6681 | return 0; |
| 6682 | } |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6683 | isinstance = PyObject_IsInstance(obj, (PyObject*)FormattedValue_type); |
| 6684 | if (isinstance == -1) { |
| 6685 | return 1; |
| 6686 | } |
| 6687 | if (isinstance) { |
| 6688 | expr_ty value; |
| 6689 | int conversion; |
| 6690 | expr_ty format_spec; |
| 6691 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6692 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6693 | return 1; |
| 6694 | } |
| 6695 | if (tmp == NULL) { |
| 6696 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue"); |
| 6697 | return 1; |
| 6698 | } |
| 6699 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6700 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6701 | res = obj2ast_expr(tmp, &value, arena); |
| 6702 | if (res != 0) goto failed; |
| 6703 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6704 | } |
| 6705 | if (_PyObject_LookupAttrId(obj, &PyId_conversion, &tmp) < 0) { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6706 | return 1; |
| 6707 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6708 | if (tmp == NULL || tmp == Py_None) { |
| 6709 | Py_CLEAR(tmp); |
| 6710 | conversion = 0; |
| 6711 | } |
| 6712 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6713 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6714 | res = obj2ast_int(tmp, &conversion, arena); |
| 6715 | if (res != 0) goto failed; |
| 6716 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6717 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6718 | if (_PyObject_LookupAttrId(obj, &PyId_format_spec, &tmp) < 0) { |
| 6719 | return 1; |
| 6720 | } |
| 6721 | if (tmp == NULL || tmp == Py_None) { |
| 6722 | Py_CLEAR(tmp); |
| 6723 | format_spec = NULL; |
| 6724 | } |
| 6725 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6726 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6727 | res = obj2ast_expr(tmp, &format_spec, arena); |
| 6728 | if (res != 0) goto failed; |
| 6729 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6730 | } |
| 6731 | *out = FormattedValue(value, conversion, format_spec, lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6732 | col_offset, end_lineno, end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6733 | if (*out == NULL) goto failed; |
| 6734 | return 0; |
| 6735 | } |
| 6736 | isinstance = PyObject_IsInstance(obj, (PyObject*)JoinedStr_type); |
| 6737 | if (isinstance == -1) { |
| 6738 | return 1; |
| 6739 | } |
| 6740 | if (isinstance) { |
| 6741 | asdl_seq* values; |
| 6742 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6743 | if (_PyObject_LookupAttrId(obj, &PyId_values, &tmp) < 0) { |
| 6744 | return 1; |
| 6745 | } |
| 6746 | if (tmp == NULL) { |
| 6747 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr"); |
| 6748 | return 1; |
| 6749 | } |
| 6750 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6751 | int res; |
| 6752 | Py_ssize_t len; |
| 6753 | Py_ssize_t i; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6754 | if (!PyList_Check(tmp)) { |
| 6755 | PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6756 | goto failed; |
| 6757 | } |
| 6758 | len = PyList_GET_SIZE(tmp); |
| 6759 | values = _Py_asdl_seq_new(len, arena); |
| 6760 | if (values == NULL) goto failed; |
| 6761 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6762 | expr_ty val; |
| 6763 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6764 | if (res != 0) goto failed; |
Serhiy Storchaka | 5e80855 | 2016-10-07 21:55:49 +0300 | [diff] [blame] | 6765 | if (len != PyList_GET_SIZE(tmp)) { |
| 6766 | PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration"); |
| 6767 | goto failed; |
| 6768 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6769 | asdl_seq_SET(values, i, val); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6770 | } |
| 6771 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6772 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6773 | *out = JoinedStr(values, lineno, col_offset, end_lineno, |
| 6774 | end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6775 | if (*out == NULL) goto failed; |
| 6776 | return 0; |
| 6777 | } |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 6778 | isinstance = PyObject_IsInstance(obj, (PyObject*)Constant_type); |
| 6779 | if (isinstance == -1) { |
| 6780 | return 1; |
| 6781 | } |
| 6782 | if (isinstance) { |
| 6783 | constant value; |
| 6784 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6785 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6786 | return 1; |
| 6787 | } |
| 6788 | if (tmp == NULL) { |
| 6789 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant"); |
| 6790 | return 1; |
| 6791 | } |
| 6792 | else { |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 6793 | int res; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 6794 | res = obj2ast_constant(tmp, &value, arena); |
| 6795 | if (res != 0) goto failed; |
| 6796 | Py_CLEAR(tmp); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 6797 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6798 | *out = Constant(value, lineno, col_offset, end_lineno, end_col_offset, |
| 6799 | arena); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 6800 | if (*out == NULL) goto failed; |
| 6801 | return 0; |
| 6802 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6803 | isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type); |
| 6804 | if (isinstance == -1) { |
| 6805 | return 1; |
| 6806 | } |
| 6807 | if (isinstance) { |
| 6808 | expr_ty value; |
| 6809 | identifier attr; |
| 6810 | expr_context_ty ctx; |
| 6811 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6812 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6813 | return 1; |
| 6814 | } |
| 6815 | if (tmp == NULL) { |
| 6816 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 6817 | return 1; |
| 6818 | } |
| 6819 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6820 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6821 | res = obj2ast_expr(tmp, &value, arena); |
| 6822 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6823 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6824 | } |
| 6825 | if (_PyObject_LookupAttrId(obj, &PyId_attr, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6826 | return 1; |
| 6827 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6828 | if (tmp == NULL) { |
| 6829 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 6830 | return 1; |
| 6831 | } |
| 6832 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6833 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6834 | res = obj2ast_identifier(tmp, &attr, arena); |
| 6835 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6836 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6837 | } |
| 6838 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6839 | return 1; |
| 6840 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6841 | if (tmp == NULL) { |
| 6842 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 6843 | return 1; |
| 6844 | } |
| 6845 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6846 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6847 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 6848 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6849 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6850 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6851 | *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno, |
| 6852 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6853 | if (*out == NULL) goto failed; |
| 6854 | return 0; |
| 6855 | } |
| 6856 | isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type); |
| 6857 | if (isinstance == -1) { |
| 6858 | return 1; |
| 6859 | } |
| 6860 | if (isinstance) { |
| 6861 | expr_ty value; |
| 6862 | slice_ty slice; |
| 6863 | expr_context_ty ctx; |
| 6864 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6865 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6866 | return 1; |
| 6867 | } |
| 6868 | if (tmp == NULL) { |
| 6869 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 6870 | return 1; |
| 6871 | } |
| 6872 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6873 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6874 | res = obj2ast_expr(tmp, &value, arena); |
| 6875 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6876 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6877 | } |
| 6878 | if (_PyObject_LookupAttrId(obj, &PyId_slice, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6879 | return 1; |
| 6880 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6881 | if (tmp == NULL) { |
| 6882 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 6883 | return 1; |
| 6884 | } |
| 6885 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6886 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6887 | res = obj2ast_slice(tmp, &slice, arena); |
| 6888 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6889 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6890 | } |
| 6891 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6892 | return 1; |
| 6893 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6894 | if (tmp == NULL) { |
| 6895 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 6896 | return 1; |
| 6897 | } |
| 6898 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6899 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6900 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 6901 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6902 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6903 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6904 | *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno, |
| 6905 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6906 | if (*out == NULL) goto failed; |
| 6907 | return 0; |
| 6908 | } |
| 6909 | isinstance = PyObject_IsInstance(obj, (PyObject*)Starred_type); |
| 6910 | if (isinstance == -1) { |
| 6911 | return 1; |
| 6912 | } |
| 6913 | if (isinstance) { |
| 6914 | expr_ty value; |
| 6915 | expr_context_ty ctx; |
| 6916 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6917 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6918 | return 1; |
| 6919 | } |
| 6920 | if (tmp == NULL) { |
| 6921 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 6922 | return 1; |
| 6923 | } |
| 6924 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6925 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6926 | res = obj2ast_expr(tmp, &value, arena); |
| 6927 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6928 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6929 | } |
| 6930 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6931 | return 1; |
| 6932 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6933 | if (tmp == NULL) { |
| 6934 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 6935 | return 1; |
| 6936 | } |
| 6937 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6938 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6939 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 6940 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6941 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6942 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6943 | *out = Starred(value, ctx, lineno, col_offset, end_lineno, |
| 6944 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6945 | if (*out == NULL) goto failed; |
| 6946 | return 0; |
| 6947 | } |
| 6948 | isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type); |
| 6949 | if (isinstance == -1) { |
| 6950 | return 1; |
| 6951 | } |
| 6952 | if (isinstance) { |
| 6953 | identifier id; |
| 6954 | expr_context_ty ctx; |
| 6955 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6956 | if (_PyObject_LookupAttrId(obj, &PyId_id, &tmp) < 0) { |
| 6957 | return 1; |
| 6958 | } |
| 6959 | if (tmp == NULL) { |
| 6960 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 6961 | return 1; |
| 6962 | } |
| 6963 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6964 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6965 | res = obj2ast_identifier(tmp, &id, arena); |
| 6966 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6967 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6968 | } |
| 6969 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6970 | return 1; |
| 6971 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6972 | if (tmp == NULL) { |
| 6973 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 6974 | return 1; |
| 6975 | } |
| 6976 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6977 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6978 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 6979 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6980 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6981 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6982 | *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 6983 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6984 | if (*out == NULL) goto failed; |
| 6985 | return 0; |
| 6986 | } |
| 6987 | isinstance = PyObject_IsInstance(obj, (PyObject*)List_type); |
| 6988 | if (isinstance == -1) { |
| 6989 | return 1; |
| 6990 | } |
| 6991 | if (isinstance) { |
| 6992 | asdl_seq* elts; |
| 6993 | expr_context_ty ctx; |
| 6994 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6995 | if (_PyObject_LookupAttrId(obj, &PyId_elts, &tmp) < 0) { |
| 6996 | return 1; |
| 6997 | } |
| 6998 | if (tmp == NULL) { |
| 6999 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 7000 | return 1; |
| 7001 | } |
| 7002 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7003 | int res; |
| 7004 | Py_ssize_t len; |
| 7005 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7006 | if (!PyList_Check(tmp)) { |
| 7007 | PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7008 | goto failed; |
| 7009 | } |
| 7010 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7011 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7012 | if (elts == NULL) goto failed; |
| 7013 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7014 | expr_ty val; |
| 7015 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7016 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7017 | if (len != PyList_GET_SIZE(tmp)) { |
| 7018 | PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration"); |
| 7019 | goto failed; |
| 7020 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7021 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7022 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7023 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7024 | } |
| 7025 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7026 | return 1; |
| 7027 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7028 | if (tmp == NULL) { |
| 7029 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 7030 | return 1; |
| 7031 | } |
| 7032 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7033 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7034 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 7035 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7036 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7037 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7038 | *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 7039 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7040 | if (*out == NULL) goto failed; |
| 7041 | return 0; |
| 7042 | } |
| 7043 | isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type); |
| 7044 | if (isinstance == -1) { |
| 7045 | return 1; |
| 7046 | } |
| 7047 | if (isinstance) { |
| 7048 | asdl_seq* elts; |
| 7049 | expr_context_ty ctx; |
| 7050 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7051 | if (_PyObject_LookupAttrId(obj, &PyId_elts, &tmp) < 0) { |
| 7052 | return 1; |
| 7053 | } |
| 7054 | if (tmp == NULL) { |
| 7055 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 7056 | return 1; |
| 7057 | } |
| 7058 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7059 | int res; |
| 7060 | Py_ssize_t len; |
| 7061 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7062 | if (!PyList_Check(tmp)) { |
| 7063 | PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7064 | goto failed; |
| 7065 | } |
| 7066 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7067 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7068 | if (elts == NULL) goto failed; |
| 7069 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7070 | expr_ty val; |
| 7071 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7072 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7073 | if (len != PyList_GET_SIZE(tmp)) { |
| 7074 | PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration"); |
| 7075 | goto failed; |
| 7076 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7077 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7078 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7079 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7080 | } |
| 7081 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7082 | return 1; |
| 7083 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7084 | if (tmp == NULL) { |
| 7085 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 7086 | return 1; |
| 7087 | } |
| 7088 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7089 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7090 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 7091 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7092 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7093 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7094 | *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 7095 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7096 | if (*out == NULL) goto failed; |
| 7097 | return 0; |
| 7098 | } |
| 7099 | |
| 7100 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
| 7101 | failed: |
| 7102 | Py_XDECREF(tmp); |
| 7103 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7104 | } |
| 7105 | |
| 7106 | int |
| 7107 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 7108 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7109 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7110 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7111 | isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); |
| 7112 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7113 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7114 | } |
| 7115 | if (isinstance) { |
| 7116 | *out = Load; |
| 7117 | return 0; |
| 7118 | } |
| 7119 | isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type); |
| 7120 | if (isinstance == -1) { |
| 7121 | return 1; |
| 7122 | } |
| 7123 | if (isinstance) { |
| 7124 | *out = Store; |
| 7125 | return 0; |
| 7126 | } |
| 7127 | isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type); |
| 7128 | if (isinstance == -1) { |
| 7129 | return 1; |
| 7130 | } |
| 7131 | if (isinstance) { |
| 7132 | *out = Del; |
| 7133 | return 0; |
| 7134 | } |
| 7135 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type); |
| 7136 | if (isinstance == -1) { |
| 7137 | return 1; |
| 7138 | } |
| 7139 | if (isinstance) { |
| 7140 | *out = AugLoad; |
| 7141 | return 0; |
| 7142 | } |
| 7143 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type); |
| 7144 | if (isinstance == -1) { |
| 7145 | return 1; |
| 7146 | } |
| 7147 | if (isinstance) { |
| 7148 | *out = AugStore; |
| 7149 | return 0; |
| 7150 | } |
| 7151 | isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type); |
| 7152 | if (isinstance == -1) { |
| 7153 | return 1; |
| 7154 | } |
| 7155 | if (isinstance) { |
| 7156 | *out = Param; |
| 7157 | return 0; |
| 7158 | } |
| 7159 | |
| 7160 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj); |
| 7161 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7162 | } |
| 7163 | |
| 7164 | int |
| 7165 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
| 7166 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7167 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7168 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7169 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7170 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7171 | if (obj == Py_None) { |
| 7172 | *out = NULL; |
| 7173 | return 0; |
| 7174 | } |
| 7175 | isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type); |
| 7176 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7177 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7178 | } |
| 7179 | if (isinstance) { |
| 7180 | expr_ty lower; |
| 7181 | expr_ty upper; |
| 7182 | expr_ty step; |
| 7183 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7184 | if (_PyObject_LookupAttrId(obj, &PyId_lower, &tmp) < 0) { |
| 7185 | return 1; |
| 7186 | } |
| 7187 | if (tmp == NULL || tmp == Py_None) { |
| 7188 | Py_CLEAR(tmp); |
| 7189 | lower = NULL; |
| 7190 | } |
| 7191 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7192 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7193 | res = obj2ast_expr(tmp, &lower, arena); |
| 7194 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7195 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7196 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7197 | if (_PyObject_LookupAttrId(obj, &PyId_upper, &tmp) < 0) { |
| 7198 | return 1; |
| 7199 | } |
| 7200 | if (tmp == NULL || tmp == Py_None) { |
| 7201 | Py_CLEAR(tmp); |
| 7202 | upper = NULL; |
| 7203 | } |
| 7204 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7205 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7206 | res = obj2ast_expr(tmp, &upper, arena); |
| 7207 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7208 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7209 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7210 | if (_PyObject_LookupAttrId(obj, &PyId_step, &tmp) < 0) { |
| 7211 | return 1; |
| 7212 | } |
| 7213 | if (tmp == NULL || tmp == Py_None) { |
| 7214 | Py_CLEAR(tmp); |
| 7215 | step = NULL; |
| 7216 | } |
| 7217 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7218 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7219 | res = obj2ast_expr(tmp, &step, arena); |
| 7220 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7221 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7222 | } |
| 7223 | *out = Slice(lower, upper, step, arena); |
| 7224 | if (*out == NULL) goto failed; |
| 7225 | return 0; |
| 7226 | } |
| 7227 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type); |
| 7228 | if (isinstance == -1) { |
| 7229 | return 1; |
| 7230 | } |
| 7231 | if (isinstance) { |
| 7232 | asdl_seq* dims; |
| 7233 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7234 | if (_PyObject_LookupAttrId(obj, &PyId_dims, &tmp) < 0) { |
| 7235 | return 1; |
| 7236 | } |
| 7237 | if (tmp == NULL) { |
| 7238 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
| 7239 | return 1; |
| 7240 | } |
| 7241 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7242 | int res; |
| 7243 | Py_ssize_t len; |
| 7244 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7245 | if (!PyList_Check(tmp)) { |
| 7246 | PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7247 | goto failed; |
| 7248 | } |
| 7249 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7250 | dims = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7251 | if (dims == NULL) goto failed; |
| 7252 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7253 | slice_ty val; |
| 7254 | res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7255 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7256 | if (len != PyList_GET_SIZE(tmp)) { |
| 7257 | PyErr_SetString(PyExc_RuntimeError, "ExtSlice field \"dims\" changed size during iteration"); |
| 7258 | goto failed; |
| 7259 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7260 | asdl_seq_SET(dims, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7261 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7262 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7263 | } |
| 7264 | *out = ExtSlice(dims, arena); |
| 7265 | if (*out == NULL) goto failed; |
| 7266 | return 0; |
| 7267 | } |
| 7268 | isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type); |
| 7269 | if (isinstance == -1) { |
| 7270 | return 1; |
| 7271 | } |
| 7272 | if (isinstance) { |
| 7273 | expr_ty value; |
| 7274 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7275 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 7276 | return 1; |
| 7277 | } |
| 7278 | if (tmp == NULL) { |
| 7279 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
| 7280 | return 1; |
| 7281 | } |
| 7282 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7283 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7284 | res = obj2ast_expr(tmp, &value, arena); |
| 7285 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7286 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7287 | } |
| 7288 | *out = Index(value, arena); |
| 7289 | if (*out == NULL) goto failed; |
| 7290 | return 0; |
| 7291 | } |
| 7292 | |
| 7293 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj); |
| 7294 | failed: |
| 7295 | Py_XDECREF(tmp); |
| 7296 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7297 | } |
| 7298 | |
| 7299 | int |
| 7300 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 7301 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7302 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7303 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7304 | isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); |
| 7305 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7306 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7307 | } |
| 7308 | if (isinstance) { |
| 7309 | *out = And; |
| 7310 | return 0; |
| 7311 | } |
| 7312 | isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type); |
| 7313 | if (isinstance == -1) { |
| 7314 | return 1; |
| 7315 | } |
| 7316 | if (isinstance) { |
| 7317 | *out = Or; |
| 7318 | return 0; |
| 7319 | } |
| 7320 | |
| 7321 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj); |
| 7322 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7323 | } |
| 7324 | |
| 7325 | int |
| 7326 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 7327 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7328 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7329 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7330 | isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); |
| 7331 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7332 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7333 | } |
| 7334 | if (isinstance) { |
| 7335 | *out = Add; |
| 7336 | return 0; |
| 7337 | } |
| 7338 | isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type); |
| 7339 | if (isinstance == -1) { |
| 7340 | return 1; |
| 7341 | } |
| 7342 | if (isinstance) { |
| 7343 | *out = Sub; |
| 7344 | return 0; |
| 7345 | } |
| 7346 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type); |
| 7347 | if (isinstance == -1) { |
| 7348 | return 1; |
| 7349 | } |
| 7350 | if (isinstance) { |
| 7351 | *out = Mult; |
| 7352 | return 0; |
| 7353 | } |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 7354 | isinstance = PyObject_IsInstance(obj, (PyObject *)MatMult_type); |
| 7355 | if (isinstance == -1) { |
| 7356 | return 1; |
| 7357 | } |
| 7358 | if (isinstance) { |
| 7359 | *out = MatMult; |
| 7360 | return 0; |
| 7361 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7362 | isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type); |
| 7363 | if (isinstance == -1) { |
| 7364 | return 1; |
| 7365 | } |
| 7366 | if (isinstance) { |
| 7367 | *out = Div; |
| 7368 | return 0; |
| 7369 | } |
| 7370 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type); |
| 7371 | if (isinstance == -1) { |
| 7372 | return 1; |
| 7373 | } |
| 7374 | if (isinstance) { |
| 7375 | *out = Mod; |
| 7376 | return 0; |
| 7377 | } |
| 7378 | isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type); |
| 7379 | if (isinstance == -1) { |
| 7380 | return 1; |
| 7381 | } |
| 7382 | if (isinstance) { |
| 7383 | *out = Pow; |
| 7384 | return 0; |
| 7385 | } |
| 7386 | isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type); |
| 7387 | if (isinstance == -1) { |
| 7388 | return 1; |
| 7389 | } |
| 7390 | if (isinstance) { |
| 7391 | *out = LShift; |
| 7392 | return 0; |
| 7393 | } |
| 7394 | isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type); |
| 7395 | if (isinstance == -1) { |
| 7396 | return 1; |
| 7397 | } |
| 7398 | if (isinstance) { |
| 7399 | *out = RShift; |
| 7400 | return 0; |
| 7401 | } |
| 7402 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type); |
| 7403 | if (isinstance == -1) { |
| 7404 | return 1; |
| 7405 | } |
| 7406 | if (isinstance) { |
| 7407 | *out = BitOr; |
| 7408 | return 0; |
| 7409 | } |
| 7410 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type); |
| 7411 | if (isinstance == -1) { |
| 7412 | return 1; |
| 7413 | } |
| 7414 | if (isinstance) { |
| 7415 | *out = BitXor; |
| 7416 | return 0; |
| 7417 | } |
| 7418 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type); |
| 7419 | if (isinstance == -1) { |
| 7420 | return 1; |
| 7421 | } |
| 7422 | if (isinstance) { |
| 7423 | *out = BitAnd; |
| 7424 | return 0; |
| 7425 | } |
| 7426 | isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type); |
| 7427 | if (isinstance == -1) { |
| 7428 | return 1; |
| 7429 | } |
| 7430 | if (isinstance) { |
| 7431 | *out = FloorDiv; |
| 7432 | return 0; |
| 7433 | } |
| 7434 | |
| 7435 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj); |
| 7436 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7437 | } |
| 7438 | |
| 7439 | int |
| 7440 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 7441 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7442 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7443 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7444 | isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); |
| 7445 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7446 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7447 | } |
| 7448 | if (isinstance) { |
| 7449 | *out = Invert; |
| 7450 | return 0; |
| 7451 | } |
| 7452 | isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type); |
| 7453 | if (isinstance == -1) { |
| 7454 | return 1; |
| 7455 | } |
| 7456 | if (isinstance) { |
| 7457 | *out = Not; |
| 7458 | return 0; |
| 7459 | } |
| 7460 | isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type); |
| 7461 | if (isinstance == -1) { |
| 7462 | return 1; |
| 7463 | } |
| 7464 | if (isinstance) { |
| 7465 | *out = UAdd; |
| 7466 | return 0; |
| 7467 | } |
| 7468 | isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type); |
| 7469 | if (isinstance == -1) { |
| 7470 | return 1; |
| 7471 | } |
| 7472 | if (isinstance) { |
| 7473 | *out = USub; |
| 7474 | return 0; |
| 7475 | } |
| 7476 | |
| 7477 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj); |
| 7478 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7479 | } |
| 7480 | |
| 7481 | int |
| 7482 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 7483 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7484 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7485 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7486 | isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); |
| 7487 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7488 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7489 | } |
| 7490 | if (isinstance) { |
| 7491 | *out = Eq; |
| 7492 | return 0; |
| 7493 | } |
| 7494 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type); |
| 7495 | if (isinstance == -1) { |
| 7496 | return 1; |
| 7497 | } |
| 7498 | if (isinstance) { |
| 7499 | *out = NotEq; |
| 7500 | return 0; |
| 7501 | } |
| 7502 | isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type); |
| 7503 | if (isinstance == -1) { |
| 7504 | return 1; |
| 7505 | } |
| 7506 | if (isinstance) { |
| 7507 | *out = Lt; |
| 7508 | return 0; |
| 7509 | } |
| 7510 | isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type); |
| 7511 | if (isinstance == -1) { |
| 7512 | return 1; |
| 7513 | } |
| 7514 | if (isinstance) { |
| 7515 | *out = LtE; |
| 7516 | return 0; |
| 7517 | } |
| 7518 | isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type); |
| 7519 | if (isinstance == -1) { |
| 7520 | return 1; |
| 7521 | } |
| 7522 | if (isinstance) { |
| 7523 | *out = Gt; |
| 7524 | return 0; |
| 7525 | } |
| 7526 | isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type); |
| 7527 | if (isinstance == -1) { |
| 7528 | return 1; |
| 7529 | } |
| 7530 | if (isinstance) { |
| 7531 | *out = GtE; |
| 7532 | return 0; |
| 7533 | } |
| 7534 | isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type); |
| 7535 | if (isinstance == -1) { |
| 7536 | return 1; |
| 7537 | } |
| 7538 | if (isinstance) { |
| 7539 | *out = Is; |
| 7540 | return 0; |
| 7541 | } |
| 7542 | isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type); |
| 7543 | if (isinstance == -1) { |
| 7544 | return 1; |
| 7545 | } |
| 7546 | if (isinstance) { |
| 7547 | *out = IsNot; |
| 7548 | return 0; |
| 7549 | } |
| 7550 | isinstance = PyObject_IsInstance(obj, (PyObject *)In_type); |
| 7551 | if (isinstance == -1) { |
| 7552 | return 1; |
| 7553 | } |
| 7554 | if (isinstance) { |
| 7555 | *out = In; |
| 7556 | return 0; |
| 7557 | } |
| 7558 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type); |
| 7559 | if (isinstance == -1) { |
| 7560 | return 1; |
| 7561 | } |
| 7562 | if (isinstance) { |
| 7563 | *out = NotIn; |
| 7564 | return 0; |
| 7565 | } |
| 7566 | |
| 7567 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj); |
| 7568 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7569 | } |
| 7570 | |
| 7571 | int |
| 7572 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 7573 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7574 | PyObject* tmp = NULL; |
| 7575 | expr_ty target; |
| 7576 | expr_ty iter; |
| 7577 | asdl_seq* ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 7578 | int is_async; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7579 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7580 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 7581 | return 1; |
| 7582 | } |
| 7583 | if (tmp == NULL) { |
| 7584 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 7585 | return 1; |
| 7586 | } |
| 7587 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7588 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7589 | res = obj2ast_expr(tmp, &target, arena); |
| 7590 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7591 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7592 | } |
| 7593 | if (_PyObject_LookupAttrId(obj, &PyId_iter, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7594 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7595 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7596 | if (tmp == NULL) { |
| 7597 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 7598 | return 1; |
| 7599 | } |
| 7600 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7601 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7602 | res = obj2ast_expr(tmp, &iter, arena); |
| 7603 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7604 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7605 | } |
| 7606 | if (_PyObject_LookupAttrId(obj, &PyId_ifs, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7607 | return 1; |
| 7608 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7609 | if (tmp == NULL) { |
| 7610 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 7611 | return 1; |
| 7612 | } |
| 7613 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7614 | int res; |
| 7615 | Py_ssize_t len; |
| 7616 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7617 | if (!PyList_Check(tmp)) { |
| 7618 | PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7619 | goto failed; |
| 7620 | } |
| 7621 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7622 | ifs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7623 | if (ifs == NULL) goto failed; |
| 7624 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7625 | expr_ty val; |
| 7626 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7627 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7628 | if (len != PyList_GET_SIZE(tmp)) { |
| 7629 | PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration"); |
| 7630 | goto failed; |
| 7631 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7632 | asdl_seq_SET(ifs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7633 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7634 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7635 | } |
| 7636 | if (_PyObject_LookupAttrId(obj, &PyId_is_async, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7637 | return 1; |
| 7638 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7639 | if (tmp == NULL) { |
| 7640 | PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension"); |
| 7641 | return 1; |
| 7642 | } |
| 7643 | else { |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 7644 | int res; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 7645 | res = obj2ast_int(tmp, &is_async, arena); |
| 7646 | if (res != 0) goto failed; |
| 7647 | Py_CLEAR(tmp); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 7648 | } |
| 7649 | *out = comprehension(target, iter, ifs, is_async, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7650 | return 0; |
| 7651 | failed: |
| 7652 | Py_XDECREF(tmp); |
| 7653 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7654 | } |
| 7655 | |
| 7656 | int |
| 7657 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 7658 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7659 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 7660 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7661 | PyObject *tmp = NULL; |
| 7662 | int lineno; |
| 7663 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7664 | int end_lineno; |
| 7665 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7666 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7667 | if (obj == Py_None) { |
| 7668 | *out = NULL; |
| 7669 | return 0; |
| 7670 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7671 | if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) { |
| 7672 | return 1; |
| 7673 | } |
| 7674 | if (tmp == NULL) { |
| 7675 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 7676 | return 1; |
| 7677 | } |
| 7678 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7679 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7680 | res = obj2ast_int(tmp, &lineno, arena); |
| 7681 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7682 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7683 | } |
| 7684 | if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7685 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7686 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7687 | if (tmp == NULL) { |
| 7688 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 7689 | return 1; |
| 7690 | } |
| 7691 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7692 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7693 | res = obj2ast_int(tmp, &col_offset, arena); |
| 7694 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7695 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7696 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7697 | if (_PyObject_LookupAttrId(obj, &PyId_end_lineno, &tmp) < 0) { |
| 7698 | return 1; |
| 7699 | } |
| 7700 | if (tmp == NULL || tmp == Py_None) { |
| 7701 | Py_CLEAR(tmp); |
| 7702 | end_lineno = 0; |
| 7703 | } |
| 7704 | else { |
| 7705 | int res; |
| 7706 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 7707 | if (res != 0) goto failed; |
| 7708 | Py_CLEAR(tmp); |
| 7709 | } |
| 7710 | if (_PyObject_LookupAttrId(obj, &PyId_end_col_offset, &tmp) < 0) { |
| 7711 | return 1; |
| 7712 | } |
| 7713 | if (tmp == NULL || tmp == Py_None) { |
| 7714 | Py_CLEAR(tmp); |
| 7715 | end_col_offset = 0; |
| 7716 | } |
| 7717 | else { |
| 7718 | int res; |
| 7719 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 7720 | if (res != 0) goto failed; |
| 7721 | Py_CLEAR(tmp); |
| 7722 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7723 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type); |
| 7724 | if (isinstance == -1) { |
| 7725 | return 1; |
| 7726 | } |
| 7727 | if (isinstance) { |
| 7728 | expr_ty type; |
| 7729 | identifier name; |
| 7730 | asdl_seq* body; |
| 7731 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7732 | if (_PyObject_LookupAttrId(obj, &PyId_type, &tmp) < 0) { |
| 7733 | return 1; |
| 7734 | } |
| 7735 | if (tmp == NULL || tmp == Py_None) { |
| 7736 | Py_CLEAR(tmp); |
| 7737 | type = NULL; |
| 7738 | } |
| 7739 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7740 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7741 | res = obj2ast_expr(tmp, &type, arena); |
| 7742 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7743 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7744 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7745 | if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) { |
| 7746 | return 1; |
| 7747 | } |
| 7748 | if (tmp == NULL || tmp == Py_None) { |
| 7749 | Py_CLEAR(tmp); |
| 7750 | name = NULL; |
| 7751 | } |
| 7752 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7753 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7754 | res = obj2ast_identifier(tmp, &name, arena); |
| 7755 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7756 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7757 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7758 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 7759 | return 1; |
| 7760 | } |
| 7761 | if (tmp == NULL) { |
| 7762 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 7763 | return 1; |
| 7764 | } |
| 7765 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7766 | int res; |
| 7767 | Py_ssize_t len; |
| 7768 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7769 | if (!PyList_Check(tmp)) { |
| 7770 | PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7771 | goto failed; |
| 7772 | } |
| 7773 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7774 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7775 | if (body == NULL) goto failed; |
| 7776 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7777 | stmt_ty val; |
| 7778 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7779 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7780 | if (len != PyList_GET_SIZE(tmp)) { |
| 7781 | PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration"); |
| 7782 | goto failed; |
| 7783 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7784 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7785 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7786 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7787 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7788 | *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno, |
| 7789 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7790 | if (*out == NULL) goto failed; |
| 7791 | return 0; |
| 7792 | } |
| 7793 | |
| 7794 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
| 7795 | failed: |
| 7796 | Py_XDECREF(tmp); |
| 7797 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7798 | } |
| 7799 | |
| 7800 | int |
| 7801 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 7802 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7803 | PyObject* tmp = NULL; |
| 7804 | asdl_seq* args; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7805 | arg_ty vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7806 | asdl_seq* kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7807 | asdl_seq* kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7808 | arg_ty kwarg; |
| 7809 | asdl_seq* defaults; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7810 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7811 | if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) { |
| 7812 | return 1; |
| 7813 | } |
| 7814 | if (tmp == NULL) { |
| 7815 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 7816 | return 1; |
| 7817 | } |
| 7818 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7819 | int res; |
| 7820 | Py_ssize_t len; |
| 7821 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7822 | if (!PyList_Check(tmp)) { |
| 7823 | PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7824 | goto failed; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7825 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7826 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7827 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7828 | if (args == NULL) goto failed; |
| 7829 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7830 | arg_ty val; |
| 7831 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7832 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7833 | if (len != PyList_GET_SIZE(tmp)) { |
| 7834 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration"); |
| 7835 | goto failed; |
| 7836 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7837 | asdl_seq_SET(args, i, val); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7838 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7839 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7840 | } |
| 7841 | if (_PyObject_LookupAttrId(obj, &PyId_vararg, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7842 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7843 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7844 | if (tmp == NULL || tmp == Py_None) { |
| 7845 | Py_CLEAR(tmp); |
| 7846 | vararg = NULL; |
| 7847 | } |
| 7848 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7849 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7850 | res = obj2ast_arg(tmp, &vararg, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7851 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7852 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7853 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7854 | if (_PyObject_LookupAttrId(obj, &PyId_kwonlyargs, &tmp) < 0) { |
| 7855 | return 1; |
| 7856 | } |
| 7857 | if (tmp == NULL) { |
| 7858 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 7859 | return 1; |
| 7860 | } |
| 7861 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7862 | int res; |
| 7863 | Py_ssize_t len; |
| 7864 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7865 | if (!PyList_Check(tmp)) { |
| 7866 | PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7867 | goto failed; |
| 7868 | } |
| 7869 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7870 | kwonlyargs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7871 | if (kwonlyargs == NULL) goto failed; |
| 7872 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7873 | arg_ty val; |
| 7874 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7875 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7876 | if (len != PyList_GET_SIZE(tmp)) { |
| 7877 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration"); |
| 7878 | goto failed; |
| 7879 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7880 | asdl_seq_SET(kwonlyargs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7881 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7882 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7883 | } |
| 7884 | if (_PyObject_LookupAttrId(obj, &PyId_kw_defaults, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7885 | return 1; |
| 7886 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7887 | if (tmp == NULL) { |
| 7888 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 7889 | return 1; |
| 7890 | } |
| 7891 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7892 | int res; |
| 7893 | Py_ssize_t len; |
| 7894 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7895 | if (!PyList_Check(tmp)) { |
| 7896 | PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7897 | goto failed; |
| 7898 | } |
| 7899 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7900 | kw_defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7901 | if (kw_defaults == NULL) goto failed; |
| 7902 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7903 | expr_ty val; |
| 7904 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7905 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7906 | if (len != PyList_GET_SIZE(tmp)) { |
| 7907 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration"); |
| 7908 | goto failed; |
| 7909 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7910 | asdl_seq_SET(kw_defaults, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7911 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7912 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7913 | } |
| 7914 | if (_PyObject_LookupAttrId(obj, &PyId_kwarg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7915 | return 1; |
| 7916 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7917 | if (tmp == NULL || tmp == Py_None) { |
| 7918 | Py_CLEAR(tmp); |
| 7919 | kwarg = NULL; |
| 7920 | } |
| 7921 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7922 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7923 | res = obj2ast_arg(tmp, &kwarg, arena); |
| 7924 | if (res != 0) goto failed; |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 7925 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7926 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7927 | if (_PyObject_LookupAttrId(obj, &PyId_defaults, &tmp) < 0) { |
| 7928 | return 1; |
| 7929 | } |
| 7930 | if (tmp == NULL) { |
| 7931 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 7932 | return 1; |
| 7933 | } |
| 7934 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7935 | int res; |
| 7936 | Py_ssize_t len; |
| 7937 | Py_ssize_t i; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7938 | if (!PyList_Check(tmp)) { |
| 7939 | PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7940 | goto failed; |
| 7941 | } |
| 7942 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7943 | defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7944 | if (defaults == NULL) goto failed; |
| 7945 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7946 | expr_ty val; |
| 7947 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7948 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7949 | if (len != PyList_GET_SIZE(tmp)) { |
| 7950 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration"); |
| 7951 | goto failed; |
| 7952 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7953 | asdl_seq_SET(defaults, i, val); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7954 | } |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 7955 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7956 | } |
| 7957 | *out = arguments(args, vararg, kwonlyargs, kw_defaults, kwarg, defaults, |
| 7958 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7959 | return 0; |
| 7960 | failed: |
| 7961 | Py_XDECREF(tmp); |
| 7962 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7963 | } |
| 7964 | |
| 7965 | int |
| 7966 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 7967 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7968 | PyObject* tmp = NULL; |
| 7969 | identifier arg; |
| 7970 | expr_ty annotation; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 7971 | int lineno; |
| 7972 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7973 | int end_lineno; |
| 7974 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7975 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7976 | if (_PyObject_LookupAttrId(obj, &PyId_arg, &tmp) < 0) { |
| 7977 | return 1; |
| 7978 | } |
| 7979 | if (tmp == NULL) { |
| 7980 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
| 7981 | return 1; |
| 7982 | } |
| 7983 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7984 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7985 | res = obj2ast_identifier(tmp, &arg, arena); |
| 7986 | if (res != 0) goto failed; |
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_annotation, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7990 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7991 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7992 | if (tmp == NULL || tmp == Py_None) { |
| 7993 | Py_CLEAR(tmp); |
| 7994 | annotation = NULL; |
| 7995 | } |
| 7996 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7997 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7998 | res = obj2ast_expr(tmp, &annotation, arena); |
| 7999 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8000 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8001 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8002 | if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) { |
| 8003 | return 1; |
| 8004 | } |
| 8005 | if (tmp == NULL) { |
| 8006 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg"); |
| 8007 | return 1; |
| 8008 | } |
| 8009 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8010 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8011 | res = obj2ast_int(tmp, &lineno, arena); |
| 8012 | if (res != 0) goto failed; |
| 8013 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8014 | } |
| 8015 | if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8016 | return 1; |
| 8017 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8018 | if (tmp == NULL) { |
| 8019 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg"); |
| 8020 | return 1; |
| 8021 | } |
| 8022 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8023 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8024 | res = obj2ast_int(tmp, &col_offset, arena); |
| 8025 | if (res != 0) goto failed; |
| 8026 | Py_CLEAR(tmp); |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8027 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8028 | if (_PyObject_LookupAttrId(obj, &PyId_end_lineno, &tmp) < 0) { |
| 8029 | return 1; |
| 8030 | } |
| 8031 | if (tmp == NULL || tmp == Py_None) { |
| 8032 | Py_CLEAR(tmp); |
| 8033 | end_lineno = 0; |
| 8034 | } |
| 8035 | else { |
| 8036 | int res; |
| 8037 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 8038 | if (res != 0) goto failed; |
| 8039 | Py_CLEAR(tmp); |
| 8040 | } |
| 8041 | if (_PyObject_LookupAttrId(obj, &PyId_end_col_offset, &tmp) < 0) { |
| 8042 | return 1; |
| 8043 | } |
| 8044 | if (tmp == NULL || tmp == Py_None) { |
| 8045 | Py_CLEAR(tmp); |
| 8046 | end_col_offset = 0; |
| 8047 | } |
| 8048 | else { |
| 8049 | int res; |
| 8050 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 8051 | if (res != 0) goto failed; |
| 8052 | Py_CLEAR(tmp); |
| 8053 | } |
| 8054 | *out = arg(arg, annotation, lineno, col_offset, end_lineno, end_col_offset, |
| 8055 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8056 | return 0; |
| 8057 | failed: |
| 8058 | Py_XDECREF(tmp); |
| 8059 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8060 | } |
| 8061 | |
| 8062 | int |
| 8063 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 8064 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8065 | PyObject* tmp = NULL; |
| 8066 | identifier arg; |
| 8067 | expr_ty value; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8068 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8069 | if (_PyObject_LookupAttrId(obj, &PyId_arg, &tmp) < 0) { |
| 8070 | return 1; |
| 8071 | } |
| 8072 | if (tmp == NULL || tmp == Py_None) { |
| 8073 | Py_CLEAR(tmp); |
| 8074 | arg = NULL; |
| 8075 | } |
| 8076 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8077 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8078 | res = obj2ast_identifier(tmp, &arg, arena); |
| 8079 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8080 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8081 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8082 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 8083 | return 1; |
| 8084 | } |
| 8085 | if (tmp == NULL) { |
| 8086 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 8087 | return 1; |
| 8088 | } |
| 8089 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8090 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8091 | res = obj2ast_expr(tmp, &value, arena); |
| 8092 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8093 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8094 | } |
| 8095 | *out = keyword(arg, value, arena); |
| 8096 | return 0; |
| 8097 | failed: |
| 8098 | Py_XDECREF(tmp); |
| 8099 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8100 | } |
| 8101 | |
| 8102 | int |
| 8103 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 8104 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8105 | PyObject* tmp = NULL; |
| 8106 | identifier name; |
| 8107 | identifier asname; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8108 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8109 | if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) { |
| 8110 | return 1; |
| 8111 | } |
| 8112 | if (tmp == NULL) { |
| 8113 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 8114 | return 1; |
| 8115 | } |
| 8116 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8117 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8118 | res = obj2ast_identifier(tmp, &name, arena); |
| 8119 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8120 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8121 | } |
| 8122 | if (_PyObject_LookupAttrId(obj, &PyId_asname, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8123 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8124 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8125 | if (tmp == NULL || tmp == Py_None) { |
| 8126 | Py_CLEAR(tmp); |
| 8127 | asname = NULL; |
| 8128 | } |
| 8129 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8130 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8131 | res = obj2ast_identifier(tmp, &asname, arena); |
| 8132 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8133 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8134 | } |
| 8135 | *out = alias(name, asname, arena); |
| 8136 | return 0; |
| 8137 | failed: |
| 8138 | Py_XDECREF(tmp); |
| 8139 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8140 | } |
| 8141 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 8142 | int |
| 8143 | obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) |
| 8144 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8145 | PyObject* tmp = NULL; |
| 8146 | expr_ty context_expr; |
| 8147 | expr_ty optional_vars; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 8148 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8149 | if (_PyObject_LookupAttrId(obj, &PyId_context_expr, &tmp) < 0) { |
| 8150 | return 1; |
| 8151 | } |
| 8152 | if (tmp == NULL) { |
| 8153 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); |
| 8154 | return 1; |
| 8155 | } |
| 8156 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8157 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8158 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 8159 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8160 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8161 | } |
| 8162 | if (_PyObject_LookupAttrId(obj, &PyId_optional_vars, &tmp) < 0) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 8163 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8164 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8165 | if (tmp == NULL || tmp == Py_None) { |
| 8166 | Py_CLEAR(tmp); |
| 8167 | optional_vars = NULL; |
| 8168 | } |
| 8169 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8170 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8171 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 8172 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8173 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8174 | } |
| 8175 | *out = withitem(context_expr, optional_vars, arena); |
| 8176 | return 0; |
| 8177 | failed: |
| 8178 | Py_XDECREF(tmp); |
| 8179 | return 1; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 8180 | } |
| 8181 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8182 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 8183 | static struct PyModuleDef _astmodule = { |
| 8184 | PyModuleDef_HEAD_INIT, "_ast" |
| 8185 | }; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 8186 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 8187 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 8188 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8189 | PyObject *m, *d; |
| 8190 | if (!init_types()) return NULL; |
| 8191 | m = PyModule_Create(&_astmodule); |
| 8192 | if (!m) return NULL; |
| 8193 | d = PyModule_GetDict(m); |
| 8194 | if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return NULL; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8195 | if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8196 | return NULL; |
| 8197 | if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return NULL; |
| 8198 | if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) return |
| 8199 | NULL; |
| 8200 | if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) < |
| 8201 | 0) return NULL; |
| 8202 | if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < 0) |
| 8203 | return NULL; |
| 8204 | if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return |
| 8205 | NULL; |
| 8206 | if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return NULL; |
| 8207 | if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) < |
| 8208 | 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8209 | if (PyDict_SetItemString(d, "AsyncFunctionDef", |
| 8210 | (PyObject*)AsyncFunctionDef_type) < 0) return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8211 | if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) |
| 8212 | return NULL; |
| 8213 | if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) return |
| 8214 | NULL; |
| 8215 | if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) return |
| 8216 | NULL; |
| 8217 | if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) return |
| 8218 | NULL; |
| 8219 | if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < 0) |
| 8220 | return NULL; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 8221 | if (PyDict_SetItemString(d, "AnnAssign", (PyObject*)AnnAssign_type) < 0) |
| 8222 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8223 | if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8224 | if (PyDict_SetItemString(d, "AsyncFor", (PyObject*)AsyncFor_type) < 0) |
| 8225 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8226 | if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return |
| 8227 | NULL; |
| 8228 | if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return NULL; |
| 8229 | if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8230 | if (PyDict_SetItemString(d, "AsyncWith", (PyObject*)AsyncWith_type) < 0) |
| 8231 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8232 | if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return |
| 8233 | NULL; |
| 8234 | if (PyDict_SetItemString(d, "Try", (PyObject*)Try_type) < 0) return NULL; |
| 8235 | if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) return |
| 8236 | NULL; |
| 8237 | if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) return |
| 8238 | NULL; |
| 8239 | if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < 0) |
| 8240 | return NULL; |
| 8241 | if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) return |
| 8242 | NULL; |
| 8243 | if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0) |
| 8244 | return NULL; |
| 8245 | if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return NULL; |
| 8246 | if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return NULL; |
| 8247 | if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return |
| 8248 | NULL; |
| 8249 | if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) |
| 8250 | return NULL; |
| 8251 | if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return NULL; |
| 8252 | if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) return |
| 8253 | NULL; |
| 8254 | if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return |
| 8255 | NULL; |
| 8256 | if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) return |
| 8257 | NULL; |
| 8258 | if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) return |
| 8259 | NULL; |
| 8260 | if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return |
| 8261 | NULL; |
| 8262 | if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return NULL; |
| 8263 | if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return NULL; |
| 8264 | if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) |
| 8265 | return NULL; |
| 8266 | if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) return |
| 8267 | NULL; |
| 8268 | if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0) |
| 8269 | return NULL; |
| 8270 | if (PyDict_SetItemString(d, "GeneratorExp", (PyObject*)GeneratorExp_type) < |
| 8271 | 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8272 | if (PyDict_SetItemString(d, "Await", (PyObject*)Await_type) < 0) return |
| 8273 | NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8274 | if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return |
| 8275 | NULL; |
| 8276 | if (PyDict_SetItemString(d, "YieldFrom", (PyObject*)YieldFrom_type) < 0) |
| 8277 | return NULL; |
| 8278 | if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) return |
| 8279 | NULL; |
| 8280 | if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return NULL; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8281 | if (PyDict_SetItemString(d, "FormattedValue", |
| 8282 | (PyObject*)FormattedValue_type) < 0) return NULL; |
| 8283 | if (PyDict_SetItemString(d, "JoinedStr", (PyObject*)JoinedStr_type) < 0) |
| 8284 | return NULL; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8285 | if (PyDict_SetItemString(d, "Constant", (PyObject*)Constant_type) < 0) |
| 8286 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8287 | if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < 0) |
| 8288 | return NULL; |
| 8289 | if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < 0) |
| 8290 | return NULL; |
| 8291 | if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0) return |
| 8292 | NULL; |
| 8293 | if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return NULL; |
| 8294 | if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return NULL; |
| 8295 | if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return |
| 8296 | NULL; |
| 8297 | if (PyDict_SetItemString(d, "expr_context", (PyObject*)expr_context_type) < |
| 8298 | 0) return NULL; |
| 8299 | if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return NULL; |
| 8300 | if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return |
| 8301 | NULL; |
| 8302 | if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return NULL; |
| 8303 | if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) return |
| 8304 | NULL; |
| 8305 | if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) |
| 8306 | return NULL; |
| 8307 | if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return |
| 8308 | NULL; |
| 8309 | if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return |
| 8310 | NULL; |
| 8311 | if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return |
| 8312 | NULL; |
| 8313 | if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) |
| 8314 | return NULL; |
| 8315 | if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return |
| 8316 | NULL; |
| 8317 | if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) return |
| 8318 | NULL; |
| 8319 | if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return NULL; |
| 8320 | if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return NULL; |
| 8321 | if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) |
| 8322 | return NULL; |
| 8323 | if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return NULL; |
| 8324 | if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return NULL; |
| 8325 | if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return NULL; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 8326 | if (PyDict_SetItemString(d, "MatMult", (PyObject*)MatMult_type) < 0) return |
| 8327 | NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8328 | if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return NULL; |
| 8329 | if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return NULL; |
| 8330 | if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return NULL; |
| 8331 | if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) return |
| 8332 | NULL; |
| 8333 | if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) return |
| 8334 | NULL; |
| 8335 | if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return |
| 8336 | NULL; |
| 8337 | if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) return |
| 8338 | NULL; |
| 8339 | if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) return |
| 8340 | NULL; |
| 8341 | if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) |
| 8342 | return NULL; |
| 8343 | if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) return |
| 8344 | NULL; |
| 8345 | if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) return |
| 8346 | NULL; |
| 8347 | if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return NULL; |
| 8348 | if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return NULL; |
| 8349 | if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return NULL; |
| 8350 | if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return |
| 8351 | NULL; |
| 8352 | if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return NULL; |
| 8353 | if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return |
| 8354 | NULL; |
| 8355 | if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return NULL; |
| 8356 | if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return NULL; |
| 8357 | if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return NULL; |
| 8358 | if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return NULL; |
| 8359 | if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return NULL; |
| 8360 | if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return |
| 8361 | NULL; |
| 8362 | if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return NULL; |
| 8363 | if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return |
| 8364 | NULL; |
| 8365 | if (PyDict_SetItemString(d, "comprehension", (PyObject*)comprehension_type) |
| 8366 | < 0) return NULL; |
| 8367 | if (PyDict_SetItemString(d, "excepthandler", (PyObject*)excepthandler_type) |
| 8368 | < 0) return NULL; |
| 8369 | if (PyDict_SetItemString(d, "ExceptHandler", (PyObject*)ExceptHandler_type) |
| 8370 | < 0) return NULL; |
| 8371 | if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < 0) |
| 8372 | return NULL; |
| 8373 | if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return NULL; |
| 8374 | if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) return |
| 8375 | NULL; |
| 8376 | if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return |
| 8377 | NULL; |
| 8378 | if (PyDict_SetItemString(d, "withitem", (PyObject*)withitem_type) < 0) |
| 8379 | return NULL; |
| 8380 | return m; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 8381 | } |
| 8382 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 8383 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 8384 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 8385 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 8386 | if (!init_types()) |
| 8387 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 8388 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 8389 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 8390 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 8391 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 8392 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8393 | { |
| 8394 | mod_ty res; |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 8395 | PyObject *req_type[3]; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 8396 | char *req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 8397 | int isinstance; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 8398 | |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 8399 | req_type[0] = (PyObject*)Module_type; |
| 8400 | req_type[1] = (PyObject*)Expression_type; |
| 8401 | req_type[2] = (PyObject*)Interactive_type; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 8402 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 8403 | assert(0 <= mode && mode <= 2); |
| 8404 | |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 8405 | if (!init_types()) |
| 8406 | return NULL; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 8407 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 8408 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 8409 | if (isinstance == -1) |
| 8410 | return NULL; |
| 8411 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 8412 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
| 8413 | req_name[mode], Py_TYPE(ast)->tp_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8414 | return NULL; |
| 8415 | } |
| 8416 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 8417 | return NULL; |
| 8418 | else |
| 8419 | return res; |
| 8420 | } |
| 8421 | |
| 8422 | int PyAST_Check(PyObject* obj) |
| 8423 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 8424 | if (!init_types()) |
| 8425 | return -1; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 8426 | return PyObject_IsInstance(obj, (PyObject*)&AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8427 | } |
| 8428 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 8429 | |